Skip to content

Commit a330a78

Browse files
committed
refactor: remove DetectionType enum and update detection strategies to infer types from config
1 parent 7501fda commit a330a78

File tree

11 files changed

+87
-93
lines changed

11 files changed

+87
-93
lines changed

src/Install/CodeEnvironment/ClaudeCode.php

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

55
namespace Laravel\Boost\Install\CodeEnvironment;
66

7-
use Laravel\Boost\Install\Enums\DetectionType;
87
use Laravel\Boost\Install\Enums\Platform;
98

109
class ClaudeCode extends CodeEnvironment
@@ -24,11 +23,9 @@ public function systemDetectionConfig(Platform $platform): array
2423
return match ($platform) {
2524
Platform::Darwin, Platform::Linux => [
2625
'command' => 'which claude',
27-
'type' => DetectionType::Command,
2826
],
2927
Platform::Windows => [
3028
'command' => 'where claude 2>null',
31-
'type' => DetectionType::Command,
3229
],
3330
};
3431
}
@@ -38,7 +35,6 @@ public function projectDetectionConfig(): array
3835
return [
3936
'paths' => ['.claude'],
4037
'files' => ['CLAUDE.md'],
41-
'type' => [DetectionType::Directory, DetectionType::File],
4238
];
4339
}
4440
}

src/Install/CodeEnvironment/CodeEnvironment.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ abstract public function projectDetectionConfig(): array;
5252
public function detectOnSystem(Platform $platform): bool
5353
{
5454
$config = $this->systemDetectionConfig($platform);
55-
$strategy = $this->strategyFactory->make($config['type']);
55+
$strategy = $this->strategyFactory->makeFromConfig($config);
5656

57-
return $strategy->detect($config, $platform->value);
57+
return $strategy->detect($config, $platform);
5858
}
5959

