|
7 | 7 | use function Tempest\root_path; |
8 | 8 | use function Tempest\Support\str; |
9 | 9 |
|
10 | | -/** |
11 | | - * @phpstan-require-implements \Tempest\Core\Installer |
12 | | - */ |
13 | | -trait IsComponentInstaller |
14 | | -{ |
15 | | - use PublishesFiles; |
16 | | - |
17 | | - private function installMainNamespace(): void |
| 10 | +if (trait_exists(PublishesFiles::class)) { |
| 11 | + /** |
| 12 | + * @phpstan-require-implements \Tempest\Core\Installer |
| 13 | + */ |
| 14 | + trait IsComponentInstaller |
18 | 15 | { |
19 | | - if ($this->composer->mainNamespace !== null) { |
20 | | - return; |
21 | | - } |
| 16 | + use PublishesFiles; |
22 | 17 |
|
23 | | - if (! $this->confirm('Tempest detected no main project namespace. Do you want to create it?', default: true)) { |
24 | | - return; |
25 | | - } |
| 18 | + private function installMainNamespace(): void |
| 19 | + { |
| 20 | + if ($this->composer->mainNamespace !== null) { |
| 21 | + return; |
| 22 | + } |
26 | 23 |
|
27 | | - $appPath = root_path($this->ask('Which path do you wish to use as your main project directory?', default: 'app/')); |
| 24 | + if (! $this->confirm('Tempest detected no main project namespace. Do you want to create it?', default: true)) { |
| 25 | + return; |
| 26 | + } |
28 | 27 |
|
29 | | - $defaultAppNamespace = str($appPath) |
30 | | - ->replaceStart(root_path(), '') |
31 | | - ->trim('/') |
32 | | - ->explode('/') |
33 | | - ->map(fn (string $part) => ucfirst($part)) |
34 | | - ->implode('\\') |
35 | | - ->append('\\') |
36 | | - ->toString(); |
| 28 | + $appPath = root_path($this->ask('Which path do you wish to use as your main project directory?', default: 'app/')); |
37 | 29 |
|
38 | | - $appNamespace = str($this->ask('Which namespace do you wish to use?', default: $defaultAppNamespace)) |
39 | | - ->trim('\\') |
40 | | - ->append('\\') |
41 | | - ->toString(); |
| 30 | + $defaultAppNamespace = str($appPath) |
| 31 | + ->replaceStart(root_path(), '') |
| 32 | + ->trim('/') |
| 33 | + ->explode('/') |
| 34 | + ->map(fn (string $part) => ucfirst($part)) |
| 35 | + ->implode('\\') |
| 36 | + ->append('\\') |
| 37 | + ->toString(); |
42 | 38 |
|
43 | | - if (! is_dir($appPath)) { |
44 | | - mkdir($appPath, recursive: true); |
45 | | - } |
| 39 | + $appNamespace = str($this->ask('Which namespace do you wish to use?', default: $defaultAppNamespace)) |
| 40 | + ->trim('\\') |
| 41 | + ->append('\\') |
| 42 | + ->toString(); |
46 | 43 |
|
47 | | - $this->composer |
48 | | - ->addNamespace( |
49 | | - $appNamespace, |
50 | | - $appPath, |
51 | | - ) |
52 | | - ->save(); |
| 44 | + if (! is_dir($appPath)) { |
| 45 | + mkdir($appPath, recursive: true); |
| 46 | + } |
53 | 47 |
|
54 | | - $this->success("Project namespace created: {$appPath}"); |
55 | | - } |
| 48 | + $this->composer |
| 49 | + ->addNamespace( |
| 50 | + $appNamespace, |
| 51 | + $appPath, |
| 52 | + ) |
| 53 | + ->save(); |
56 | 54 |
|
57 | | - private function updateComposer(): void |
58 | | - { |
59 | | - if ($this->confirm(question: 'Run composer update?', default: true)) { |
60 | | - $this->composer->executeUpdate(); |
| 55 | + $this->success("Project namespace created: {$appPath}"); |
| 56 | + } |
| 57 | + |
| 58 | + private function updateComposer(): void |
| 59 | + { |
| 60 | + if ($this->confirm(question: 'Run composer update?', default: true)) { |
| 61 | + $this->composer->executeUpdate(); |
| 62 | + } |
61 | 63 | } |
62 | 64 | } |
63 | 65 | } |
0 commit comments