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

MigrateInstallCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A run() 0 11 2
A register() 0 9 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\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