Passed
Push — master ( 05c3b6...3a433f )
by Malte
02:38
created

Command::getPathToOutput()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 4
nc 2
nop 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 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $this->task->getUnusedPublicAssets(
57
            $input->getArgument(self::ARGUMENT_PATH_TO_PUBLIC),
58
            $input->getArgument(self::ARGUMENT_PATH_TO_LOG_FILE),
59
            $input->getOption(self::OPTION_REG_EXP_TO_FIND_FILE),
60
            $input->getOption(self::OPTION_PATH_TO_OUTPUT),
61
            $input->getOption(self::OPTION_PATH_TO_BLACKLIST),
62
            new SymfonyStyle($input, $output)
63
        );
64
    }
65
}
66