AnnotationLintCommand::getAliases()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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