1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Symplify |
5
|
|
|
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz). |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Symplify\MultiCodingStandard\PhpCsFixer\Application; |
9
|
|
|
|
10
|
|
|
use Symfony\CS\Config; |
11
|
|
|
use Symfony\CS\Fixer; |
12
|
|
|
use Symplify\MultiCodingStandard\PhpCsFixer\Application\Command\RunApplicationCommand; |
13
|
|
|
use Symplify\MultiCodingStandard\PhpCsFixer\Factory\FixerSetFactory; |
14
|
|
|
use Symplify\PHP7_CodeSniffer\File\Finder\SourceFinder; |
15
|
|
|
|
16
|
|
|
final class Application |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var Fixer |
20
|
|
|
*/ |
21
|
|
|
private $fixer; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var FixerSetFactory |
25
|
|
|
*/ |
26
|
|
|
private $fixerSetFactory; |
27
|
|
|
/** |
28
|
|
|
* @var SourceFinder |
29
|
|
|
*/ |
30
|
|
|
private $sourceFinder; |
31
|
|
|
|
32
|
|
|
public function __construct(Fixer $fixer, FixerSetFactory $fixerSetFactory, SourceFinder $sourceFinder) |
33
|
|
|
{ |
34
|
|
|
$this->fixer = $fixer; |
35
|
|
|
$this->fixerSetFactory = $fixerSetFactory; |
36
|
|
|
$this->sourceFinder = $sourceFinder; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function runCommand(RunApplicationCommand $command) |
40
|
|
|
{ |
41
|
|
|
$this->registerFixersToFixer($command->getFixerLevels(), $command->getFixers(), $command->getExcludeFixers()); |
42
|
|
|
|
43
|
|
|
$this->runForSource($command->getSource(), $command->isFixer()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
private function registerFixersToFixer(array $fixerLevels, array $fixers, array $excludedFixers) |
47
|
|
|
{ |
48
|
|
|
$fixers = $this->fixerSetFactory->createFromLevelsFixersAndExcludedFixers($fixerLevels, $fixers, $excludedFixers); |
49
|
|
|
$this->fixer->registerCustomFixers($fixers); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
private function runForSource(array $source, bool $isFixer) |
53
|
|
|
{ |
54
|
|
|
// $files = $this->sourceFinder->find($source); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$config = new Config(); |
57
|
|
|
$config->finder(new \ArrayIterator($source)); |
58
|
|
|
$configs = $this->fixer->addConfig($config); |
|
|
|
|
59
|
|
|
|
60
|
|
|
foreach ($files as $splFileInfo) { |
|
|
|
|
61
|
|
|
$this->fixer->fixFile($splFileInfo, $this->fixer->getFixers(), !$isFixer); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.