MigrationCreateCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * This file is part of the SVN-Buddy library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/svn-buddy
9
 */
10
11
namespace ConsoleHelpers\SVNBuddy\Command\Dev;
12
13
14
use ConsoleHelpers\DatabaseMigration\MigrationManager;
15
use ConsoleHelpers\SVNBuddy\Command\AbstractCommand;
16
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
class MigrationCreateCommand extends AbstractCommand
23
{
24
25
	/**
26
	 * Migration manager.
27
	 *
28
	 * @var MigrationManager
29
	 */
30
	private $_migrationManager;
31
32
	/**
33
	 * {@inheritdoc}
34
	 */
35
	protected function configure()
36
	{
37
		$this
38
			->setName('dev:migration-create')
39
			->setDescription(
40
				'Creates new database migration'
41
			)
42
			->addArgument(
43
				'name',
44
				InputArgument::REQUIRED,
45
				'Migration name'
46
			)
47
			->addOption(
48
				'extension',
49
				'e',
50
				InputOption::VALUE_REQUIRED,
51
				'Migration file extension',
52
				'sql'
53
			);
54
55
		parent::configure();
56
	}
57
58
	/**
59
	 * Prepare dependencies.
60
	 *
61
	 * @return void
62
	 */
63
	protected function prepareDependencies()
64
	{
65
		parent::prepareDependencies();
66
67
		$container = $this->getContainer();
68
69
		$this->_migrationManager = $container['migration_manager'];
70
	}
71
72
	/**
73
	 * Return possible values for the named option
74
	 *
75
	 * @param string            $optionName Option name.
76
	 * @param CompletionContext $context    Completion context.
77
	 *
78
	 * @return array
79
	 */
80
	public function completeOptionValues($optionName, CompletionContext $context)
81
	{
82
		$ret = parent::completeOptionValues($optionName, $context);
83
84
		if ( $optionName === 'extension' ) {
85
			return $this->_migrationManager->getMigrationFileExtensions();
86
		}
87
88
		return $ret;
89
	}
90
91
	/**
92
	 * {@inheritdoc}
93
	 */
94
	protected function execute(InputInterface $input, OutputInterface $output)
95
	{
96
		$migration_name = $this->_migrationManager->createMigration(
97
			$this->io->getArgument('name'),
0 ignored issues
show
Bug introduced by
It seems like $this->io->getArgument('name') can also be of type string[]; however, parameter $name of ConsoleHelpers\DatabaseM...ager::createMigration() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

97
			/** @scrutinizer ignore-type */ $this->io->getArgument('name'),
Loading history...
98
			$this->io->getOption('extension')
0 ignored issues
show
Bug introduced by
It seems like $this->io->getOption('extension') can also be of type string[]; however, parameter $file_extension of ConsoleHelpers\DatabaseM...ager::createMigration() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

98
			/** @scrutinizer ignore-type */ $this->io->getOption('extension')
Loading history...
99
		);
100
101
		$this->io->writeln('Migration <info>' . $migration_name . '</info> created.');
102
	}
103
104
}
105