Test Failed
Push — main ( 823f4e...dcdb43 )
by mikhail
03:06
created

Command::getProjectRoot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\Commands;
6
7
use RecursiveDirectoryIterator;
8
use RecursiveIteratorIterator;
9
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...
10
use SavinMikhail\CommentsDensity\CommentDensity;
11
use SavinMikhail\CommentsDensity\ConfigLoader;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDensity\ConfigLoader 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\DTO\Input\ConfigDTO;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDensity\DTO\Input\ConfigDTO 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...
13
use SavinMikhail\CommentsDensity\Reporters\ReporterInterface;
14
use Symfony\Component\Console\Command\Command as SymfonyCommand;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
abstract class Command extends SymfonyCommand
18
{
19
    protected function getConfigDto(): ConfigDTO
20
    {
21
        $configLoader = new ConfigLoader();
22
        return $configLoader->getConfigDto();
23
    }
24
25
    protected function getFilesFromDirectories(array $directories): array
26
    {
27
        $files = [];
28
        foreach ($directories as $directory) {
29
            $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
30
            foreach ($iterator as $file) {
31
                $files[] = $file;
32
            }
33
        }
34
        return $files;
35
    }
36
37
    protected function analyze(CommentDensity $analyzer, array $files, OutputInterface $output): int
38
    {
39
        $limitExceeded = $analyzer->analyzeFiles($files);
40
41
        if ($limitExceeded) {
42
            $output->writeln('<error>Comment thresholds were exceeded!</error>');
43
            return SymfonyCommand::FAILURE;
44
        }
45
        $output->writeln('<info>Comment thresholds are passed!</info>');
46
        return SymfonyCommand::SUCCESS;
47
    }
48
49
    protected function getAnalyzer(
50
        AnalyzerFactory $factory,
51
        ConfigDTO $configDto,
52
        OutputInterface $output,
53
        ReporterInterface $reporter
54
    ): CommentDensity {
55
        return $factory->getAnalyzer($configDto, $output, $reporter);
56
    }
57
}
58