InstallCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 30
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 7 1
A execute() 0 3 1
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