Completed
Push — master ( 5ff3e1...46578f )
by Jonathan
12s
created

GenerateCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 24 1
B execute() 0 25 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tools\Console\Command;
6
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use function sprintf;
11
12
class GenerateCommand extends AbstractCommand
13
{
14 11
    protected function configure() : void
15
    {
16
        $this
17 11
            ->setName('migrations:generate')
18 11
            ->setAliases(['generate'])
19 11
            ->setDescription('Generate a blank migration class.')
20 11
            ->addOption(
21 11
                'editor-cmd',
22 11
                null,
23 11
                InputOption::VALUE_OPTIONAL,
24 11
                'Open file with this command upon creation.'
25
            )
26 11
            ->setHelp(<<<EOT
27 11
The <info>%command.name%</info> command generates a blank migration class:
28
29
    <info>%command.full_name%</info>
30
31
You can optionally specify a <comment>--editor-cmd</comment> option to open the generated file in your favorite editor:
32
33
    <info>%command.full_name% --editor-cmd=mate</info>
34
EOT
35
        );
36
37 11
        parent::configure();
38 11
    }
39
40 3
    public function execute(InputInterface $input, OutputInterface $output) : void
41
    {
42 3
        $versionNumber = $this->configuration->generateVersionNumber();
43
44 3
        $migrationGenerator = $this->dependencyFactory->getMigrationGenerator();
45
46 3
        $path = $migrationGenerator->generateMigration($versionNumber);
47
48 3
        $editorCommand = $input->getOption('editor-cmd');
49
50 3
        if ($editorCommand !== null) {
51 1
            $this->procOpen($editorCommand, $path);
52
        }
53
54 3
        $output->writeln([
55 3
            sprintf('Generated new migration class to "<info>%s</info>"', $path),
56 3
            '',
57 3
            sprintf(
58 3
                'To run just this migration for testing purposes, you can use <info>migrations:execute --up %s</info>',
59 3
                $versionNumber
60
            ),
61 3
            '',
62 3
            sprintf(
63 3
                'To revert the migration you can use <info>migrations:execute --down %s</info>',
64 3
                $versionNumber
65
            ),
66
        ]);
67 3
    }
68
}
69