Passed
Push — master ( 756a96...c3a1af )
by Arthur
06:27
created

SeedCommand::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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