Completed
Push — master ( 58d3fb...59de8c )
by Lexey
05:17
created

AbstractCommand::createProcessor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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