Failed Conditions
Pull Request — master (#228)
by Jonathan
02:55
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 Symfony\Bundle\FrameworkBundle\Console\Application;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Command for generate migration classes by comparing your current database schema
15
 * to your mapping information.
16
 */
17
class MigrationsDiffDoctrineCommand extends DiffCommand
18
{
19
    protected function configure() : void
20
    {
21
        parent::configure();
22
23
        $this
24
            ->setName('doctrine:migrations:diff')
25
            ->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
26
            ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
27
            ->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
28
        ;
29
    }
30
31
    public function initialize(InputInterface $input, OutputInterface $output) : void
32
    {
33
        /** @var Application $application */
34
        $application = $this->getApplication();
35
36
        Helper\DoctrineCommandHelper::setApplicationHelper($application, $input);
37
38
        $configuration = $this->getMigrationConfiguration($input, $output);
39
        DoctrineCommand::configureMigrations($application->getKernel()->getContainer(), $configuration);
40
41
        parent::initialize($input, $output);
42
    }
43
44
    public function execute(InputInterface $input, OutputInterface $output) : ?int
45
    {
46
        // EM and DB options cannot be set at same time
47
        if ($input->getOption('em') !== null && $input->getOption('db') !== null) {
48
            throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
0 ignored issues
show
Bug introduced by
The type Doctrine\Bundle\Migratio...nvalidArgumentException was not found. Did you mean InvalidArgumentException? If so, make sure to prefix the type with \.
Loading history...
49
        }
50
51
        return parent::execute($input, $output);
52
    }
53
}
54