Migration::configure()   A
last analyzed

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 __construct()
23
    {
24
        parent::__construct([
25
            'seed_path' => app()->getPath().'/database/seed',
26
            'data_set_path' => app()->getPath().'/database/dataset',
27
        ]);
28
    }
29
30
    public function configure()
31
    {
32
        parent::configure();
33
        $this->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Database default connection', 'default');
34
    }
35
36
    public function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $config = config()->get('database', []);
39
        $connection = $input->getOption('connection');
40
        if (!isset($config[$connection])) {
41
            throw new \RuntimeException(sprintf('Cannot found database "%s" config', $connection));
42
        }
43
44
        $this->config = $config[$connection];
45
        $this->config['dbname'] = $this->config['name'];
46
47
        $this->createConnection();
48
49
        return parent::execute($input, $output);
50
    }
51
}
52