AnalyzeCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 17
ccs 8
cts 8
cp 1
crap 3
rs 9.9666
1
<?php
2
3
namespace PhpNsFixer\Console;
4
5
use Symfony\Component\Console\Input\ArrayInput;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
final class AnalyzeCommand extends Command
12
{
13
    /**
14
     * Configures the current command.
15
     *
16
     * @return void
17
     */
18 2
    protected function configure()
19
    {
20 2
        $this->setName('analyze')->setDescription('Analyzes a directory');
21 2
        $this->setDefinition([
22 2
            new InputArgument('path', InputArgument::REQUIRED, 'The path.'),
23 2
            new InputOption('prefix', 'P', InputOption::VALUE_REQUIRED, 'Namespace prefix.'),
24 2
            new InputOption('skip-empty', 'E', InputOption::VALUE_NONE, 'Skip files without namespace.'),
25
        ]);
26 2
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 2
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $arguments = [
34 2
            'command'   => 'fix',
35 2
            'path'      => $input->getArgument('path'),
36
            '--dry-run' => true,
37
        ];
38
39 2
        if ($input->hasOption('prefix')) {
40 2
            $arguments['--prefix'] = $input->getOption('prefix');
41
        }
42
43 2
        if ($input->hasOption('skip-empty')) {
44 2
            $arguments['--skip-empty'] = '';
45
        }
46
47 2
        return $this->getApplication()->find('fix')->run(new ArrayInput($arguments), $output);
48
    }
49
}
50