GenericCommand::setUsages()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 * This file is part of the phpspec-console package.
4
 * (c) 2017 Timo Michna <timomichna/yahoo.de>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Tidal\PhpSpec\ConsoleExtension\Command;
11
12
use Symfony\Component\Console\Command\Command;
13
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\{
14
    ConfiguratorInterface,
15
    CommandInterface
16
};
17
use Tidal\PhpSpec\ConsoleExtension\Contract\WriterInterface;
18
use Tidal\PhpSpec\ConsoleExtension\Behavior\Command\{
19
    ConfigurableTrait,
20
    HasInputTrait,
21
    HasOutputTrait
22
};
23
use Tidal\PhpSpec\ConsoleExtension\Behavior\{
24
    HasWriterTrait,
25
    HasContainerTrait
26
};
27
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\ConfigInterface as Config;
28
29
/**
30
 * class Tidal\PhpSpec\ConsoleExtension\Command\GenericCommand
31
 */
32
class GenericCommand extends Command implements CommandInterface
33
{
34
    use ConfigurableTrait,
35
        HasInputTrait,
36
        HasOutputTrait,
37
        HasWriterTrait,
38
        HasContainerTrait;
39
40
    /**
41
     * GenericCommand constructor.
42
     * @param WriterInterface $writer
43
     * @param ConfiguratorInterface $configurator
44
     * @param array|null $config
45
     */
46
    public function __construct(WriterInterface $writer, ConfiguratorInterface $configurator, ?array $config = [])
47
    {
48
        if ($config !== null) {
49
            $configurator->setConfig($config);
50
            if (isset($config[Config::NAME_KEY])) {
51
                $this->setName($config[Config::NAME_KEY]);
52
            }
53
        }
54
        $this->setWriter($writer);
55
        $this->setConfigurator($configurator);
56
        parent::__construct();
57
    }
58
59
    protected function configure()
60
    {
61
        $this
62
            ->getConfigurator()
63
            ->configure($this);
64
    }
65
66
    /**
67
     * @param string[] $usages
68
     */
69
    public function setUsages(array $usages = [])
70
    {
71
        foreach ($usages as $usage) {
72
            $this->addUsage($usage);
73
        }
74
    }
75
}
76
77