Passed
Push — master ( 67253e...1a1f73 )
by Arthur
04:53 queued 11s
created

SeedCommand::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 2
nop 0
dl 0
loc 16
ccs 8
cts 9
cp 0.8889
crap 3.0123
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Foundation\Console;
4
5
use Foundation\Services\BootstrapRegistrarService;
6
use Illuminate\Database\ConnectionResolverInterface as Resolver;
7
use Illuminate\Database\Eloquent\Model;
8
9
class SeedCommand extends \Illuminate\Database\Console\Seeds\SeedCommand
10
{
11
    /**
12
     * The service that registers all module entities.
13
     *
14
     * @var BootstrapRegistrarService
15
     */
16
    protected $service;
17
18 17
    public function __construct(Resolver $resolver, BootstrapRegistrarService $service)
19
    {
20 17
        parent::__construct($resolver);
21 17
        $this->service = $service;
22 17
    }
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return void
28
     */
29 17
    public function handle()
30
    {
31 17
        if (!$this->confirmToProceed()) {
32
            return;
33
        }
34
35 17
        $this->resolver->setDefaultConnection($this->getDatabase());
36
37
        Model::unguarded(function () {
38 17
            foreach ($this->getSeeders() as $seeder) {
39 17
                $seeder = $this->laravel->make($seeder);
40 17
                $seeder->__invoke();
41
            }
42 17
        });
43
44 17
        $this->info('Database seeding completed successfully.');
45 17
    }
46
47 17
    protected function getSeeders(): array
48
    {
49 17
        $this->service = $this->laravel->make(BootstrapRegistrarService::class);
50
51 17
        return $this->service->getSeeders() ?? [];
52
    }
53
}
54