|
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
|
|
|
|
|
8
|
|
|
namespace PhUml\Console\Commands; |
|
9
|
|
|
|
|
10
|
|
|
use PhUml\Generators\StatisticsGenerator; |
|
11
|
|
|
use PhUml\Parser\CodebaseDirectory; |
|
12
|
|
|
use PhUml\Parser\CodeFinder; |
|
13
|
|
|
use PhUml\Parser\CodeParser; |
|
14
|
|
|
use PhUml\Parser\NonRecursiveCodeFinder; |
|
15
|
|
|
use PhUml\Processors\StatisticsProcessor; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
|
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
|
|
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
|
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* This command will generate a text file with the statistics of an OO codebase |
|
23
|
|
|
* |
|
24
|
|
|
* This command has 2 required arguments |
|
25
|
|
|
* |
|
26
|
|
|
* 1. `directory`. The path where your codebase lives |
|
27
|
|
|
* 2. `output`. The path to where the generated `png` image will be saved |
|
28
|
|
|
* |
|
29
|
|
|
* There is 1 options |
|
30
|
|
|
* |
|
31
|
|
|
* 1. `recursive`. If present it will look recursively within the `directory` provided |
|
32
|
|
|
*/ |
|
33
|
|
|
class GenerateStatisticsCommand extends GeneratorCommand |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
|
37
|
|
|
*/ |
|
38
|
72 |
|
protected function configure(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this |
|
41
|
72 |
|
->setName('phuml:statistics') |
|
42
|
72 |
|
->setDescription('Generate statistics about the code of a given directory') |
|
43
|
72 |
|
->setHelp( |
|
44
|
|
|
<<<HELP |
|
45
|
72 |
|
Example: |
|
46
|
|
|
php bin/phuml phuml:statistics -r ./src statistics.txt |
|
47
|
|
|
|
|
48
|
|
|
This example will scan the `./src` directory recursively for php files. |
|
49
|
|
|
It will generate the statistics and save them to the file `statistics.txt`. |
|
50
|
|
|
HELP |
|
51
|
|
|
) |
|
52
|
72 |
|
->addOption( |
|
53
|
72 |
|
'recursive', |
|
54
|
72 |
|
'r', |
|
55
|
72 |
|
InputOption::VALUE_NONE, |
|
56
|
72 |
|
'Look for classes in the given directory recursively' |
|
57
|
|
|
) |
|
58
|
72 |
|
->addArgument( |
|
59
|
72 |
|
'directory', |
|
60
|
72 |
|
InputArgument::REQUIRED, |
|
61
|
72 |
|
'The directory to be scanned to generate the statistics' |
|
62
|
|
|
) |
|
63
|
72 |
|
->addArgument( |
|
64
|
72 |
|
'output', |
|
65
|
72 |
|
InputArgument::REQUIRED, |
|
66
|
72 |
|
'The file name for your statistics file' |
|
67
|
|
|
) |
|
68
|
|
|
; |
|
69
|
72 |
|
} |
|
70
|
|
|
|
|
71
|
6 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
72
|
|
|
{ |
|
73
|
6 |
|
$statisticsInput = new StatisticsInput($input->getArguments(), $input->getOptions()); |
|
74
|
6 |
|
$codebasePath = $statisticsInput->directory(); |
|
75
|
6 |
|
$statisticsFilePath = $statisticsInput->outputFile(); |
|
76
|
|
|
$recursive = $statisticsInput->recursive(); |
|
77
|
6 |
|
|
|
78
|
6 |
|
$statisticsGenerator = new StatisticsGenerator(new CodeParser(), new StatisticsProcessor()); |
|
79
|
|
|
$statisticsGenerator->attach($this->display); |
|
80
|
6 |
|
|
|
81
|
6 |
|
$codeFinder = $recursive ? new CodeFinder() : new NonRecursiveCodeFinder(); |
|
82
|
|
|
$codeFinder->addDirectory(CodebaseDirectory::from($codebasePath)); |
|
83
|
3 |
|
|
|
84
|
|
|
$statisticsGenerator->generate($codeFinder, $statisticsFilePath); |
|
85
|
3 |
|
|
|
86
|
|
|
return self::SUCCESS; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths