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

MigrateInstallCommand::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
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\MigrationRepositoryInterface;
8
9
class MigrateInstallCommand extends Command
10
{
11
    use DatabaseAwareCommandTrait;
12
    use MigrationAwareCommandTrait;
13
14
    public static $name = 'migrate:install';
15
    protected $args;
16
    protected $repository;
17
18
    public function __construct(callable $outputFormatter, Args $args, MigrationRepositoryInterface $repository)
19
    {
20
        parent::__construct($outputFormatter);
21
        $this->args = $args;
22
        $this->repository = $repository;
23
    }
24
25
    public function run()
26
    {
27
        if ($this->repository->repositoryExists()) {
28
            $this->echoInfo('Migration table already exists.');
29
            return 0;
30
        }
31
32
        $this->repository->createRepository();
33
        $this->echoInfo('Migration table created successfully.');
34
        return 0;
35
    }
36
37
    public static function register(Cli $cli)
38
    {
39
        $cli = static::registerDatabaseOpts($cli);
40
        $cli = static::registerMigrationOpts($cli);
41
42
        return $cli
43
            ->command(static::$name)
44
            ->description('Create the migration repository.');
45
    }
46
}
47