Passed
Push — master ( efb428...d376d7 )
by Timo
02:13
created

GenericInlineConfigCommand::setUsages()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
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
14
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\{
15
    ConfiguratorInterface
16
};
17
use Tidal\PhpSpec\ConsoleExtension\Contract\WriterInterface;
18
use Tidal\PhpSpec\ConsoleExtension\Behavior\Command\ConfigurableTrait;
19
use Tidal\PhpSpec\ConsoleExtension\Behavior\HasWriterTrait;
20
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\ConfigInterface as Config;
21
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\InlineConfigCommandInterface;
22
23
/**
24
 * class Tidal\PhpSpec\ConsoleExtension\Command\GenericInlineConfigCommand
25
 */
26
class GenericInlineConfigCommand extends Command implements InlineConfigCommandInterface
27
{
28
    use ConfigurableTrait,
29
        HasWriterTrait;
30
31
    /**
32
     * CONFIG
33
     */
34
    public const NAME = 'inline-config-command';
35
    public const DESCRIPTION = 'generic inline config command';
36
    public const HIDDEN = false;
37
    public const USAGES = [];
38
    public const HELP = '';
39
    public const ARGUMENTS = [];
40
    public const OPTIONS = [];
41
42
    /**
43
     * GenericInlineConfigCommand constructor.
44
     * @param WriterInterface $writer
45
     * @param ConfiguratorInterface $configurator
46
     * @param array|null $config
47
     */
48
    public function __construct(WriterInterface $writer, ConfiguratorInterface $configurator, ?array $config = [])
49
    {
50
        if ($config !== null) {
51
            $configurator->setConfig($config);
52
            if (isset($config[Config::NAME_KEY])) {
53
                $this->setName($config[Config::NAME_KEY]);
54
            }
55
        }
56
        $this->setWriter($writer);
57
        $this->setConfigurator($configurator);
58
        parent::__construct();
59
    }
60
61
    protected function configure()
62
    {
63
        $this
64
            ->getConfigurator()
65
            ->configure($this);
66
    }
67
68
    /**
69
     * @param string[] $usages
70
     */
71
    public function setUsages(array $usages = [])
72
    {
73
        foreach ($usages as $usage) {
74
            $this->addUsage($usage);
75
        }
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function getConfig(): array
82
    {
83
        return [
84
            Config::NAME_KEY => static::NAME,
85
            Config::DESCRIPTION_KEY => static::DESCRIPTION,
86
            Config::HELP_KEY => static::HELP,
87
            Config::HIDDEN_KEY => static::HIDDEN,
88
            Config::ARGUMENTS_KEY => static::ARGUMENTS,
89
            Config::OPTIONS_KEY => static::OPTIONS,
90
        ];
91
    }
92
}
93
94