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

Migration::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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