Completed
Pull Request — master (#689)
by Jonathan
02:35
created

GenerateCommand::procOpen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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