MigrationsGeneratorCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 60
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B fire() 0 28 4
A getArguments() 0 6 1
A getOptions() 0 6 1
1
<?php namespace Nwidart\DbExporter\Commands;
2
3
use Nwidart\DbExporter\DbExporter;
4
use Nwidart\DbExporter\DbExportHandler;
5
use Symfony\Component\Console\Input\InputOption;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Config;
8
9
class MigrationsGeneratorCommand extends GeneratorCommand
10
{
11
    protected $name = 'dbe:migrations';
12
13
    protected $description = 'Export your database to migrations.';
14
    /**
15
     * @var \Nwidart\DbExporter\DbExportHandler
16
     */
17
    protected $handler;
18
19
    public function __construct(DbExportHandler $handler)
20
    {
21
        parent::__construct();
22
23
        $this->handler = $handler;
24
    }
25
26
    public function fire()
27
    {
28
        $database = $this->argument('database');
29
30
        // Display some helpfull info
31
        if (empty($database)) {
32
            $this->comment("Preparing the migrations for database: {$this->getDatabaseName()}");
33
        } else {
34
            $this->comment("Preparing the migrations for database {$database}");
35
        }
36
37
        // Grab the options
38
        $ignore = $this->option('ignore');
39
40
        if (empty($ignore)) {
41
            $this->handler->migrate($database);
42
        } else {
43
            $tables = explode(',', str_replace(' ', '', $ignore));
44
45
            $this->handler->ignore($tables)->migrate($this->argument('database'));
46
            foreach (DbExporter::$ignore as $table) {
47
                $this->comment("Ignoring the {$table} table");
48
            }
49
        }
50
51
        // Symfony style block messages
52
        $this->blockMessage('Success!', 'Database migrations generated in: ' . $this->handler->getMigrationsFilePath());
53
    }
54
55
    protected function getArguments()
56
    {
57
        return array(
58
            array('database', InputArgument::OPTIONAL, 'Override the application database')
59
        );
60
    }
61
62
    protected function getOptions()
63
    {
64
        return array(
65
            array('ignore', 'ign', InputOption::VALUE_REQUIRED, 'Ignore tables to export, seperated by a comma', null)
66
        );
67
    }
68
}