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

MigrateMakeCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 6
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A run() 0 13 1
A register() 0 13 1
1
<?php
2
3
namespace Schnittstabil\Dartisan\Commands;
4
5
use Garden\Cli\Cli;
6
use Garden\Cli\Args;
7
use Illuminate\Database\Migrations\MigrationCreator;
8
9
class MigrateMakeCommand extends Command
10
{
11
    use DatabaseAwareCommandTrait;
12
    use MigrationAwareCommandTrait;
13
14
    public static $name = 'make:migration';
15
    protected $args;
16
    protected $migrationCreator;
17
    protected $migrationsPath;
18
19
    public function __construct(callable $outputFormatter, Args $args, MigrationCreator $migrationCreator, $migrationsPath)
20
    {
21
        parent::__construct($outputFormatter);
22
        $this->args = $args;
23
        $this->migrationCreator = $migrationCreator;
24
        $this->migrationsPath = $migrationsPath;
25
    }
26
27
    public function run()
28
    {
29
        $name = trim($this->args->getArg('name'));
30
        $path = $this->args->getOpt('path', $this->migrationsPath);
31
        $create = $this->args->getOpt('create');
32
        $table = $this->args->getOpt('table', $create);
33
34
        $file = pathinfo($this->migrationCreator->create($name, $path, $table, $create), PATHINFO_FILENAME);
35
        $this->echoInfo('Created Migration:', false);
36
        $this->echo(' ', false);
37
        $this->echo($file);
38
        return 0;
39
    }
40
41
    public static function register(Cli $cli)
42
    {
43
        $cli = static::registerDatabaseOpts($cli);
44
        $cli = static::registerMigrationOpts($cli);
45
46
        return $cli
47
            ->command(static::$name)
48
            ->description('Create a new migration file.')
49
            ->opt('create', 'The table to be created.')
50
            ->opt('table', 'The table to migrate.')
51
            ->opt('path', 'The location where the migration file should be created.')
52
            ->arg('name', 'The name of the migration.', true);
53
    }
54
}
55