Console   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 14
c 0
b 0
f 0
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultCommands() 0 23 6
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jellyfish\Application;
6
7
use Jellyfish\Kernel\KernelInterface;
8
use Symfony\Component\Console\Application as BaseApplication;
9
use Symfony\Component\Console\Command\Command;
10
11
use function count;
12
use function is_array;
13
14
class Console extends BaseApplication
15
{
16
    /**
17
     * @var \Jellyfish\Kernel\KernelInterface
18
     */
19
    protected $kernel;
20
21
    /**
22
     * @param \Jellyfish\Kernel\KernelInterface $kernel
23
     */
24
    public function __construct(KernelInterface $kernel)
25
    {
26
        parent::__construct('Jellyfish', '1.0.0');
27
28
        $this->kernel = $kernel;
29
    }
30
31
    /**
32
     * @return \Symfony\Component\Console\Command\Command[]
33
     */
34
    protected function getDefaultCommands(): array
35
    {
36
        $defaultCommands = parent::getDefaultCommands();
37
38
        if (!$this->kernel->getContainer()->offsetExists('commands')) {
39
            return $defaultCommands;
40
        }
41
42
        $commandsToAdd = $this->kernel->getContainer()->offsetGet('commands');
43
44
        if (!is_array($commandsToAdd) || count($commandsToAdd) === 0) {
45
            return $defaultCommands;
46
        }
47
48
        foreach ($commandsToAdd as $command) {
49
            if (!$command instanceof Command) {
50
                continue;
51
            }
52
53
            $defaultCommands[] = $command;
54
        }
55
56
        return $defaultCommands;
57
    }
58
}
59