Passed
Push — master ( 660c80...17f60a )
by Arthur
08:30
created

SeedCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
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
    public function __construct(Resolver $resolver, BootstrapRegistrarService $service)
19
    {
20
        parent::__construct($resolver);
21
        $this->service = $service;
22
    }
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
                $seeder = $this->laravel->make($seeder);
41
                $seeder->__invoke();
42
            }
43
        });
44
45
        $this->info('Database seeding completed successfully.');
46
    }
47
48
    protected function getSeeders(): array
49
    {
50
        $this->service = $this->laravel->make(BootstrapRegistrarService::class);
51
        return $this->service->getSeeders() ?? [];
52
    }
53
}
54