Passed
Push — main ( fefea7...05b26b )
by mikhail
08:12
created

AnalyzeCommentCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 5
Bugs 1 Features 0
Metric Value
eloc 15
c 5
b 1
f 0
dl 0
loc 25
ccs 16
cts 16
cp 1
rs 9.7666
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\Commands;
6
7
use SavinMikhail\CommentsDensity\Analyzer\AnalyzerFactory;
0 ignored issues
show
Bug introduced by
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\Baseline\Storage\TreePhpBaselineStorage;
9
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...
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