Completed
Push — master ( 797142...deecf0 )
by Luis
06:15 queued 02:52
created

GenerateStatisticsCommand::runningProcessor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
namespace PhUml\Console\Commands;
8
9
use PhUml\Actions\GenerateStatistics;
10
use PhUml\Parser\CodeFinder;
11
use PhUml\Parser\TokenParser;
12
use PhUml\Processors\StatisticsProcessor;
13
use RuntimeException;
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class GenerateStatisticsCommand extends GeneratorCommand
20
{
21
    /**
22
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
23
     */
24 36
    protected function configure()
25
    {
26
        $this
27 36
            ->setName('phuml:statistics')
28 36
            ->setDescription('Generate statistics about the code of a given directory')
29 36
            ->setHelp(<<<HELP
30 36
Example:
31
    php bin/phuml phuml:statistics -r  ./src statistics.txt
32
33
    This example will scan the `./src` directory recursively for php files.
34
    It will generate the statistics and save them to the file `statistics.txt`.
35
HELP
36
            )
37 36
            ->addOption(
38 36
                'recursive',
39 36
                'r',
40 36
                InputOption::VALUE_NONE,
41 36
                'Look for classes in the given directory recursively'
42
            )
43 36
            ->addArgument(
44 36
                'directory',
45 36
                InputArgument::REQUIRED,
46 36
                'The directory to be scanned to generate the statistics'
47
            )
48 36
            ->addArgument(
49 36
                'output',
50 36
                InputArgument::REQUIRED,
51 36
                'The file name for your statistics file'
52
            )
53
        ;
54 36
    }
55
56
    /**
57
     * @throws \LogicException
58
     * @throws \RuntimeException
59
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
60
     */
61 6
    protected function execute(InputInterface $input, OutputInterface $output)
62
    {
63 6
        $directory = $input->getArgument('directory');
64 6
        $statisticsFile = $input->getArgument('output');
65 6
        $recursive = (bool)$input->getOption('recursive');
66
67 6
        if (!is_dir($directory)) {
68 3
            throw new RuntimeException("'$directory' is not a valid directory");
69
        }
70
71 3
        $action = new GenerateStatistics(new TokenParser(), new StatisticsProcessor());
72 3
        $action->attach($this->display);
73
74 3
        $finder = new CodeFinder();
75 3
        $finder->addDirectory($directory, $recursive);
76
77 3
        $output->writeln('[|] Running... (This may take some time)');
78
79 3
        $action->generate($finder, $statisticsFile);
80
81 3
        return 0;
82
    }
83
}
84