CoreSeedCommand   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 7
dl 0
loc 52
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 30 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\Console\Commands;
6
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Facades\Artisan;
9
use Symfony\Component\Console\Input\ArrayInput;
10
use Symfony\Component\Console\Output\BufferedOutput;
11
12
class CoreSeedCommand extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'cortex:seed';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Seed Cortex Data.';
27
28
    /**
29
     * Execute the console command.
30
     *
31
     * @return void
32
     */
33
    public function handle(): void
34
    {
35
        $commands = collect(Artisan::all())->filter(function ($command) {
36
            return mb_strpos($command->getName(), 'cortex:seed:') !== false;
37
        })->filter(function ($command) {
38
            return $command->getName() !== 'cortex:seed:auth';
39
        })->flatten();
40
41
        $progressBar = $this->output->createProgressBar($commands->count());
42
        $progressBar->setBarCharacter('<fg=green>▒</>');
43
        $progressBar->setEmptyBarCharacter('<fg=white>▒</>');
44
        $progressBar->setProgressCharacter('<fg=green>➤</>');
45
        $progressBar->setFormat("<fg=yellow>{$this->description}. (Step %current% / %max%)</>\n[%bar%] %percent%%\nElapsed Time: %elapsed%");
46
        $progressBar->start();
47
48
        $output = new BufferedOutput();
49
        $commands->each(function (Command $command) use ($progressBar, $output) {
50
            $command->run(new ArrayInput([]), $output);
51
            $progressBar->advance();
52
        });
53
54
        $progressBar->finish();
55
56
        $this->laravel['log']->channel('installer')->debug("\n".$output->fetch());
57
58
        $this->line('');
59
        $this->line('');
60
61
        $this->call('cortex:seed:auth');
62
    }
63
}
64