|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SavinMikhail\CommentsDensity\Commands; |
|
6
|
|
|
|
|
7
|
|
|
use Generator; |
|
8
|
|
|
use SavinMikhail\CommentsDensity\Analyzer\AnalyzerFactory; |
|
|
|
|
|
|
9
|
|
|
use SavinMikhail\CommentsDensity\Baseline\Storage\TreePhpBaselineStorage; |
|
10
|
|
|
use SavinMikhail\CommentsDensity\Reporters\ConsoleReporter; |
|
|
|
|
|
|
11
|
|
|
use SplFileInfo; |
|
12
|
|
|
use Symfony\Component\Console\Command\Command as SymfonyCommand; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
16
|
|
|
|
|
17
|
|
|
class AnalyzeFilesCommand extends Command |
|
18
|
|
|
{ |
|
19
|
2 |
|
protected function configure(): void |
|
20
|
|
|
{ |
|
21
|
2 |
|
$this->setName('analyze:files') |
|
22
|
2 |
|
->setDescription('Analyzes the comment density in multiple PHP files.') |
|
23
|
2 |
|
->addArgument('files', InputArgument::IS_ARRAY, 'The PHP files to analyze') |
|
24
|
2 |
|
->setHelp('This command allows you to analyze the comments in multiple PHP files.'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
28
|
|
|
{ |
|
29
|
2 |
|
$path = __DIR__ . '/../../baseline.php'; |
|
30
|
|
|
|
|
31
|
2 |
|
$storage = new TreePhpBaselineStorage(); |
|
32
|
2 |
|
$storage->init($path); |
|
33
|
|
|
|
|
34
|
2 |
|
$configDto = $this->getConfigDto(); |
|
35
|
|
|
|
|
36
|
2 |
|
$filePaths = $input->getArgument('files'); |
|
37
|
|
|
|
|
38
|
2 |
|
$files = $this->generateFiles($filePaths); |
|
39
|
|
|
|
|
40
|
2 |
|
$analyzerFactory = new AnalyzerFactory(); |
|
41
|
2 |
|
$analyzer = $analyzerFactory->getAnalyzer($configDto, $output, $storage); |
|
42
|
2 |
|
$outputDTO = $analyzer->analyze($files); |
|
43
|
|
|
|
|
44
|
2 |
|
$reporter = new ConsoleReporter($output); |
|
45
|
2 |
|
$reporter->report($outputDTO); |
|
46
|
|
|
|
|
47
|
2 |
|
if ($outputDTO->exceedThreshold) { |
|
48
|
1 |
|
$output->writeln('<error>Comment thresholds were exceeded!</error>'); |
|
49
|
1 |
|
return SymfonyCommand::FAILURE; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
$output->writeln('<info>Comment thresholds are passed!</info>'); |
|
53
|
1 |
|
return SymfonyCommand::SUCCESS; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string[] $filePaths |
|
58
|
|
|
* @return Generator |
|
59
|
|
|
*/ |
|
60
|
2 |
|
protected function generateFiles(array $filePaths): Generator |
|
61
|
|
|
{ |
|
62
|
2 |
|
foreach ($filePaths as $filePath) { |
|
63
|
2 |
|
yield new SplFileInfo($filePath); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
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