DumpCommand::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Other;
4
5
use Illuminate\Console\Command;
6
7
class DumpCommand extends Command
8
{
9
    /** @var string */
10
    protected $signature = 'module:dump
11
                            {module? : The module to dump-autoload for}';
12
13
    /** @var string */
14
    protected $description = 'Dump-autoload for the specified module or all modules.';
15
16
    public function handle(): void
17
    {
18
        $this->info('Generating optimized autoload modules.');
19
20
        if ($module = $this->argument('module')) {
21
            $this->dump($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type string[]; however, parameter $name of Rawilk\LaravelModules\Co...her\DumpCommand::dump() does only seem to accept 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 ignore-type  annotation

21
            $this->dump(/** @scrutinizer ignore-type */ $module);
Loading history...
22
        } else {
23
            /** @var \Rawilk\LaravelModules\Module $module */
24
            foreach ($this->laravel['modules']->all() as $module) {
25
                $this->dump($module->getStudlyName());
26
            }
27
        }
28
    }
29
30
    private function dump(string $name): void
31
    {
32
        /** @var \Rawilk\LaravelModules\Module $module */
33
        $module = $this->laravel['modules']->findOrFail($name);
34
35
        $this->line("<comment>Running for module</comment>: {$module}");
36
37
        chdir($module->getPath());
38
39
        passthru('composer dump -o -n -q');
40
    }
41
}
42