Failed Conditions
Push — master ( 04109e...74e566 )
by Jonathan
34s queued 10s
created

MigrationsDiffDoctrineCommand::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 2
dl 0
loc 8
ccs 0
cts 6
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Bundle\MigrationsBundle\Command;
6
7
use Doctrine\Migrations\Tools\Console\Command\DiffCommand;
8
use InvalidArgumentException;
9
use Symfony\Bundle\FrameworkBundle\Console\Application;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
/**
15
 * Command for generate migration classes by comparing your current database schema
16
 * to your mapping information.
17
 */
18
class MigrationsDiffDoctrineCommand extends DiffCommand
19
{
20
    protected function configure() : void
21
    {
22
        parent::configure();
23
24
        $this
25
            ->setName('doctrine:migrations:diff')
26
            ->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
27
            ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
28
            ->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
29
        ;
30
    }
31
32
    public function initialize(InputInterface $input, OutputInterface $output) : void
33
    {
34
        /** @var Application $application */
35
        $application = $this->getApplication();
36
37
        Helper\DoctrineCommandHelper::setApplicationHelper($application, $input);
38
39
        $configuration = $this->getMigrationConfiguration($input, $output);
40
        DoctrineCommand::configureMigrations($application->getKernel()->getContainer(), $configuration);
41
42
        parent::initialize($input, $output);
43
    }
44
45
    public function execute(InputInterface $input, OutputInterface $output) : ?int
46
    {
47
        // EM and DB options cannot be set at same time
48
        if ($input->getOption('em') !== null && $input->getOption('db') !== null) {
49
            throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
50
        }
51
52
        return parent::execute($input, $output);
53
    }
54
}
55