Passed
Push — master ( 7af546...dfd36b )
by Arthur
04:54 queued 15s
created

SeedCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
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 1
    public function __construct(Resolver $resolver, BootstrapRegistrarService $service)
19
    {
20 1
        parent::__construct($resolver);
21 1
        $this->service = $service;
22 1
    }
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return void
28
     */
29
    public function handle()
30
    {
31
        if (!$this->confirmToProceed()) {
32
            return;
33
        }
34
35
        $this->resolver->setDefaultConnection($this->getDatabase());
36
37
        Model::unguarded(function () {
38
            foreach ($this->getSeeders() as $seeder) {
39
                $seeder = $this->laravel->make($seeder);
40
                $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