AnnotationLintCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 43
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getAliases() 0 4 1
A configure() 0 4 1
A execute() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Happyr\AnnotationWarmer\Command;
6
7
use Doctrine\Common\Annotations\AnnotationException;
8
use Happyr\AnnotationWarmer\Service\AnnotationManager;
9
use Happyr\AnnotationWarmer\Service\AnnotationValidator;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Style\SymfonyStyle;
14
15
/**
16
 * @author Tobias Nyholm <[email protected]>
17
 */
18
final class AnnotationLintCommand extends Command
19
{
20
    protected static $defaultName = 'lint:annotations';
21
22
    private $validator;
23
    private $manager;
24
25
    public function __construct(AnnotationValidator $validator, AnnotationManager $manager)
26
    {
27
        parent::__construct();
28
        $this->validator = $validator;
29
        $this->manager = $manager;
30
    }
31
32
    public function getAliases()
33
    {
34
        return ['lint:annotation'];
35
    }
36
37
    protected function configure()
38
    {
39
        $this->setHelp('Lint all annotations in paths specified in happyr_annotation_warmer.paths');
40
    }
41
42
    protected function execute(InputInterface $input, OutputInterface $output)
43
    {
44
        $style = new SymfonyStyle($input, $output);
45
        /** @var AnnotationException[] $errors */
46
        $errors = $this->validator->validateClasses($this->manager->getAllClasses());
47
        if (empty($errors)) {
48
            $style->success('Everything is fine');
49
50
            return 0;
51
        }
52
53
        $style->error(sprintf('Found %d issues.', count($errors)));
54
        foreach ($errors as $error) {
55
            $style->error($error->getMessage());
56
        }
57
58
        return 1;
59
    }
60
}
61