|
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
|
|
|
|