Completed
Push — master ( 926f1e...80db42 )
by Anton
10:25 queued 07:09
created

AbstractDbCommand::execute()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 15
nc 6
nop 2
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
47
        if ($command->getDefinition()->hasOption('environment')) {
48
            $phinxArguments['--environment'] = 'default';
49
        }
50
51
        $phinxInput = new ArrayInput($phinxArguments);
52
        $command->run($phinxInput, $output);
53
    }
54
}
55