Passed
Push — master ( 9645f3...34dd33 )
by Konstantinos
01:59
created

AnalyzeCommand::configure()   A

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 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpNsFixer\Console;
4
5
use PhpNsFixer\Finder\FileFinder;
6
use PhpNsFixer\Runner\Runner;
7
use PhpNsFixer\Runner\RunnerOptions;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
final class AnalyzeCommand extends Command
14
{
15
    /**
16
     * Configures the current command.
17
     *
18
     * @return void
19
     */
20 2
    protected function configure()
21
    {
22 2
        $this->setName('analyze');
23 2
        $this->setDefinition([
24 2
            new InputArgument('path', InputArgument::REQUIRED, 'The path.'),
25 2
            new InputOption('prefix', 'P', InputOption::VALUE_REQUIRED, 'Namespace prefix.'),
26 2
            new InputOption('skip-empty', 'E', InputOption::VALUE_NONE, 'Skip files without namespace.'),
27
        ]);
28 2
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 2
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35 2
        $files = FileFinder::list(strval($input->getArgument('path')));
36
37 2
        $this->progressStart($output, $files);
38
39 2
        $runnerOptions = new RunnerOptions(
40 2
            $files,
41 2
            strval($input->getOption('prefix')) ?? '',
42 2
            boolval($input->getOption('skip-empty')) ?? false,
43 2
            true
44
        );
45 2
        $problematicFiles = (new Runner($runnerOptions, $this->dispatcher))->run();
46
47 2
        $this->progressFinish($output);
48
49 2
        $this->printResults($output, $problematicFiles);
50
51 2
        return $problematicFiles->count();
52
    }
53
}
54