Completed
Push — master ( b2cc89...0bff0f )
by Tobias
42:03 queued 06:38
created

AnnotationLintCommand::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Happyr\AnnotationWarmer\Command;
6
7
use Happyr\AnnotationWarmer\Service\AnnotationValidator;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13
/**
14
 * @author Tobias Nyholm <[email protected]>
15
 */
16
final class AnnotationLintCommand extends Command
17
{
18
    protected static $defaultName = 'lint:annotations';
19
20
    private $validator;
21
    private $classes;
22
23
    public function __construct(AnnotationValidator $validator, array $classes)
24
    {
25
        parent::__construct();
26
        $this->validator = $validator;
27
        $this->classes = $classes;
28
    }
29
30
    public function getAliases()
31
    {
32
        return ['lint:annotation'];
33
    }
34
35
36
    protected function configure()
37
    {
38
        $this->setHelp('Lint all annotations in paths specified in happyr_annotation_warmer.paths');
39
    }
40
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        $style = new SymfonyStyle($input, $output);
44
        $errors = $this->validator->validateClasses($this->classes);
45
        if (empty($errors)) {
46
            $style->success('Everything is fine');
47
48
            return;
49
        }
50
51
        $style->error('Found some issues: ');
52
        foreach ($errors as $error) {
53
            $style->error($error);
54
        }
55
    }
56
}
57