InstallCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Zalas\Toolbox\Cli\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Zalas\Toolbox\Runner\Runner;
10
use Zalas\Toolbox\Tool\Filter;
11
use Zalas\Toolbox\UseCase\InstallTools;
12
13
final class InstallCommand extends Command
14
{
15
    use DefaultTag;
16
    use DefaultTargetDir;
17
18
    public const NAME = 'install';
19
20
    private InstallTools $useCase;
21
    private Runner $runner;
22
23 13
    public function __construct(InstallTools $useCase, Runner $runner)
24
    {
25 13
        parent::__construct(self::NAME);
26
27 13
        $this->useCase = $useCase;
28 13
        $this->runner = $runner;
29
    }
30
31 13
    protected function configure(): void
32
    {
33 13
        $this->setDescription('Installs tools');
34 13
        $this->addOption('dry-run', null, InputOption::VALUE_NONE, 'Output the command without executing it');
35 13
        $this->addOption('target-dir', null, InputOption::VALUE_REQUIRED, 'The target installation directory', $this->defaultTargetDir());
36 13
        $this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude', $this->defaultExcludeTag());
37 13
        $this->addOption('tag', 't', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to filter by', $this->defaultTag());
38
    }
39
40 4
    protected function execute(InputInterface $input, OutputInterface $output): int
41
    {
42 4
        return $this->runner->run(\call_user_func($this->useCase, new Filter($input->getOption('exclude-tag'), $input->getOption('tag'))));
43
    }
44
}
45