Passed
Push — master ( a1b0a5...d00cde )
by Alexey
02:47
created

CommandCollector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 64.71%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 47
ccs 11
cts 17
cp 0.6471
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addCommand() 0 9 2
A getCommands() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Console\Command;
4
5
use Venta\Console\Command;
6
use Venta\Contracts\Console\CommandCollector as CommandCollectorContract;
7
use Venta\Contracts\Container\Container;
8
9
/**
10
 * Class Collector
11
 *
12
 * @package Venta\Console\Command
13
 */
14
class CommandCollector implements CommandCollectorContract
15
{
16
17
    /**
18
     * Commands holder
19
     *
20
     * @var Command[]
21
     */
22
    protected $commands = [];
23
24
    /**
25
     * @var Container
26
     */
27
    protected $container;
28
29
    /**
30
     * CommandCollector constructor.
31
     *
32
     * @param Container $container
33
     */
34 2
    public function __construct(Container $container)
35
    {
36 2
        $this->container = $container;
37 2
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42 2
    public function addCommand(string $commandClassName)
43
    {
44 2
        if (!is_subclass_of($commandClassName, Command::class)) {
45 1
            throw new \InvalidArgumentException(
46 1
                sprintf('Provided command "%s" doesn\'t extend Venta\Console\Command class.', $commandClassName)
47
            );
48
        }
49 1
        $this->commands[] = $commandClassName;
50 1
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55 1
    public function getCommands(): array
56
    {
57 1
        return array_map([$this->container, 'get'], $this->commands);
58
    }
59
60
}