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

CommandCollector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1.0156
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
}