Passed
Push — main ( 28fe2f...804823 )
by mikhail
03:26
created

AnalyzeCommentCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 3
b 0
f 0
nc 1
nop 2
dl 0
loc 11
ccs 0
cts 7
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\Commands;
6
7
use Generator;
8
use RecursiveDirectoryIterator;
9
use RecursiveIteratorIterator;
10
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...
11
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...
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class AnalyzeCommentCommand extends Command
16
{
17
    protected function configure(): void
18
    {
19
        $this->setName('analyze:comments')
20
            ->setDescription('Analyzes the comment density in files within a directory.')
21
            ->setHelp('This command allows you to analyze the comments in PHP files within a specified directory.');
22
    }
23
24
    /**
25
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
26
     */
27
    protected function execute(InputInterface $input, OutputInterface $output): int
28
    {
29
        $configDto = $this->getConfigDto();
30
31
        $files = $this->getFilesFromDirectories($configDto->directories);
32
        $reporter = (new ReporterFactory())->createReporter($output, $configDto);
33
        $analyzerFactory = new AnalyzerFactory();
34
35
        $analyzer = $this->getAnalyzer($analyzerFactory, $configDto, $output, $reporter);
36
37
        return $this->analyze($analyzer, $files, $output);
38
    }
39
40
    protected function getFilesFromDirectories(array $directories): Generator
41
    {
42
        foreach ($directories as $directory) {
43
            $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
44
            foreach ($iterator as $file) {
45
                yield $file;
46
            }
47
        }
48
    }
49
}
50