AbstractDbCommand::execute()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 31
ccs 0
cts 17
cp 0
rs 9.7
c 1
b 0
f 0
cc 4
nc 6
nop 2
crap 20
1
<?php
2
3
/**
4
 * @copyright Bluz PHP Team
5
 * @link https://github.com/bluzphp/bluzman
6
 */
7
8
namespace Bluzman\Command\Db;
9
10
use Bluzman\Command\AbstractCommand;
11
use Exception;
12
use Phinx\Console\PhinxApplication;
0 ignored issues
show
Bug introduced by
The type Phinx\Console\PhinxApplication was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Symfony\Component\Console\Input\ArrayInput;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\ArrayInput was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
/**
18
 * AbstractDbCommand
19
 *
20
 * @package  Bluzman\Command\Db
21
 * @author   Anton Shevchuk
22
 */
23
abstract class AbstractDbCommand extends AbstractCommand
24
{
25
    /**
26
     * @param InputInterface $input
27
     * @param OutputInterface $output
28
     * @return int
29
     * @throws Exception
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $commandName = substr($this->getName(), 3);
34
        $arguments = $this->getDefinition()->getArguments();
35
36
        $phinx = new PhinxApplication();
37
        $command = $phinx->find($commandName);
38
39
        $phinxArguments = [];
40
41
        foreach ($arguments as $name => $argumentInput) {
42
            if ($input->getArgument($name)) {
43
                $phinxArguments[$name] = $input->getArgument($name);
44
            }
45
        }
46
47
        $phinxArguments['command'] = $commandName;
48
        $phinxArguments['--configuration'] = PATH_APPLICATION . DS . 'configs' . DS . 'phinx.php';
0 ignored issues
show
Bug introduced by
The constant Bluzman\Command\Db\PATH_APPLICATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant Bluzman\Command\Db\DS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
49
50
        // write database name to console
51
        // to avoid any mistakes
52
        $config = include $phinxArguments['--configuration'];
53
        $this->write('<info>host</info> ' . $config['environments']['default']['host']);
54
        $this->write('<info>name</info> ' . $config['environments']['default']['name']);
55
56
        if ($command->getDefinition()->hasOption('environment')) {
57
            $phinxArguments['--environment'] = 'default';
58
        }
59
60
        $phinxInput = new ArrayInput($phinxArguments);
61
        return $command->run($phinxInput, $output);
62
    }
63
}
64