Skip to content

Commit f8890c9

Browse files
committed
Merge branch 'main' into cleanup_display_helper
2 parents c653d86 + fe19a07 commit f8890c9

19 files changed

+316
-186
lines changed

src/BoostServiceProvider.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
88
use Illuminate\Http\Request;
9+
use Illuminate\Log\Logger;
910
use Illuminate\Routing\Router;
1011
use Illuminate\Support\Facades\Log;
1112
use Illuminate\Support\Facades\Route;
@@ -69,7 +70,7 @@ public function boot(Router $router): void
6970
$this->hookIntoResponses($router);
7071
}
7172

72-
protected function registerPublishing(): void
73+
private function registerPublishing(): void
7374
{
7475
if ($this->app->runningInConsole()) {
7576
$this->publishes([
@@ -78,7 +79,7 @@ protected function registerPublishing(): void
7879
}
7980
}
8081

81-
protected function registerCommands(): void
82+
private function registerCommands(): void
8283
{
8384
if ($this->app->runningInConsole()) {
8485
$this->commands([
@@ -93,14 +94,14 @@ private function registerRoutes(): void
9394
{
9495
Route::post('/_boost/browser-logs', function (Request $request) {
9596
$logs = $request->input('logs', []);
96-
/** @var \Illuminate\Log\Logger $logger */
97+
/** @var Logger $logger */
9798
$logger = Log::channel('browser');
9899

99100
/**
100101
* @var array{
101102
* type: 'error'|'warn'|'info'|'log'|'table'|'window_error'|'uncaught_error'|'unhandled_rejection',
102103
* timestamp: string,
103-
* data: array<mixed>,
104+
* data: array,
104105
* url:string,
105106
* userAgent:string
106107
* } $log */
@@ -123,13 +124,13 @@ private function registerRoutes(): void
123124
}
124125

125126
/**
126-
* Build a string message for the log based on various input types. Single dimensional, and multi:
127-
* "data":[
128-
* {"message":"Unhandled Promise Rejection","reason":{"name":"TypeError","message":"NetworkError when attempting to fetch resource.","stack":""}}]
127+
* Build a string message for the log based on various input types. Single-dimensional, and multi:
128+
* "data": {"message":"Unhandled Promise Rejection","reason":{"name":"TypeError","message":"NetworkError when attempting to fetch resource.","stack":""}}]
129129
*
130-
* @param array<mixed> $data
130+
* @param array $data
131+
* @return string
131132
*/
132-
protected function buildLogMessageFromData(array $data): string
133+
private function buildLogMessageFromData(array $data): string
133134
{
134135
$messages = [];
135136

@@ -146,7 +147,7 @@ protected function buildLogMessageFromData(array $data): string
146147
return implode(' ', $messages);
147148
}
148149

149-
protected function registerBrowserLogger(): void
150+
private function registerBrowserLogger(): void
150151
{
151152
config([
152153
'logging.channels.browser' => [
@@ -158,7 +159,7 @@ protected function registerBrowserLogger(): void
158159
]);
159160
}
160161

161-
protected function registerBladeDirectives(BladeCompiler $bladeCompiler): void
162+
private function registerBladeDirectives(BladeCompiler $bladeCompiler): void
162163
{
163164
$bladeCompiler->directive('boostJs', fn () => '<?php echo \\Laravel\\Boost\\Services\\BrowserLogger::getScript(); ?>');
164165
}
@@ -167,11 +168,8 @@ private function mapJsTypeToPsr3Level(string $type): string
167168
{
168169
return match ($type) {
169170
'warn' => 'warning',
170-
'log' => 'debug',
171-
'table' => 'debug',
172-
'window_error' => 'error',
173-
'uncaught_error' => 'error',
174-
'unhandled_rejection' => 'error',
171+
'log', 'table' => 'debug',
172+
'window_error', 'uncaught_error', 'unhandled_rejection' => 'error',
175173
default => $type
176174
};
177175
}

src/Console/InstallCommand.php

Lines changed: 21 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Laravel\Boost\Console;
66

7+
use Exception;
78
use Illuminate\Console\Command;
89
use Illuminate\Support\Arr;
910
use Illuminate\Support\Collection;
10-
use Illuminate\Support\Facades\Artisan;
1111
use Illuminate\Support\Str;
1212
use Laravel\Boost\Contracts\Agent;
1313
use Laravel\Boost\Contracts\Ide;
@@ -19,6 +19,7 @@
1919
use Laravel\Boost\Install\Herd;
2020
use Laravel\Prompts\Concerns\Colors;
2121
use Laravel\Prompts\Terminal;
22+
use ReflectionClass;
2223
use Symfony\Component\Console\Attribute\AsCommand;
2324
use Symfony\Component\Finder\Finder;
2425

@@ -162,9 +163,6 @@ private function outro(): void
162163
{
163164
$label = 'https://boost.laravel.com/installed';
164165

165-
// Build install data - CSV format with type prefixes
166-
$data = [];
167-
168166
$ideNames = $this->selectedTargetIdes->map(fn ($ide) => 'i:'.class_basename($ide))->toArray();
169167
$agentNames = $this->selectedTargetAgents->map(fn ($agent) => 'a:'.class_basename($agent))->toArray();
170168
$boostFeatures = $this->selectedBoostFeatures->map(fn ($feature) => 'b:'.$feature)->toArray();
@@ -182,7 +180,7 @@ private function outro(): void
182180
// Combine all data
183181
$allData = array_merge($ideNames, $agentNames, $boostFeatures, $guidelines);
184182

185-
// Create compact CSV string and base64 encode
183+
// Create a compact CSV string and base64 encode
186184
$installData = base64_encode(implode(',', $allData));
187185

188186
$link = $this->hyperlink($label, 'https://boost.laravel.com/installed/?d='.$installData);
@@ -191,12 +189,12 @@ private function outro(): void
191189
$paddingLength = (int) (floor(($this->terminal->cols() - mb_strlen($text.$label)) / 2)) - 2;
192190

193191
echo "\033[42m\033[2K".str_repeat(' ', $paddingLength); // Make the entire line have a green background
194-
echo $this->black($this->bold($text.$link)).$this->reset().PHP_EOL;
192+
echo $this->black($this->bold($text.$link)).$this->reset(PHP_EOL);
195193
}
196194

197195
private function hyperlink(string $label, string $url): string
198196
{
199-
return "\033]8;;{$url}\007{$label}\033]8;;\033\\";
197+
return "\033]8;;$url\007$label\033]8;;\033\\";
200198
}
201199

202200
/**
@@ -282,7 +280,6 @@ private function discoverProjectAgents(): array
282280
}
283281
}
284282

285-
// Also check installed IDEs that might not have project files yet
286283
foreach ($this->systemInstalledCodeEnvironments as $ide) {
287284
if (isset($ideToAgentMap[$ide]) && ! in_array($ideToAgentMap[$ide], $agents)) {
288285
$agents[] = $ideToAgentMap[$ide];
@@ -298,7 +295,7 @@ private function discoverProjectAgents(): array
298295
private function selectTargetIdes(): Collection
299296
{
300297
$ides = [];
301-
if (! $this->installingMcp() && ! $this->installingHerdMcp()) {
298+
if (! $this->shouldInstallMcp() && ! $this->shouldInstallHerdMcp()) {
302299
return collect();
303300
}
304301

@@ -313,7 +310,7 @@ private function selectTargetIdes(): Collection
313310
$className = 'Laravel\\Boost\\Install\\Agents\\'.$ideFile->getBasename('.php');
314311

315312
if (class_exists($className)) {
316-
$reflection = new \ReflectionClass($className);
313+
$reflection = new ReflectionClass($className);
317314

318315
if ($reflection->implementsInterface(Ide::class) && ! $reflection->isAbstract()) {
319316
$ides[$className] = Str::headline($ideFile->getBasename('.php'));
@@ -323,7 +320,6 @@ private function selectTargetIdes(): Collection
323320

324321
ksort($ides);
325322

326-
// Map detected IDE keys to class names
327323
$detectedClasses = [];
328324
foreach ($this->projectInstalledCodeEnvironments as $ideKey) {
329325
foreach ($ides as $className => $displayName) {
@@ -352,7 +348,7 @@ private function selectTargetIdes(): Collection
352348
private function selectTargetAgents(): Collection
353349
{
354350
$agents = [];
355-
if (! $this->installingGuidelines()) {
351+
if (! $this->shouldInstallAiGuidelines()) {
356352
return collect();
357353
}
358354

@@ -367,7 +363,7 @@ private function selectTargetAgents(): Collection
367363
$className = 'Laravel\\Boost\\Install\\Agents\\'.$agentFile->getBasename('.php');
368364

369365
if (class_exists($className)) {
370-
$reflection = new \ReflectionClass($className);
366+
$reflection = new ReflectionClass($className);
371367

372368
if ($reflection->implementsInterface(Agent::class)) {
373369
$agents[$className] = Str::headline($agentFile->getBasename('.php'));
@@ -412,7 +408,7 @@ protected function enactGuidelines(): void
412408

413409
$guidelineConfig = new GuidelineConfig;
414410
$guidelineConfig->enforceTests = $this->enforceTests;
415-
$guidelineConfig->laravelStyle = $this->installingStyleGuidelines();
411+
$guidelineConfig->laravelStyle = $this->shouldInstallStyleGuidelines();
416412
$guidelineConfig->caresAboutLocalization = $this->detectLocalization();
417413
$guidelineConfig->hasAnApi = false;
418414

@@ -431,15 +427,15 @@ protected function enactGuidelines(): void
431427
$longestAgentName = max(1, ...$this->selectedTargetAgents->map(fn ($agent) => Str::length(class_basename($agent)))->toArray());
432428
foreach ($this->selectedTargetAgents as $agent) {
433429
$agentName = class_basename($agent);
434-
$displayAgentName = str_pad($agentName, $longestAgentName, ' ', STR_PAD_RIGHT);
435-
$this->output->write(" {$displayAgentName}... ");
430+
$displayAgentName = str_pad($agentName, $longestAgentName);
431+
$this->output->write(" $displayAgentName... ");
436432

437433
try {
438434
(new GuidelineWriter($agent))
439435
->write($composedAiGuidelines);
440436

441437
$this->line($this->greenTick);
442-
} catch (\Exception $e) {
438+
} catch (Exception $e) {
443439
$failed[$agentName] = $e->getMessage();
444440
$this->line($this->redCross);
445441
}
@@ -453,7 +449,7 @@ protected function enactGuidelines(): void
453449
count($failed) === 1 ? '' : 's'
454450
));
455451
foreach ($failed as $agentName => $error) {
456-
$this->line(" - {$agentName}: {$error}");
452+
$this->line(" - $agentName: $error");
457453
}
458454
}
459455
}
@@ -478,53 +474,7 @@ private function shouldInstallHerdMcp(): bool
478474
return $this->selectedBoostFeatures->contains('herd_mcp');
479475
}
480476

481-
protected function publishAndUpdateConfig(): void
482-
{
483-
$configPath = config_path('boost.php');
484-
485-
// Publish config if it doesn't exist
486-
if (! file_exists($configPath)) {
487-
$this->newLine();
488-
$this->info(' Publishing Boost configuration file...');
489-
490-
Artisan::call('vendor:publish', [
491-
'--provider' => 'Laravel\\Boost\\BoostServiceProvider',
492-
'--tag' => 'boost-config',
493-
'--force' => false,
494-
]);
495-
496-
$this->line(' Configuration published '.$this->greenTick);
497-
$this->newLine();
498-
}
499-
500-
// $updated = $this->updateProjectPurposeInConfig($configPath, $this->projectPurpose);
501-
}
502-
503-
protected function updateProjectPurposeInConfig(string $configPath, ?string $purpose): bool
504-
{
505-
if (empty($purpose) || $purpose === config('boost.project_purpose', '')) {
506-
return false;
507-
}
508-
509-
$content = file_get_contents($configPath);
510-
if ($content === false) {
511-
return false;
512-
}
513-
514-
$purposeExists = preg_match('/\'project_purpose\'\s+\=\>\s+(.+),/', $content, $matches);
515-
516-
if (! $purposeExists) { // This shouldn't be possible
517-
return false;
518-
}
519-
520-
$newPurpose = addcslashes($purpose, "'");
521-
$newPurposeLine = "'project_purpose' => '{$newPurpose}',";
522-
$content = str_replace($matches[0], $newPurposeLine, $content);
523-
524-
return file_put_contents($configPath, $content) !== false;
525-
}
526-
527-
protected function enactMcpServers(): void
477+
private function enactMcpServers(): void
528478
{
529479
$this->newLine();
530480
$this->info(' Installing MCP servers to your selected IDEs');
@@ -537,8 +487,8 @@ protected function enactMcpServers(): void
537487

538488
foreach ($this->selectedTargetIdes as $ide) {
539489
$ideName = class_basename($ide);
540-
$ideDisplay = str_pad($ideName, $longestIdeName, ' ', STR_PAD_RIGHT);
541-
$this->output->write(" {$ideDisplay}... ");
490+
$ideDisplay = str_pad($ideName, $longestIdeName);
491+
$this->output->write(" $ideDisplay... ");
542492
$results = [];
543493

544494
// Install Laravel Boost MCP if enabled
@@ -552,7 +502,7 @@ protected function enactMcpServers(): void
552502
$results[] = $this->redCross.' Boost';
553503
$failed[$ideName]['boost'] = 'Failed to write configuration';
554504
}
555-
} catch (\Exception $e) {
505+
} catch (Exception $e) {
556506
$results[] = $this->redCross.' Boost';
557507
$failed[$ideName]['boost'] = $e->getMessage();
558508
}
@@ -574,7 +524,7 @@ protected function enactMcpServers(): void
574524
$results[] = $this->redCross.' Herd';
575525
$failed[$ideName]['herd'] = 'Failed to write configuration';
576526
}
577-
} catch (\Exception $e) {
527+
} catch (Exception $e) {
578528
$results[] = $this->redCross.' Herd';
579529
$failed[$ideName]['herd'] = $e->getMessage();
580530
}
@@ -589,7 +539,7 @@ protected function enactMcpServers(): void
589539
$this->error(sprintf('%s Some MCP servers failed to install:', $this->redCross));
590540
foreach ($failed as $ideName => $errors) {
591541
foreach ($errors as $server => $error) {
592-
$this->line(" - {$ideName} ({$server}): {$error}");
542+
$this->line(" - $ideName ($server): $error");
593543
}
594544
}
595545
}
@@ -598,7 +548,7 @@ protected function enactMcpServers(): void
598548
/**
599549
* Is the project actually using localization for their new features?
600550
*/
601-
protected function detectLocalization(): bool
551+
private function detectLocalization(): bool
602552
{
603553
$actuallyUsing = false;
604554

src/Install/Herd.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace Laravel\Boost\Install;
66

7+
use Laravel\Boost\Install\Enums\Platform;
8+
79
class Herd
810
{
911
public function isInstalled(): bool
1012
{
11-
$isWindows = PHP_OS_FAMILY === 'Windows';
12-
13-
if (! $isWindows) {
13+
if ($this->isWindowsPlatform()) {
1414
return file_exists('/Applications/Herd.app/Contents/MacOS/Herd');
1515
}
1616

@@ -24,7 +24,7 @@ public function isMcpAvailable(): bool
2424

2525
public function getHomePath(): string
2626
{
27-
if (PHP_OS_FAMILY === 'Windows') {
27+
if ($this->isWindowsPlatform()) {
2828
if (! isset($_SERVER['HOME'])) {
2929
$_SERVER['HOME'] = $_SERVER['USERPROFILE'];
3030
}
@@ -37,12 +37,15 @@ public function getHomePath(): string
3737

3838
public function mcpPath(): string
3939
{
40-
$isWindows = PHP_OS_FAMILY === 'Windows';
41-
42-
if ($isWindows) {
40+
if ($this->isWindowsPlatform()) {
4341
return $this->getHomePath().'/.config/herd/bin/herd-mcp.phar';
4442
}
4543

4644
return $this->getHomePath().'/Library/Application Support/Herd/bin/herd-mcp.phar';
4745
}
46+
47+
public function isWindowsPlatform(): bool
48+
{
49+
return Platform::current() === Platform::Windows;
50+
}
4851
}

0 commit comments

Comments
 (0)