Command   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 23
c 1
b 0
f 0
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 9 1
A configure() 0 9 1
1
<?php
2
3
namespace AppBundle\ShowUnusedPublicAssets;
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 ShowUnusedPublicAssets task.
14
 */
15
final class Command extends BaseCommand
16
{
17
    const ARGUMENT_PATH_TO_PUBLIC = 'pathToPublic';
18
    const ARGUMENT_PATH_TO_LOG_FILE = 'pathToLogFile';
19
    const OPTION_REG_EXP_TO_FIND_FILE = 'regExpToFindFile';
20
    const OPTION_PATH_TO_OUTPUT = 'pathToOutput';
21
    const OPTION_PATH_TO_BLACKLIST = 'pathToBlacklist';
22
23
    /**
24
     * @var Task
25
     */
26
    private $task;
27
28
    /**
29
     * @param Task $task
30
     */
31
    public function __construct(Task $task)
32
    {
33
        parent::__construct();
34
        $this->task = $task;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function configure()
41
    {
42
        $this->setName('show-unused-public-assets')
43
             ->setDescription('Show a list of potentially unused public assets.')
44
             ->addArgument(self::ARGUMENT_PATH_TO_PUBLIC, InputArgument::REQUIRED, 'Path to the public web root of your project.')
45
             ->addArgument(self::ARGUMENT_PATH_TO_LOG_FILE, InputArgument::REQUIRED, 'Path to the web server\'s access log file.')
46
             ->addOption(self::OPTION_REG_EXP_TO_FIND_FILE, 'r', InputOption::VALUE_REQUIRED, 'Regular expression for the log file capturing the path of the accessed file as it\'s first capture group.', '#"(?:get|post) ([a-z0-9\_\-\.\/]*)#i')
47
             ->addOption(self::OPTION_PATH_TO_OUTPUT, 'o', InputOption::VALUE_REQUIRED, 'Path to the output file. If not set, it will be "potentially-unused-public-assets.txt" in the folder above the public web root.')
48
             ->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#');
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $this->task->getUnusedPublicAssets(
57
            $input->getArgument(self::ARGUMENT_PATH_TO_PUBLIC),
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument(self...RGUMENT_PATH_TO_PUBLIC) can also be of type string[]; however, parameter $pathToPublic of AppBundle\ShowUnusedPubl...getUnusedPublicAssets() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
            /** @scrutinizer ignore-type */ $input->getArgument(self::ARGUMENT_PATH_TO_PUBLIC),
Loading history...
58
            $input->getArgument(self::ARGUMENT_PATH_TO_LOG_FILE),
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument(self...UMENT_PATH_TO_LOG_FILE) can also be of type string[]; however, parameter $pathToLogfile of AppBundle\ShowUnusedPubl...getUnusedPublicAssets() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

58
            /** @scrutinizer ignore-type */ $input->getArgument(self::ARGUMENT_PATH_TO_LOG_FILE),
Loading history...
59
            $input->getOption(self::OPTION_REG_EXP_TO_FIND_FILE),
0 ignored issues
show
Bug introduced by
It seems like $input->getOption(self::...N_REG_EXP_TO_FIND_FILE) can also be of type string[]; however, parameter $regExpToFindFile of AppBundle\ShowUnusedPubl...getUnusedPublicAssets() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
            /** @scrutinizer ignore-type */ $input->getOption(self::OPTION_REG_EXP_TO_FIND_FILE),
Loading history...
60
            $input->getOption(self::OPTION_PATH_TO_OUTPUT),
0 ignored issues
show
Bug introduced by
It seems like $input->getOption(self::OPTION_PATH_TO_OUTPUT) can also be of type string[]; however, parameter $pathToOutput of AppBundle\ShowUnusedPubl...getUnusedPublicAssets() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
            /** @scrutinizer ignore-type */ $input->getOption(self::OPTION_PATH_TO_OUTPUT),
Loading history...
61
            $input->getOption(self::OPTION_PATH_TO_BLACKLIST),
0 ignored issues
show
Bug introduced by
It seems like $input->getOption(self::OPTION_PATH_TO_BLACKLIST) can also be of type string[]; however, parameter $pathToBlacklist of AppBundle\ShowUnusedPubl...getUnusedPublicAssets() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
            /** @scrutinizer ignore-type */ $input->getOption(self::OPTION_PATH_TO_BLACKLIST),
Loading history...
62
            new SymfonyStyle($input, $output)
63
        );
64
    }
65
}
66