Commands   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A addCommand() 0 3 1
A __construct() 0 3 1
A add() 0 12 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Cli;
6
7
class Commands
8
{
9
    protected array $commands = [];
10
11 21
    public function __construct(Command|array $commands = [])
12
    {
13 21
        $this->add($commands);
14
    }
15
16 21
    public function add(Commands|Command|array $commands): void
17
    {
18 21
        if (is_array($commands)) {
0 ignored issues
show
introduced by
The condition is_array($commands) is always true.
Loading history...
19 19
            foreach ($commands as $command) {
20 18
                $this->add($command);
21
            }
22 21
        } elseif ($commands instanceof Commands) {
23 2
            foreach ($commands->get() as $command) {
24 2
                $this->addCommand($command);
25
            }
26
        } else {
27 21
            $this->addCommand($commands);
28
        }
29
    }
30
31 21
    public function get(): array
32
    {
33 21
        return $this->commands;
34
    }
35
36 21
    protected function addCommand(Command $command): void
37
    {
38 21
        $this->commands[] = $command;
39
    }
40
}
41