6060
/**
@@ -66,7 +66,7 @@ public function detectOnSystem(Platform $platform): bool
6666
public function detectInProject(string $basePath): bool
6767
{
6868
$config = array_merge($this->projectDetectionConfig(), ['basePath' => $basePath]);
69-
$strategy = $this->strategyFactory->make($config['type']);
69+
$strategy = $this->strategyFactory->makeFromConfig($config);
7070

7171
return $strategy->detect($config);
7272
}

src/Install/CodeEnvironment/Copilot.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Laravel\Boost\Install\CodeEnvironment;
66

7-
use Laravel\Boost\Install\Enums\DetectionType;
87
use Laravel\Boost\Install\Enums\Platform;
98

109
class Copilot extends CodeEnvironment
@@ -23,7 +22,6 @@ public function systemDetectionConfig(Platform $platform): array
2322
{
2423
// Copilot doesn't have system-wide detection as it's an extension/feature
2524
return [
26-
'type' => DetectionType::File,
2725
'files' => [],
2826
];
2927
}
@@ -32,7 +30,6 @@ public function projectDetectionConfig(): array
3230
{
3331
return [
3432
'files' => ['.github/copilot-instructions.md'],
35-
'type' => DetectionType::File,
3633
];
3734
}
3835

src/Install/CodeEnvironment/Cursor.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Laravel\Boost\Install\CodeEnvironment;
66

7-
use Laravel\Boost\Install\Enums\DetectionType;
87
use Laravel\Boost\Install\Enums\Platform;
98

109
class Cursor extends CodeEnvironment
@@ -24,22 +23,19 @@ public function systemDetectionConfig(Platform $platform): array
2423
return match ($platform) {
2524
Platform::Darwin => [
2625
'paths' => ['/Applications/Cursor.app'],
27-
'type' => DetectionType::Directory,
2826
],
2927
Platform::Linux => [
3028
'paths' => [
3129
'/opt/cursor',
3230
'/usr/local/bin/cursor',
3331
'~/.local/bin/cursor',
3432
],
35-
'type' => DetectionType::Directory,
3633
],
3734
Platform::Windows => [
3835
'paths' => [
3936
'%ProgramFiles%\\Cursor',
4037
'%LOCALAPPDATA%\\Programs\\Cursor',
4138
],
42-
'type' => DetectionType::Directory,
4339
],
4440
};
4541
}
@@ -48,7 +44,6 @@ public function projectDetectionConfig(): array
4844
{
4945
return [
5046
'paths' => ['.cursor'],
51-
'type' => DetectionType::Directory,
5247
];
5348
}
5449

src/Install/CodeEnvironment/PhpStorm.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Laravel\Boost\Install\CodeEnvironment;
66

7-
use Laravel\Boost\Install\Enums\DetectionType;
87
use Laravel\Boost\Install\Enums\Platform;
98

109
class PhpStorm extends CodeEnvironment
@@ -24,7 +23,6 @@ public function systemDetectionConfig(Platform $platform): array
2423
return match ($platform) {
2524
Platform::Darwin => [
2625
'paths' => ['/Applications/PhpStorm.app'],
27-
'type' => DetectionType::Directory,
2826
],
2927
Platform::Linux => [
3028
'paths' => [
@@ -33,14 +31,12 @@ public function systemDetectionConfig(Platform $platform): array
3331
'/usr/local/bin/phpstorm',
3432
'~/.local/share/JetBrains/Toolbox/apps/PhpStorm/ch-*',
3533
],
36-
'type' => DetectionType::Directory,
3734
],
3835
Platform::Windows => [
3936
'paths' => [
4037
'%ProgramFiles%\\JetBrains\\PhpStorm*',
4138
'%LOCALAPPDATA%\\JetBrains\\Toolbox\\apps\\PhpStorm\\ch-*',
4239
],
43-
'type' => DetectionType::Directory,
4440
],
4541
};
4642
}
@@ -49,7 +45,6 @@ public function projectDetectionConfig(): array
4945
{
5046
return [
5147
'paths' => ['.idea', '.junie'],
52-
'type' => DetectionType::Directory,
5348
];
5449
}
5550

src/Install/CodeEnvironment/VSCode.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Laravel\Boost\Install\CodeEnvironment;
66

7-
use Laravel\Boost\Install\Enums\DetectionType;
87
use Laravel\Boost\Install\Enums\Platform;
98

109
class VSCode extends CodeEnvironment
@@ -24,18 +23,15 @@ public function systemDetectionConfig(Platform $platform): array
2423
return match ($platform) {
2524
Platform::Darwin => [
2625
'paths' => ['/Applications/Visual Studio Code.app'],
27-
'type' => DetectionType::Directory,
2826
],
2927
Platform::Linux => [
3028
'command' => 'which code',
31-
'type' => DetectionType::Command,
3229
],
3330
Platform::Windows => [
3431
'paths' => [
3532
'%ProgramFiles%\\Microsoft VS Code',
3633
'%LOCALAPPDATA%\\Programs\\Microsoft VS Code',
3734
],
38-
'type' => DetectionType::Directory,
3935
],
4036
};
4137
}
@@ -44,7 +40,6 @@ public function projectDetectionConfig(): array
4440
{
4541
return [
4642
'paths' => ['.vscode'],
47-
'type' => DetectionType::Directory,
4843
];
4944
}
5045

src/Install/CodeEnvironment/Windsurf.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Laravel\Boost\Install\CodeEnvironment;
66

7-
use Laravel\Boost\Install\Enums\DetectionType;
87
use Laravel\Boost\Install\Enums\Platform;
98

109
class Windsurf extends CodeEnvironment
@@ -24,23 +23,20 @@ public function systemDetectionConfig(Platform $platform): array
2423
return match ($platform) {
2524
Platform::Darwin => [
2625
'paths' => ['/Applications/Windsurf.app'],
27-
'type' => DetectionType::Directory,
2826
],
2927
Platform::Linux => [
3028
'paths' => [
3129
'/opt/windsurf',
3230
'/usr/local/bin/windsurf',
3331
'~/.local/bin/windsurf',
3432
],
35-
'type' => DetectionType::Directory,
3633
],
3734
Platform::Windows => [
3835
'paths' => [
3936
'%ProgramFiles%\\Windsurf',
4037
'%ProgramFiles(x86)%\\Windsurf',
4138
'%LOCALAPPDATA%\\Programs\\Windsurf',
4239
],
43-
'type' => DetectionType::Directory,
4440
],
4541
};
4642
}
@@ -49,7 +45,6 @@ public function projectDetectionConfig(): array
4945
{
5046
return [
5147
'files' => ['.windsurfrules.md'],
52-
'type' => DetectionType::File,
5348
];
5449
}
5550

src/Install/CodeEnvironment/Zed.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Laravel\Boost\Install\CodeEnvironment;
66

7-
use Laravel\Boost\Install\Enums\DetectionType;
87
use Laravel\Boost\Install\Enums\Platform;
98

109
class Zed extends CodeEnvironment
@@ -24,22 +23,19 @@ public function systemDetectionConfig(Platform $platform): array
2423
return match ($platform) {
2524
Platform::Darwin => [
2625
'paths' => ['/Applications/Zed.app'],
27-
'type' => DetectionType::Directory,
2826
],
2927
Platform::Linux => [
3028
'paths' => [
3129
'/opt/zed',
3230
'/usr/local/bin/zed',
3331
'~/.local/bin/zed',
3432
],
35-
'type' => DetectionType::Directory,
3633
],
3734
Platform::Windows => [
3835
'paths' => [
3936
'%ProgramFiles%\\Zed',
4037
'%LOCALAPPDATA%\\Programs\\Zed',
4138
],
42-
'type' => DetectionType::Directory,
4339
],
4440
};
4541
}
@@ -48,7 +44,6 @@ public function projectDetectionConfig(): array
4844
{
4945
return [
5046
'paths' => ['.zed'],
51-
'type' => DetectionType::Directory,
5247
];
5348
}
5449

src/Install/Detection/DetectionStrategyFactory.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,56 @@
77
use Illuminate\Container\Container;
88
use InvalidArgumentException;
99
use Laravel\Boost\Install\Contracts\DetectionStrategy;
10-
use Laravel\Boost\Install\Enums\DetectionType;
1110

1211
class DetectionStrategyFactory
1312
{
1413
public function __construct(private readonly Container $container)
1514
{
1615
}
1716

18-
public function make(DetectionType|string|array $type): DetectionStrategy
17+
public function make(string|array $type, array $config = []): DetectionStrategy
1918
{
2019
if (is_array($type)) {
2120
return new CompositeDetectionStrategy(
22-
array_map(fn ($singleType) => $this->make($singleType), $type)
21+
array_map(fn ($singleType) => $this->make($singleType, $config), $type)
2322
);
2423
}
2524

26-
$detectionType = $type instanceof DetectionType ? $type : DetectionType::from($type);
27-
28-
return match ($detectionType) {
29-
DetectionType::Directory => $this->container->make(DirectoryDetectionStrategy::class),
30-
DetectionType::Command => $this->container->make(CommandDetectionStrategy::class),
31-
DetectionType::File => $this->container->make(FileDetectionStrategy::class),
32-
default => throw new InvalidArgumentException("Unknown detection type: {$detectionType->value}"),
25+
return match ($type) {
26+
'directory' => $this->container->make(DirectoryDetectionStrategy::class),
27+
'command' => $this->container->make(CommandDetectionStrategy::class),
28+
'file' => $this->container->make(FileDetectionStrategy::class),
29+
default => throw new InvalidArgumentException("Unknown detection type: {$type}"),
3330
};
3431
}
32+
33+
public function makeFromConfig(array $config): DetectionStrategy
34+
{
35+
$type = $this->inferTypeFromConfig($config);
36+
37+
return $this->make($type, $config);
38+
}
39+
40+
private function inferTypeFromConfig(array $config): string|array
41+
{
42+
$types = [];
43+
44+
if (isset($config['files'])) {
45+
$types[] = 'file';
46+
}
47+
48+
if (isset($config['paths'])) {
49+
$types[] = 'directory';
50+
}
51+
52+
if (isset($config['command'])) {
53+
$types[] = 'command';
54+
}
55+
56+
if (empty($types)) {
57+
throw new InvalidArgumentException('Cannot infer detection type from config keys. Expected one of: files, paths, command');
58+
}
59+
60+
return count($types) === 1 ? $types[0] : $types;
61+
}
3562
}

src/Install/Enums/DetectionType.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)