AnalyzeCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
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