|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SavinMikhail\CommentsDensity\Commands; |
|
6
|
|
|
|
|
7
|
|
|
use Generator; |
|
8
|
|
|
use RecursiveDirectoryIterator; |
|
9
|
|
|
use RecursiveIteratorIterator; |
|
10
|
|
|
use SavinMikhail\CommentsDensity\AnalyzerFactory; |
|
|
|
|
|
|
11
|
|
|
use SavinMikhail\CommentsDensity\Reporters\ReporterFactory; |
|
|
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
class AnalyzeCommentCommand extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
protected function configure(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->setName('analyze:comments') |
|
20
|
|
|
->setDescription('Analyzes the comment density in files within a directory.') |
|
21
|
|
|
->setHelp('This command allows you to analyze the comments in PHP files within a specified directory.'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
28
|
|
|
{ |
|
29
|
|
|
$configDto = $this->getConfigDto(); |
|
30
|
|
|
|
|
31
|
|
|
$files = $this->getFilesFromDirectories($configDto->directories); |
|
32
|
|
|
$reporter = (new ReporterFactory())->createReporter($output, $configDto); |
|
33
|
|
|
$analyzerFactory = new AnalyzerFactory(); |
|
34
|
|
|
|
|
35
|
|
|
$analyzer = $this->getAnalyzer($analyzerFactory, $configDto, $output, $reporter); |
|
36
|
|
|
|
|
37
|
|
|
return $this->analyze($analyzer, $files, $output); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function getFilesFromDirectories(array $directories): Generator |
|
41
|
|
|
{ |
|
42
|
|
|
foreach ($directories as $directory) { |
|
43
|
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); |
|
44
|
|
|
foreach ($iterator as $file) { |
|
45
|
|
|
yield $file; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
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