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

SeedCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 23.53%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 43
ccs 4
cts 17
cp 0.2353
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 3
A __construct() 0 4 1
A getSeeders() 0 5 1
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