1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\ShowUnusedPhpFiles; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command as BaseCommand; |
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
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Symfony-Console-Command wrapper for the ShowUnusedPhpFiles task. |
14
|
|
|
*/ |
15
|
|
|
final class Command extends BaseCommand |
16
|
|
|
{ |
17
|
|
|
const ARGUMENT_USED_FILES = 'usedFiles'; |
18
|
|
|
const OPTION_PATH_TO_INSPECT = 'pathToInspect'; |
19
|
|
|
const OPTION_PATH_TO_OUTPUT = 'pathToOutput'; |
20
|
|
|
const OPTION_PATH_TO_BLACKLIST = 'pathToBlacklist'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Task |
24
|
|
|
*/ |
25
|
|
|
private $task; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Task $task |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Task $task) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
$this->task = $task; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
protected function configure() |
40
|
|
|
{ |
41
|
|
|
$this->setName('show-unused-php-files') |
42
|
|
|
->setDescription('Show a list of potentially unused PHP files.') |
43
|
|
|
->addArgument(self::ARGUMENT_USED_FILES, InputArgument::REQUIRED, 'Path to the list of used files.') |
44
|
|
|
->addOption(self::OPTION_PATH_TO_INSPECT, 'p', InputOption::VALUE_REQUIRED, 'Path to search for PHP files. If not set, it will be determined as the common parent path of the used files.') |
45
|
|
|
->addOption(self::OPTION_PATH_TO_OUTPUT, 'o', InputOption::VALUE_REQUIRED, 'Path to the output file. If not set, it will be "potentially-unused-files.txt" next to the file named in the usedFiles argument.') |
46
|
|
|
->addOption(self::OPTION_PATH_TO_BLACKLIST, 'b', InputOption::VALUE_REQUIRED, 'Path to a file containing a blacklist of regular expressions to exclude from the output. One regular expression per line, don\'t forget the delimiters. E.g.: ' . PHP_EOL . '#^/project/keepme.php#' . PHP_EOL . '#^/project/tmp/#' . PHP_EOL . '#.*Test.php#'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
53
|
|
|
{ |
54
|
|
|
$this->task->getUnusedPhpFiles( |
55
|
|
|
$input->getArgument(self::ARGUMENT_USED_FILES), |
56
|
|
|
$input->getOption(self::OPTION_PATH_TO_INSPECT), |
57
|
|
|
$input->getOption(self::OPTION_PATH_TO_OUTPUT), |
58
|
|
|
$input->getOption(self::OPTION_PATH_TO_BLACKLIST), |
59
|
|
|
new SymfonyStyle($input, $output) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|