Failed Conditions
Push — master ( 34c0d8...598f4b )
by Alexander
03:28
created

MigrationCreateCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 83
ccs 0
cts 34
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 22 1
A prepareDependencies() 0 8 1
A completeOptionValues() 0 10 2
A execute() 0 9 1
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;
12
13
14
use ConsoleHelpers\SVNBuddy\Database\Migration\MigrationManager;
15
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
class MigrationCreateCommand extends AbstractCommand implements IAggregatorAwareCommand
22
{
23
24
	/**
25
	 * Migration manager.
26
	 *
27
	 * @var MigrationManager
28
	 */
29
	private $_migrationManager;
30
31
	/**
32
	 * {@inheritdoc}
1 ignored issue
show
introduced by
Doc comment short description must start with a capital letter
Loading history...
33
	 */
1 ignored issue
show
introduced by
Missing @return tag in function comment
Loading history...
34
	protected function configure()
35
	{
36
		$this
37
			->setName('migration:create')
38
			->setDescription(
39
				'Creates new database migration'
40
			)
41
			->addArgument(
42
				'name',
43
				InputArgument::REQUIRED,
44
				'Migration name'
45
			)
46
			->addOption(
47
				'extension',
48
				'e',
49
				InputOption::VALUE_REQUIRED,
50
				'Migration file extension',
51
				'sql'
52
			);
53
54
		parent::configure();
55
	}
56
57
	/**
58
	 * Prepare dependencies.
59
	 *
60
	 * @return void
61
	 */
62
	protected function prepareDependencies()
63
	{
64
		parent::prepareDependencies();
65
66
		$container = $this->getContainer();
67
68
		$this->_migrationManager = $container['migration_manager'];
69
	}
70
71
	/**
72
	 * Return possible values for the named option
73
	 *
74
	 * @param string            $optionName Option name.
75
	 * @param CompletionContext $context    Completion context.
76
	 *
77
	 * @return array
78
	 */
79
	public function completeOptionValues($optionName, CompletionContext $context)
80
	{
81
		$ret = parent::completeOptionValues($optionName, $context);
82
83
		if ( $optionName === 'extension' ) {
84
			return $this->_migrationManager->getMigrationFileExtensions();
85
		}
86
87
		return $ret;
88
	}
89
90
	/**
2 ignored issues
show
introduced by
Doc comment for parameter "$input" missing
Loading history...
introduced by
Doc comment for parameter "$output" missing
Loading history...
91
	 * {@inheritdoc}
1 ignored issue
show
introduced by
Doc comment short description must start with a capital letter
Loading history...
92
	 */
1 ignored issue
show
introduced by
Missing @return tag in function comment
Loading history...
93
	protected function execute(InputInterface $input, OutputInterface $output)
94
	{
95
		$migration_name = $this->_migrationManager->createMigration(
96
			$this->io->getArgument('name'),
97
			$this->io->getOption('extension')
98
		);
99
100
		$this->io->writeln('Migration <info>' . $migration_name . '</info> created.');
101
	}
102
103
}
104