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

BaselineCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 23
ccs 0
cts 15
cp 0
rs 9.7998
cc 2
nc 2
nop 2
crap 6
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\BaselineManager;
9
use SavinMikhail\CommentsDensity\Database\SQLiteDatabaseManager;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDen...e\SQLiteDatabaseManager 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\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...
11
use Symfony\Component\Console\Command\Command as SymfonyCommand;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use function file_exists;
15
use function touch;
16
17
final class BaselineCommand extends Command
18
{
19
    protected function configure(): void
20
    {
21
        $this->setName('generate:baseline')
22
            ->setDescription('Generate a baseline of comments to ignore them in the future')
23
            ->setHelp('This command allows you to ignore old tech debt and start this quality check from this point');
24
    }
25
26
27
    protected function execute(InputInterface $input, OutputInterface $output): int
28
    {
29
        $databaseFile = __DIR__ . '/../../comments_density.sqlite';
30
        if (! file_exists($databaseFile)) {
31
            touch($databaseFile);
32
        }
33
        $dbManager = new SQLiteDatabaseManager($databaseFile);
34
        $connection = $dbManager->getConnection();
35
        $baselineManager = new BaselineManager($connection);
36
37
        $configDto = $this->getConfigDto();
38
39
        $files = $this->getFilesFromDirectories($configDto->directories);
40
        $analyzerFactory = new AnalyzerFactory();
41
42
        $analyzer = $analyzerFactory->getAnalyzer($configDto, $output);
43
        $outputDTO = $analyzer->analyze($files);
44
45
        $baselineManager->set($outputDTO);
46
47
        $output->writeln('<info>Baseline generated successfully!</info>');
48
49
        return SymfonyCommand::SUCCESS;
50
    }
51
}