Completed
Push — master ( 7a93ab...e5b266 )
by Michael
03:59
created

MigrateCommand::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Schnittstabil\Dartisan\Commands;
4
5
use Garden\Cli\Cli;
6
use Garden\Cli\Args;
7
use Illuminate\Database\Migrations\Migrator;
8
9
class MigrateCommand extends Command
10
{
11
    use DatabaseAwareCommandTrait;
12
    use MigrationAwareCommandTrait;
13
14
    public static $name = 'migrate';
15
    protected $args;
16
    protected $migrator;
17
    protected $defaultPath;
18
19
    public function __construct(callable $outputFormatter, Args $args, Migrator $migrator, $defaultPath)
20
    {
21
        parent::__construct($outputFormatter);
22
        $this->args = $args;
23
        $this->migrator = $migrator;
24
        $this->defaultPath = $defaultPath;
25
    }
26
27
    public function run()
28
    {
29
        $path = $this->args->getOpt('path', $this->defaultPath);
30
        $this->migrator->run($path, [
31
            'pretend' => $this->args->getOpt('pretend', null),
32
            'step' => $this->args->getOpt('step', null),
33
        ]);
34
        $this->echoNotes($this->migrator->getNotes());
35
        return 0;
36
    }
37
38
    public static function register(Cli $cli)
39
    {
40
        $cli = static::registerDatabaseOpts($cli);
41
        $cli = static::registerMigrationOpts($cli);
42
43
        return $cli
44
            ->command(static::$name)
45
            ->description('Run the database migrations.')
46
            ->opt('path', 'The path of migrations files to be executed.')
47
            ->opt('pretend', 'Dump the SQL queries that would be run.')
48
            ->opt('step', 'Force the migrations to be run so they can be rolled back individually.');
49
    }
50
}
51