Passed
Push — main ( b8dd52...35d689 )
by mikhail
03:26
created

AnalyzeCommentCommand::getFilesFromDirectories()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 4
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\Commands;
6
7
use SavinMikhail\CommentsDensity\AnalyzerFactory;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDensity\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\Reporters\ReporterFactory;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDen...porters\ReporterFactory 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...
9
use Symfony\Component\Console\Command\Command as SymfonyCommand;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class AnalyzeCommentCommand extends Command
14
{
15
    protected function configure(): void
16
    {
17
        $this->setName('analyze:comments')
18
            ->setDescription('Analyzes the comment density in files within a directory.')
19
            ->setHelp('This command allows you to analyze the comments in PHP files within a specified directory.');
20
    }
21
22
    /**
23
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
24
     */
25
    protected function execute(InputInterface $input, OutputInterface $output): int
26
    {
27
        $configDto = $this->getConfigDto();
28
29
        $files = $this->getFilesFromDirectories($configDto->directories);
30
        $reporter = (new ReporterFactory())->createReporter($output, $configDto);
31
        $analyzerFactory = new AnalyzerFactory();
32
33
        $analyzer = $analyzerFactory->getAnalyzer($configDto, $output);
34
35
        $outputDTO = $analyzer->analyze($files);
36
37
        $reporter->report($outputDTO);
38
39
        if ($outputDTO->exceedThreshold) {
40
            $output->writeln('<error>Comment thresholds were exceeded!</error>');
41
            return SymfonyCommand::FAILURE;
42
        }
43
        $output->writeln('<info>Comment thresholds are passed!</info>');
44
        return SymfonyCommand::SUCCESS;
45
    }
46
}
47