ModuleSeed::proceed()   B
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 14
nc 2
nop 0
1
<?php
2
3
namespace Mnabialek\LaravelModular\Console\Commands;
4
5
use Mnabialek\LaravelModular\Models\Module;
6
use Mnabialek\LaravelModular\Console\Traits\ModuleCreator;
7
use Mnabialek\LaravelModular\Console\Traits\ModuleVerification;
8
9
class ModuleSeed extends BaseCommand
10
{
11
    use ModuleVerification;
12
    use ModuleCreator;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'module:seed 
20
    {module* : Module name or multiple module names}
21
    {--class= : Class name that exists inside module seeds directory without namespace}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Runs main seeders for selected modules';
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function proceed()
34
    {
35
        $modules = collect($this->argument('module'))->unique();
36
        $modules = $this->verifyActive($modules);
37
        if ($modules === false || $modules->isEmpty()) {
38
            return;
39
        }
40
41
        $options = $this->getOptions();
42
43
        $modules->each(function ($module) use ($options) {
44
            /* @var Module $module */
45
            $class = $module->seederClass($this->option('class'));
0 ignored issues
show
Bug introduced by
It seems like $this->option('class') targeting Illuminate\Console\Command::option() can also be of type array; however, Mnabialek\LaravelModular...s\Module::seederClass() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
46
47
            $result = $this->call('db:seed',
48
                array_merge($options, ['--class' => $class]));
49
50
            if ($result != 0) {
51
                $this->error("[Module {$module->name()}] There was a problem with running seeder {$class}");
52
53
                return;
54
            }
55
            $this->info("[Module {$module->name()}] Seeded: {$class}");
56
        });
57
    }
58
}
59