1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SavinMikhail\CommentsDensity\Baseline\Commands; |
6
|
|
|
|
7
|
|
|
use RecursiveDirectoryIterator; |
8
|
|
|
use RecursiveIteratorIterator; |
9
|
|
|
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\AnalyzerFactory; |
|
|
|
|
10
|
|
|
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\ConfigLoader; |
|
|
|
|
11
|
|
|
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO; |
|
|
|
|
12
|
|
|
use SavinMikhail\CommentsDensity\AnalyzeComments\Exception\CommentsDensityException; |
13
|
|
|
use SavinMikhail\CommentsDensity\Baseline\Storage\TreePhpBaselineStorage; |
14
|
|
|
use SplFileInfo; |
15
|
|
|
use Symfony\Component\Console\Command\Command; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
final class BaselineCommand extends Command |
20
|
|
|
{ |
21
|
|
|
protected function configure(): void |
22
|
|
|
{ |
23
|
|
|
$this->setName('generate:baseline') |
24
|
|
|
->setDescription('Generate a baseline of comments to ignore them in the future') |
25
|
|
|
->setHelp('This command allows you to ignore old tech debt and start this quality check from this point'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
29
|
|
|
{ |
30
|
|
|
$configLoader = new ConfigLoader(); |
31
|
|
|
$path = $configLoader->getProjectRoot() . '/baseline.php'; |
32
|
|
|
|
33
|
|
|
$storage = new TreePhpBaselineStorage(); |
34
|
|
|
|
35
|
|
|
$storage->init($path); |
36
|
|
|
|
37
|
|
|
$configDto = $configLoader->getConfigDto(); |
38
|
|
|
$files = $this->getFilesFromDirectories($configDto->directories); |
39
|
|
|
|
40
|
|
|
$analyzerFactory = new AnalyzerFactory(); |
41
|
|
|
|
42
|
|
|
$analyzer = $analyzerFactory->getAnalyzer($configDto, $output, $storage); |
43
|
|
|
$outputDTO = $analyzer->analyze($files); |
44
|
|
|
|
45
|
|
|
$storage->setComments($outputDTO->comments); |
46
|
|
|
|
47
|
|
|
$output->writeln('<info>Baseline generated successfully!</info>'); |
48
|
|
|
|
49
|
|
|
return Command::SUCCESS; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string[] $directories |
54
|
|
|
* @return SplFileInfo[] |
55
|
|
|
*/ |
56
|
|
|
protected function getFilesFromDirectories(array $directories): iterable |
57
|
|
|
{ |
58
|
|
|
foreach ($directories as $directory) { |
59
|
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); |
60
|
|
|
foreach ($iterator as $file) { |
61
|
|
|
yield $file; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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