Skip to content

Commit 44b2001

Browse files
authored
Merge pull request #111 from laravel/refactor/#109
refactor: streamline path resolution and simplify the MCP client interface
2 parents aaf038d + cbba494 commit 44b2001

File tree

5 files changed

+63
-50
lines changed

5 files changed

+63
-50
lines changed

src/Console/InstallCommand.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,10 @@ private function installMcpServerConfig(): void
469469
$this->output->write(" {$ideDisplay}... ");
470470
$results = [];
471471

472-
$php = $this->getPhpPathForMcpClient($mcpClient);
472+
$php = $mcpClient->getPhpPath();
473473
if ($this->shouldInstallMcp()) {
474474
try {
475-
$artisan = $this->getArtisanPathForMcpClient($mcpClient);
475+
$artisan = $mcpClient->getArtisanPath();
476476
$result = $mcpClient->installMcp('laravel-boost', $php, [$artisan, 'boost:mcp']);
477477

478478
if ($result) {
@@ -492,7 +492,7 @@ private function installMcpServerConfig(): void
492492
try {
493493
$result = $mcpClient->installMcp(
494494
key: 'herd',
495-
command: $this->getPhpPathForMcpClient($mcpClient),
495+
command: $mcpClient->getPhpPath(),
496496
args: [$this->herd->mcpPath()],
497497
env: ['SITE_PATH' => base_path()]
498498
);
@@ -524,16 +524,6 @@ private function installMcpServerConfig(): void
524524
}
525525
}
526526

527-
private function getPhpPathForMcpClient(McpClient $mcpClient): string
528-
{
529-
return $mcpClient->useAbsolutePathForMcp() ? PHP_BINARY : 'php';
530-
}
531-
532-
private function getArtisanPathForMcpClient(McpClient $mcpClient): string
533-
{
534-
return $mcpClient->useAbsolutePathForMcp() ? base_path('artisan') : './artisan';
535-
}
536-
537527
/**
538528
* Is the project actually using localization for their new features?
539529
*/

src/Contracts/McpClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public function mcpClientName(): ?string;
2121
*/
2222
public function useAbsolutePathForMcp(): bool;
2323

24+
/**
25+
* Get the PHP executable path for this MCP client.
26+
*/
27+
public function getPhpPath(): string;
28+
29+
/**
30+
* Get the artisan path for this MCP client.
31+
*/
32+
public function getArtisanPath(): string;
33+
2434
/**
2535
* Install an MCP server configuration in this IDE.
2636
*

src/Install/CodeEnvironment/CodeEnvironment.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ public function useAbsolutePathForMcp(): bool
4040
return $this->useAbsolutePathForMcp;
4141
}
4242

43+
public function getPhpPath(): string
44+
{
45+
return $this->useAbsolutePathForMcp() ? PHP_BINARY : 'php';
46+
}
47+
48+
public function getArtisanPath(): string
49+
{
50+
return $this->useAbsolutePathForMcp() ? getcwd().'/artisan' : './artisan';
51+
52+
}
53+
4354
/**
4455
* Get the detection configuration for system-wide installation detection.
4556
*

tests/Unit/Console/InstallCommandPhpPathTest.php

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Laravel\Boost\Install\CodeEnvironment\Cursor;
6+
use Laravel\Boost\Install\CodeEnvironment\PhpStorm;
7+
use Laravel\Boost\Install\Detection\DetectionStrategyFactory;
8+
9+
test('PhpStorm returns absolute PHP_BINARY path', function () {
10+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
11+
$phpStorm = new PhpStorm($strategyFactory);
12+
13+
expect($phpStorm->getPhpPath())->toBe(PHP_BINARY);
14+
});
15+
16+
test('PhpStorm returns absolute artisan path', function () {
17+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
18+
$phpStorm = new PhpStorm($strategyFactory);
19+
20+
$artisanPath = $phpStorm->getArtisanPath();
21+
22+
// Should be an absolute path ending with 'artisan'
23+
expect($artisanPath)->toEndWith('artisan')
24+
->and($artisanPath)->not()->toBe('./artisan');
25+
});
26+
27+
test('Cursor returns relative php string', function () {
28+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
29+
$cursor = new Cursor($strategyFactory);
30+
31+
expect($cursor->getPhpPath())->toBe('php');
32+
});
33+
34+
test('Cursor returns relative artisan path', function () {
35+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
36+
$cursor = new Cursor($strategyFactory);
37+
38+
expect($cursor->getArtisanPath())->toBe('./artisan');
39+
});

0 commit comments

Comments
 (0)