rawilk /
laravel-modules
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Rawilk\LaravelModules\Commands\Other; |
||||
| 4 | |||||
| 5 | use Illuminate\Console\Command; |
||||
| 6 | use Rawilk\LaravelModules\Json; |
||||
| 7 | use Rawilk\LaravelModules\Process\Installer; |
||||
| 8 | |||||
| 9 | class InstallCommand extends Command |
||||
| 10 | { |
||||
| 11 | /** @var string */ |
||||
| 12 | protected $signature = 'module:install |
||||
| 13 | {name? : The name of the module to install} |
||||
| 14 | {version? : The version of the module to install} |
||||
| 15 | {--timeout= : The process timeout} |
||||
| 16 | {--path= : The installation path} |
||||
| 17 | {--type= : The type of installation} |
||||
| 18 | {--tree : Install the module as a git subtree} |
||||
| 19 | {--no-update : Disables the automatic update of the dependencies}'; |
||||
| 20 | |||||
| 21 | /** @var string */ |
||||
| 22 | protected $description = 'Install the specified module by a given package name (vendor/name).'; |
||||
| 23 | |||||
| 24 | public function handle(): void |
||||
| 25 | { |
||||
| 26 | if ($this->argument('name') === null) { |
||||
| 27 | $this->installFromFile(); |
||||
| 28 | |||||
| 29 | return; |
||||
| 30 | } |
||||
| 31 | |||||
| 32 | $this->install( |
||||
| 33 | $this->argument('name'), |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 34 | $this->argument('version'), |
||||
|
0 ignored issues
–
show
It seems like
$this->argument('version') can also be of type string[]; however, parameter $version of Rawilk\LaravelModules\Co...stallCommand::install() does only seem to accept null|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 35 | $this->option('type'), |
||||
| 36 | $this->option('tree') |
||||
|
0 ignored issues
–
show
$this->option('tree') of type string is incompatible with the type boolean|null expected by parameter $tree of Rawilk\LaravelModules\Co...stallCommand::install().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 37 | ); |
||||
| 38 | } |
||||
| 39 | |||||
| 40 | private function install(string $name, ?string $version = 'dev-master', ?string $type = 'composer', ?bool $tree = false): void |
||||
| 41 | { |
||||
| 42 | $installer = new Installer( |
||||
| 43 | $name, |
||||
| 44 | $version, |
||||
| 45 | $type ?: $this->option('type'), |
||||
| 46 | $tree ?: $this->option('tree') |
||||
|
0 ignored issues
–
show
It seems like
$tree ?: $this->option('tree') can also be of type string; however, parameter $tree of Rawilk\LaravelModules\Pr...nstaller::__construct() does only seem to accept boolean, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 47 | ); |
||||
| 48 | |||||
| 49 | $installer->setRepository($this->laravel['modules']); |
||||
| 50 | |||||
| 51 | $installer->setConsole($this); |
||||
| 52 | |||||
| 53 | if ($timeout = $this->option('timeout')) { |
||||
| 54 | $installer->setTimeout($timeout); |
||||
|
0 ignored issues
–
show
$timeout of type string is incompatible with the type integer expected by parameter $timeout of Rawilk\LaravelModules\Pr...Installer::setTimeout().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 55 | } |
||||
| 56 | |||||
| 57 | $installer->run(); |
||||
| 58 | |||||
| 59 | if (! $this->option('no-update')) { |
||||
| 60 | $this->call('module:update', [ |
||||
| 61 | 'module' => $installer->getModuleName() |
||||
| 62 | ]); |
||||
| 63 | } |
||||
| 64 | } |
||||
| 65 | |||||
| 66 | private function installFromFile(): void |
||||
| 67 | { |
||||
| 68 | if (! file_exists($path = base_path('modules.json'))) { |
||||
| 69 | $this->error("File 'modules.json' does not exist in your project root."); |
||||
| 70 | |||||
| 71 | return; |
||||
| 72 | } |
||||
| 73 | |||||
| 74 | $modules = Json::make($path); |
||||
| 75 | |||||
| 76 | $dependencies = $modules->get('require', []); |
||||
| 77 | |||||
| 78 | foreach ($dependencies as $module) { |
||||
| 79 | $module = collect($module); |
||||
| 80 | |||||
| 81 | $this->install( |
||||
| 82 | $module->get('name'), |
||||
| 83 | $module->get('version'), |
||||
| 84 | $module->get('type') |
||||
| 85 | ); |
||||
| 86 | } |
||||
| 87 | } |
||||
| 88 | } |
||||
| 89 |