Command::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace AppBundle\ShowUnusedComposerPackages;
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 ShowUnusedComposerPackages task.
14
 */
15
final class Command extends BaseCommand
16
{
17
    const ARGUMENT_COMPOSER_JSON = 'composerJson';
18
    const OPTION_VENDOR_DIRECTORY = 'vendorDir';
19
    const ARGUMENT_USED_FILES = 'usedFiles';
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-composer-packages')
42
             ->setDescription('Show a list of potentially unused composer packages.')
43
             ->addArgument(self::ARGUMENT_COMPOSER_JSON, InputArgument::REQUIRED, 'Path to the project\'s composer.json.')
44
             ->addOption(self::OPTION_VENDOR_DIRECTORY, 'l', InputOption::VALUE_REQUIRED, 'Path to the project\'s vendor directory.')
45
             ->addArgument(self::ARGUMENT_USED_FILES, InputArgument::REQUIRED, 'Path to the list of used files.')
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->getUnusedPackagePaths(
55
            $input->getArgument(self::ARGUMENT_COMPOSER_JSON),
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument(self::ARGUMENT_COMPOSER_JSON) can also be of type string[]; however, parameter $pathToComposerJson of AppBundle\ShowUnusedComp...getUnusedPackagePaths() 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

55
            /** @scrutinizer ignore-type */ $input->getArgument(self::ARGUMENT_COMPOSER_JSON),
Loading history...
56
            $input->getOption(self::OPTION_VENDOR_DIRECTORY),
0 ignored issues
show
Bug introduced by
It seems like $input->getOption(self::OPTION_VENDOR_DIRECTORY) can also be of type string[]; however, parameter $pathToVendor of AppBundle\ShowUnusedComp...getUnusedPackagePaths() 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

56
            /** @scrutinizer ignore-type */ $input->getOption(self::OPTION_VENDOR_DIRECTORY),
Loading history...
57
            $input->getArgument(self::ARGUMENT_USED_FILES),
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument(self::ARGUMENT_USED_FILES) can also be of type string[]; however, parameter $pathToUsedFiles of AppBundle\ShowUnusedComp...getUnusedPackagePaths() 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_USED_FILES),
Loading history...
58
            $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\ShowUnusedComp...getUnusedPackagePaths() 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

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