Migration   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
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 __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