1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SavinMikhail\CommentsDensity\Commands; |
6
|
|
|
|
7
|
|
|
use SavinMikhail\CommentsDensity\Analyzer\AnalyzerFactory; |
|
|
|
|
8
|
|
|
use SavinMikhail\CommentsDensity\Baseline\Storage\TreePhpBaselineStorage; |
9
|
|
|
use SavinMikhail\CommentsDensity\Reporters\ReporterFactory; |
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Command\Command as SymfonyCommand; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
class AnalyzeCommentCommand extends Command |
16
|
|
|
{ |
17
|
2 |
|
protected function configure(): void |
18
|
|
|
{ |
19
|
2 |
|
$this->setName('analyze:comments') |
20
|
2 |
|
->setDescription('Analyzes the comment density in files within a directory.') |
21
|
2 |
|
->setHelp('This command allows you to analyze the comments in PHP files within a specified directory.'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @inheritDoc |
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 |
|
$files = $this->getFilesFromDirectories($configDto->directories); |
37
|
2 |
|
$reporter = (new ReporterFactory())->createReporter($output, $configDto); |
38
|
2 |
|
$analyzerFactory = new AnalyzerFactory(); |
39
|
|
|
|
40
|
2 |
|
$analyzer = $analyzerFactory->getAnalyzer($configDto, $output, $storage); |
41
|
|
|
|
42
|
2 |
|
$outputDTO = $analyzer->analyze($files); |
43
|
|
|
|
44
|
2 |
|
$reporter->report($outputDTO); |
45
|
|
|
|
46
|
2 |
|
if ($outputDTO->exceedThreshold) { |
47
|
1 |
|
$output->writeln('<error>Comment thresholds were exceeded!</error>'); |
48
|
1 |
|
return SymfonyCommand::FAILURE; |
49
|
|
|
} |
50
|
1 |
|
$output->writeln('<info>Comment thresholds are passed!</info>'); |
51
|
1 |
|
return SymfonyCommand::SUCCESS; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
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