DatabaseSeedCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 58
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 28 5
1
<?php
2
3
namespace Jumilla\Versionia\Laravel\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Console\ConfirmableTrait;
7
use Jumilla\Versionia\Laravel\Migrator;
8
9
class DatabaseSeedCommand extends Command
10
{
11
    use DatabaseCommandTrait;
12
    use ConfirmableTrait;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'database:seed
20
        {name? : the name of seed.}
21
        {--force : Force the operation to run when in production.}
22
    ';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Insert seed to database';
30
31
    /**
32
     * Execute the console command.
33
     *
34
     * @param \Jumilla\Versionia\Laravel\Migrator $migrator
35
     *
36
     * @return mixed
37
     */
38
    public function handle(Migrator $migrator)
39
    {
40
        if (!$this->confirmToProceed()) {
41
            return;
42
        }
43
44
        $seed = $this->argument('name') ?: $migrator->defaultSeed();
45
46
        if (!$seed) {
47
            $this->error('Default seed is not defined.');
48
49
            return;
50
        }
51
52
        $class = $migrator->seedClass($seed);
53
54
        if (!$class) {
55
            $this->error("Seed '$seed' is not defined.");
56
57
            return;
58
        }
59
60
        $this->infoSeedRun($seed, $class);
61
62
        $seeder = new $class();
63
64
        $seeder->setCommand($this)->run();
65
    }
66
}
67