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