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

AbstractDbCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 31
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 23 3
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