Test Failed
Push — master ( a29797...6ce97f )
by huang
06:37
created

Migration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 15 2
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2017
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
10
namespace FastD\Console;
11
12
use FastD\Migration\Migrate;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * Class Migration.
19
 */
20
class Migration extends Migrate
21
{
22
    public function configure()
23
    {
24
        parent::configure();
25
        $this->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Database default connection', 'default');
26
    }
27
28
    public function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $config = config()->get('database', []);
31
        $connection = $input->getOption('connection');
32
        if (!isset($config[$connection])) {
33
            throw new \RuntimeException(sprintf('Cannot found database "%s" config', $connection));
34
        }
35
36
        $this->config = $config[$connection];
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean configFile?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
37
        $this->config['dbname'] = $this->config['name'];
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean configFile?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
38
39
        $this->createConnection();
40
41
        return parent::execute($input, $output);
42
    }
43
}
44