SeedCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
B actionIndex() 0 31 6
A __construct() 0 4 1
1
<?php
2
3
namespace App\Ship\Command;
4
5
use Rudra\Container\Facades\Rudra;
6
use Rudra\Cli\ConsoleFacade as Cli;
7
use App\Ship\Utils\Database\LoggerAdapter;
8
9
class SeedCommand extends LoggerAdapter
10
{
11
    public function __construct()
12
    {
13
        $this->table = "rudra_seeds";
14
        parent::__construct();
15
    }
16
17
    public function actionIndex(): void
18
    {
19
        Cli::printer("Enter container (empty for Ship): ", "magneta");
20
        $container = ucfirst(str_replace(PHP_EOL, "", Cli::reader()));
21
22
        if (!empty($container)) {
23
            $fileList  = array_slice(scandir(str_replace('/', DIRECTORY_SEPARATOR, Rudra::config()->get('app.path') . "/app/Containers/" . $container . "/Seed/")), 2);
24
            $namespace = "App\\Containers\\$container\\Seed\\";
25
        } else {
26
            $fileList  = array_slice(scandir(str_replace('/', DIRECTORY_SEPARATOR, Rudra::config()->get('app.path') . "/app/Ship/Seed/")), 2);
27
            $namespace = "App\\Ship\\Seed\\";
28
        }
29
30
        if (!$this->isTable()) {
31
            $this->up();
32
        }
33
34
        foreach ($fileList as $filename) {
35
36
            $seedName = $namespace . strstr($filename, '.', true);
37
38
            if ($seedName === 'App\Ship\Seed\AbstractSeed') {
39
                continue;
40
            }
41
42
            if ($this->checkLog($seedName)) {
43
                Cli::printer("The $seedName is already seeded" . PHP_EOL, "light_yellow");
44
            } else {
45
                (new $seedName)->create();
46
                Cli::printer("The $seedName was seed" . PHP_EOL, "light_green");
47
                $this->writeLog($seedName);
48
            }
49
        }
50
    }
51
}
52