Passed
Push — master ( 2f27bd...7f89e7 )
by Anton
01:49
created

AbstractDbCommand::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 15
cp 0
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 14
nc 3
nop 2
crap 12
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/bluzman
5
 */
6
7
namespace Bluzman\Command\Db;
8
9
use Bluzman\Command\AbstractCommand;
10
use Phinx\Console\PhinxApplication;
11
use Symfony\Component\Console\Input\ArrayInput;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
/**
16
 * AbstractDbCommand
17
 *
18
 * @package  Bluzman\Command\Db
19
 * @author   Anton Shevchuk
20
 */
21
abstract class AbstractDbCommand extends AbstractCommand
22
{
23
    /**
24
     * @param InputInterface $input
25
     * @param OutputInterface $output
26
     * @return int|null|void
27
     */
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $commandName = substr($this->getName(), 3);
31
        $arguments = $this->getDefinition()->getArguments();
32
33
        $phinx = new PhinxApplication();
34
        $command = $phinx->find($commandName);
35
36
        $phinxArguments = [];
37
38
        foreach ($arguments as $name => $argumentInput) {
39
            if ($input->getArgument($name)) {
40
                $phinxArguments[$name] = $input->getArgument($name);
41
            }
42
        }
43
44
        $phinxArguments['command'] = $commandName;
45
        $phinxArguments['--configuration'] = PATH_APPLICATION .DS. 'configs' .DS. 'phinx.php';
46
        $phinxArguments['--environment'] = 'default';
47
48
        $phinxInput = new ArrayInput($phinxArguments);
49
        $command->run($phinxInput, $output);
50
    }
51
}
52