Passed
Push — master ( 676110...9cfebc )
by Daniel
02:12
created

ValidateCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 2
A __construct() 0 4 1
A configure() 0 6 1
1
<?php
2
3
namespace Dandelion\Console\Command;
4
5
use Dandelion\Configuration\ConfigurationValidatorInterface;
6
use Dandelion\Exception\ConfigurationNotValidException;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
use function sprintf;
12
13
class ValidateCommand extends Command
14
{
15
    public const NAME = 'validate';
16
    public const DESCRIPTION = 'Validates dandelion.json.';
17
    /**
18
     * @var \Dandelion\Configuration\ConfigurationValidatorInterface
19
     */
20
    protected $configurationValidator;
21
22
    public function __construct(ConfigurationValidatorInterface $configurationValidator)
23
    {
24
        parent::__construct();
25
        $this->configurationValidator = $configurationValidator;
26
    }
27
28
    /**
29
     * @return void
30
     */
31
    protected function configure(): void
32
    {
33
        parent::configure();
34
35
        $this->setName(static::NAME);
36
        $this->setDescription(static::DESCRIPTION);
37
    }
38
39
40
    /**
41
     * @param \Symfony\Component\Console\Input\InputInterface $input
42
     * @param \Symfony\Component\Console\Output\OutputInterface $output
43
     *
44
     * @return int
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output): int
47
    {
48
        try {
49
            $this->configurationValidator->validate();
50
        } catch (ConfigurationNotValidException $e) {
51
            $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
52
            return 1;
53
        }
54
55
        $output->writeln(sprintf('<info>%s</info>', 'Configuration is valid.'));
56
57
        return 0;
58
    }
59
}
60