Skip to content

Commit 28b7b39

Browse files
committed
refactor: streamline InstallCommand structure and improve method visibility
1 parent 2dacc9f commit 28b7b39

File tree

1 file changed

+62
-63
lines changed

1 file changed

+62
-63
lines changed

src/Console/InstallCommand.php

Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,85 +23,103 @@
2323

2424
use function Laravel\Prompts\intro;
2525
use function Laravel\Prompts\multiselect;
26+
use function Laravel\Prompts\note;
2627
use function Laravel\Prompts\select;
2728
use function Laravel\Prompts\text;
2829

2930
#[AsCommand('boost:install', 'Install Laravel Boost')]
3031
class InstallCommand extends Command
3132
{
32-
private $colors;
33+
use Colors;
3334

34-
// Used for nicer install experience
35-
protected string $projectName;
35+
private ApplicationDetector $appDetector;
3636

37-
// Used as part of AI Guidelines
38-
protected string $projectPurpose = '';
37+
private Herd $herd;
3938

40-
/** @var string[] */
41-
protected array $installedIdes = [];
39+
private Roster $roster;
4240

43-
protected array $detectedProjectIdes = [];
41+
private Terminal $terminal;
4442

45-
protected bool $enforceTests = true;
43+
/** @var Collection<int, \Laravel\Boost\Contracts\Agent> */
44+
private Collection $agentsToInstallTo = collect();
4645

4746
/** @var Collection<int, \Laravel\Boost\Contracts\Ide> */
48-
protected Collection $idesToInstallTo;
47+
private Collection $idesToInstallTo = collect();
4948

50-
protected Collection $boostToInstall;
49+
private Collection $boostToInstall;
5150

52-
protected array $boostToolsToDisable = [];
51+
private string $projectName;
5352

54-
protected array $detectedProjectAgents = [];
53+
private string $projectPurpose = '';
5554

56-
/** @var Collection<int, \Laravel\Boost\Contracts\Agent> */
57-
protected Collection $agentsToInstallTo;
55+
/** @var array<non-empty-string> */
56+
private array $installedIdes = [];
57+
58+
private array $detectedProjectIdes = [];
5859

59-
protected Roster $roster;
60+
private bool $enforceTests = true;
6061

61-
protected Herd $herd;
62+
private array $boostToolsToDisable = [];
6263

63-
protected ApplicationDetector $appDetector;
64+
private array $detectedProjectAgents = [];
6465

6566
private string $greenTick;
6667

6768
private string $redCross;
6869

69-
private Terminal $terminal;
70+
public function handle(ApplicationDetector $appDetector, Herd $herd, Roster $roster, Terminal $terminal): void
71+
{
72+
$this->bootstrapBoost($appDetector, $herd, $roster, $terminal);
73+
74+
$this->displayBoostHeader();
75+
$this->detect();
76+
$this->query();
77+
$this->enact();
78+
$this->outro();
79+
}
7080

71-
public function handle(Roster $roster, Herd $herd): void
81+
private function bootstrapBoost(ApplicationDetector $appDetector, Herd $herd, Roster $roster, Terminal $terminal): void
7282
{
73-
$this->terminal = new Terminal;
74-
$this->terminal->initDimensions();
75-
$this->agentsToInstallTo = collect();
76-
$this->idesToInstallTo = collect();
77-
$this->roster = $roster;
83+
$this->appDetector = $appDetector;
7884
$this->herd = $herd;
79-
$this->appDetector = new ApplicationDetector;
85+
$this->roster = $roster;
86+
$this->terminal = $terminal;
8087

81-
$this->colors = new class
82-
{
83-
use Colors;
84-
};
85-
$this->greenTick = $this->colors->green('');
86-
$this->redCross = $this->colors->red('');
88+
$this->terminal->initDimensions();
89+
$this->greenTick = $this->green('');
90+
$this->redCross = $this->red('');
8791

8892
$this->projectName = basename(base_path());
93+
}
8994

90-
$this->intro();
91-
$this->detect();
92-
$this->query();
93-
$this->enact();
94-
$this->outro();
95+
private function displayBoostHeader(): void
96+
{
97+
note($this->boostLogo());
98+
intro('✦ Laravel Boost :: Install :: We Must Ship ✦');
99+
note("Let's give {$this->bgYellow($this->black($this->bold($this->projectName)))} a Boost");
100+
}
101+
102+
private function boostLogo(): string
103+
{
104+
return
105+
<<<'HEADER'
106+
██████╗ ██████╗ ██████╗ ███████╗ ████████╗
107+
██╔══██╗ ██╔═══██╗ ██╔═══██╗ ██╔════╝ ╚══██╔══╝
108+
██████╔╝ ██║ ██║ ██║ ██║ ███████╗ ██║
109+
██╔══██╗ ██║ ██║ ██║ ██║ ╚════██║ ██║
110+
██████╔╝ ╚██████╔╝ ╚██████╔╝ ███████║ ██║
111+
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝
112+
HEADER;
95113
}
96114

97-
protected function detect()
115+
private function detect()
98116
{
99117
$this->installedIdes = $this->detectInstalledIdes();
100118
$this->detectedProjectIdes = $this->detectIdesUsedInProject();
101119
$this->detectedProjectAgents = $this->detectProjectAgents();
102120
}
103121

104-
protected function query()
122+
private function query()
105123
{
106124
// Which parts of boost should we install
107125
$this->boostToInstall = $this->boostToInstall();
@@ -114,7 +132,7 @@ protected function query()
114132
$this->agentsToInstallTo = $this->agentsToInstallTo(); // AI Guidelines, which file do they go, are they separated, or all in one file?
115133
}
116134

117-
protected function enact(): void
135+
private function enact(): void
118136
{
119137
if ($this->installingGuidelines() && ! empty($this->agentsToInstallTo)) {
120138
$this->enactGuidelines();
@@ -130,7 +148,7 @@ protected function enact(): void
130148
/**
131149
* Which IDEs are installed on this developer's machine?
132150
*/
133-
protected function detectInstalledIdes(): array
151+
private function detectInstalledIdes(): array
134152
{
135153
return $this->appDetector->detectInstalled();
136154
}
@@ -139,12 +157,12 @@ protected function detectInstalledIdes(): array
139157
* Specifically want to detect what's in use in _this_ project.
140158
* Just because they have claude code installed doesn't mean they're using it.
141159
*/
142-
protected function detectIdesUsedInProject(): array
160+
private function detectIdesUsedInProject(): array
143161
{
144162
return $this->appDetector->detectInProject(base_path());
145163
}
146164

147-
protected function discoverTools(): array
165+
private function discoverTools(): array
148166
{
149167
$tools = [];
150168
$toolDir = implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'Mcp', 'Tools']);
@@ -165,25 +183,6 @@ protected function discoverTools(): array
165183
return $tools;
166184
}
167185

168-
private function intro()
169-
{
170-
$this->newline();
171-
$header = <<<'HEADER'
172-
██████╗ ██████╗ ██████╗ ███████╗ ████████╗
173-
██╔══██╗ ██╔═══██╗ ██╔═══██╗ ██╔════╝ ╚══██╔══╝
174-
██████╔╝ ██║ ██║ ██║ ██║ ███████╗ ██║
175-
██╔══██╗ ██║ ██║ ██║ ██║ ╚════██║ ██║
176-
██████╔╝ ╚██████╔╝ ╚██████╔╝ ███████║ ██║
177-
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝
178-
HEADER;
179-
foreach (explode(PHP_EOL, $header) as $i => $line) {
180-
echo "{$line}\n";
181-
}
182-
183-
intro('✦ Laravel Boost :: Install :: We Must Ship ✦');
184-
$this->line(' Let\'s give '.$this->colors->bgYellow($this->colors->black($this->projectName)).' a Boost');
185-
}
186-
187186
private function outro(): void
188187
{
189188
$label = 'https://boost.laravel.com/installed';
@@ -217,7 +216,7 @@ private function outro(): void
217216
$paddingLength = (int) (floor(($this->terminal->cols() - mb_strlen($text.$label)) / 2)) - 2;
218217

219218
echo "\033[42m\033[2K".str_repeat(' ', $paddingLength); // Make the entire line have a green background
220-
echo $this->colors->black($this->colors->bold($text.$link)).PHP_EOL;
219+
echo $this->black($this->bold($text.$link)).PHP_EOL;
221220
}
222221

223222
private function hyperlink(string $label, string $url): string

0 commit comments

Comments
 (0)