Passed
Pull Request — master (#33)
by Anton
03:09
created

AbstractDbCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 6
dl 0
loc 33
ccs 0
cts 16
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 25 4
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
        if ($command->getDefinition()->hasOption('environment')) {
47
            $phinxArguments['--environment'] = 'default';
48
        }
49
50
        $phinxInput = new ArrayInput($phinxArguments);
51
        $command->run($phinxInput, $output);
52
    }
53
}
54