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

FixCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

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