Issues (52)

AnalyzeComments/Commands/AnalyzeCommentCommand.php (4 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Commands;
6
7
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\AnalyzerFactory;
0 ignored issues
show
The type SavinMikhail\CommentsDen...nalyzer\AnalyzerFactory was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\ConfigLoader;
9
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\HtmlOutputDTO;
0 ignored issues
show
The type SavinMikhail\CommentsDen...onfig\DTO\HtmlOutputDTO was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use SavinMikhail\CommentsDensity\AnalyzeComments\Formatter\ConsoleFormatter;
0 ignored issues
show
The type SavinMikhail\CommentsDen...matter\ConsoleFormatter was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use SavinMikhail\CommentsDensity\AnalyzeComments\Formatter\HtmlFormatter;
0 ignored issues
show
The type SavinMikhail\CommentsDen...Formatter\HtmlFormatter was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use SavinMikhail\CommentsDensity\Baseline\Storage\TreePhpBaselineStorage;
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 AnalyzeCommentCommand 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
        parent::__construct($name);
26
    }
27
28
    protected function configure(): void
29
    {
30
        $this->setName('analyze')
31
            ->setDescription('Analyzes the comment density in files within a directory.')
32
            ->setHelp('This command allows you to analyze the comments in PHP files within a specified directory.');
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
43
        $formatters = ['console' => new ConsoleFormatter($output)];
44
        if ($configDto->output instanceof HtmlOutputDTO) {
45
            $formatters['html'] = new HtmlFormatter($configDto->output->file);
46
        }
47
        $formatter = $formatters[$configDto->output->type] ?? $formatters['console'];
48
49
        $analyzer = $this->analyzerFactory->getAnalyzer($configDto, $this->storage);
50
51
        $report = $analyzer->analyze();
52
53
        $formatter->report($report);
54
55
        if ($report->exceedThreshold) {
56
            $output->writeln('<error>Comment thresholds were exceeded!</error>');
57
58
            return Command::FAILURE;
59
        }
60
        $output->writeln('<info>Comment thresholds are passed!</info>');
61
62
        return Command::SUCCESS;
63
    }
64
}
65