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

MigrationsDumpSchemaDoctrineCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 2
rs 9.6666
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\DumpSchemaCommand;
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 dumping your current database schema to a migration.
16
 */
17
class MigrationsDumpSchemaDoctrineCommand extends DumpSchemaCommand
18
{
19
    protected function configure() : void
20
    {
21
        parent::configure();
22
23
        $this
24
            ->setName('doctrine:migrations:dump-schema')
25
            ->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
26
            ->addOption('em', null, InputOption::VALUE_REQUIRED, '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.');
49
        }
50
51
        return parent::execute($input, $output);
52
    }
53
}
54