Application::getDefaultCommands()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 11
nc 5
nop 0
dl 0
loc 23
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dandelion\Console;
6
7
use Pimple\Container;
8
use Symfony\Component\Console\Application as SymfonyApplication;
9
use Symfony\Component\Console\Command\Command;
10
11
use function count;
12
use function is_array;
13
14
class Application extends SymfonyApplication
15
{
16
    public const NAME = 'Monorepo';
17
    public const VERSION = '1.0.0';
18
19
    /**
20
     * @var \Pimple\Container
21
     */
22
    protected $container;
23
24
    /**
25
     * @param \Pimple\Container $container
26
     */
27
    public function __construct(Container $container)
28
    {
29
        parent::__construct(static::NAME, static::VERSION);
30
31
        $this->container = $container;
32
    }
33
34
    /**
35
     * @return \Symfony\Component\Console\Command\Command[]
36
     */
37
    protected function getDefaultCommands(): array
38
    {
39
        $defaultCommands = parent::getDefaultCommands();
40
41
        if (!$this->container->offsetExists('commands')) {
42
            return $defaultCommands;
43
        }
44
45
        $commandsToAdd = $this->container->offsetGet('commands');
46
47
        if (!is_array($commandsToAdd) || count($commandsToAdd) === 0) {
48
            return $defaultCommands;
49
        }
50
51
        foreach ($commandsToAdd as $command) {
52
            if (!$command instanceof Command) {
53
                continue;
54
            }
55
56
            $defaultCommands[] = $command;
57
        }
58
59
        return $defaultCommands;
60
    }
61
}
62