Test Failed
Pull Request — master (#6)
by
unknown
09:23
created

AbstractCommand::createProcessor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace LF\EnvDiff\Console\Command;
4
5
use LF\EnvDiff\Config;
6
use LF\EnvDiff\IO\ConsoleIO;
7
use LF\EnvDiff\Processor;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Exception\InvalidArgumentException;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
abstract class AbstractCommand extends Command
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 1
    protected function configure()
20
    {
21 1
        $this
22 1
            ->addArgument('dist', InputOption::VALUE_REQUIRED, 'From file', Config::DEFAULT_DIST)
23 1
            ->addArgument('target', InputOption::VALUE_REQUIRED, 'To file', Config::DEFAULT_TARGET)
24 1
            ->addOption('remove-outdated', 'r', InputOption::VALUE_NONE, 'Remove old env variables', false);
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     *
30
     * @throws InvalidArgumentException
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $config    = $this->createConfig($input);
35
        $processor = $this->createProcessor($input, $output);
36
37
        $this->doExecute($processor, $config);
38
39
        return 0;
40
    }
41
42
    /**
43
     * @param InputInterface $input
44
     *
45
     * @return Config
46
     *
47
     * @throws InvalidArgumentException
48
     */
49
    private function createConfig(InputInterface $input)
50
    {
51
        $dist           = $input->getArgument('dist');
52
        $target         = $input->getArgument('target');
53
        $removeOutdated = $input->getOption('remove-outdated');
54
55
        return new Config($dist, $target, !$removeOutdated);
56
    }
57
58
    /**
59
     * @param InputInterface  $input
60
     * @param OutputInterface $output
61
     *
62
     * @return Processor
63
     */
64
    private function createProcessor(InputInterface $input, OutputInterface $output)
65
    {
66
        return new Processor(new ConsoleIO($input, $output));
67
    }
68
69
    /**
70
     * @param Processor $processor
71
     * @param Config    $config
72
     */
73
    abstract protected function doExecute(Processor $processor, Config $config);
74
}
75