Test Failed
Branch master (b3e807)
by Alexey
03:28
created

CommandCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addCommand() 0 9 2
A getCommands() 0 4 1
A getIterator() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Console;
4
5
use ArrayIterator;
6
use InvalidArgumentException;
7
use Symfony\Component\Console\Command\Command;
8
use Venta\Contracts\Console\CommandCollection as CommandCollectionContract;
9
10
/**
11
 * Class CommandCollection
12
 *
13
 * @package Venta\Console
14
 */
15
class CommandCollection implements CommandCollectionContract
16
{
17
    /**
18
     * @var string[]
19
     */
20
    protected $commands = [];
21
22
    /**
23
     * @inheritDoc
24
     */
25
    public function addCommand(string $commandClass)
26
    {
27
        if (!is_subclass_of($commandClass, Command::class)) {
28
            throw new InvalidArgumentException(
29
                sprintf('Provided command "%s" is not subclass of "%s" class.', $commandClass, Command::class)
30
            );
31
        }
32
        $this->commands[] = $commandClass;
33
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38
    public function getCommands(): array
39
    {
40
        return array_unique($this->commands);
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    public function getIterator()
47
    {
48
        return new ArrayIterator($this->getCommands());
49
    }
50
}