Completed
Push — master ( 1c87cd...c75e6a )
by Alejandro
03:14
created

DumpTypeClassesCommand::execute()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 5
nop 2
crap 3
1
<?php
2
namespace Acelaya\Doctrine\Console;
3
4
use Acelaya\Doctrine\Exception\InvalidArgumentException;
5
use Acelaya\Doctrine\Registrator\EnumTypeRegistratorInterface;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class DumpTypeClassesCommand extends Command
11
{
12
    /**
13
     * @var EnumTypeRegistratorInterface
14
     */
15
    private $registrator;
16
    /**
17
     * @var array
18
     */
19
    private $enums;
20
21 4
    public function __construct(EnumTypeRegistratorInterface $registrator, array $enums)
22
    {
23 4
        parent::__construct();
24 4
        $this->registrator = $registrator;
25 4
        $this->enums = $enums;
26 4
    }
27
28 4
    protected function configure()
29
    {
30 4
        $this
31 4
            ->setName('det:dump-type-files')
32 4
            ->setDescription('Generates the doctrine type class files for every configured enum');
33 4
    }
34
35 3
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37 3
        $output->write('Generating enum doctrine type files...');
38
        try {
39 3
            $this->registrator->registerEnumTypes($this->enums);
40 1
            $output->writeln(' <info>Success!</info>');
41 3
        } catch (InvalidArgumentException $e) {
42 2
            $output->writeln(' <error>Error!</error>');
43 2
            if ($output->isVerbose()) {
44 1
                $this->getApplication()->renderException($e, $output);
45 1
            }
46
        }
47 3
    }
48
}
49