SeedCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 22.22%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 45
ccs 4
cts 18
cp 0.2222
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 18 5
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 26
    public function __construct(Resolver $resolver, BootstrapRegistrarService $service)
19
    {
20 26
        parent::__construct($resolver);
21 26
        $this->service = $service;
22 26
    }
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['class']);
40
                if (! isset($seeder->enabled) || $seeder->enabled) {
41
                    $seeder->__invoke();
42
                }
43
            }
44
        });
45
46
        $this->info('Database seeding completed successfully.');
47
    }
48
49
    protected function getSeeders(): array
50
    {
51
        $this->service = $this->laravel->make(BootstrapRegistrarService::class);
52
53
        return $this->service->getSeeders() ?? [];
54
    }
55
}
56