Completed
Pull Request — master (#2)
by Randall
04:53
created

MigrateStatusCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A migrateStatus() 0 7 1
A handle() 0 17 3
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Other;
4
5
use Illuminate\Console\Command;
6
use Rawilk\LaravelModules\Migrations\Migrator;
7
use Rawilk\LaravelModules\Module;
8
9
class MigrateStatusCommand extends Command
10
{
11
    /** @var string */
12
    protected $signature = 'module:migrate-status
13
                            {module? : Show migration status for a specific module}
14
                            {--d|direction=asc : The direction to order modules in}
15
                            {--database= : The database connection to use}';
16
17
    /** @var string */
18
    protected $description = 'See the status of module migrations.';
19
20
    /** @var \Rawilk\LaravelModules\Contracts\Repository */
21
    protected $module;
22
23
    public function handle(): void
24
    {
25
        $this->module = $this->laravel['modules'];
26
27
        if ($name = $this->option('module')) {
28
            $module = $this->module->findOrFail($name);
29
30
            $this->migrateStatus($module);
31
32
            return;
33
        }
34
35
        /** @var \Rawilk\LaravelModules\Module $module */
36
        foreach ($this->module->getOrdered($this->option('direction')) as $module) {
37
            $this->line("Getting migration status for module: <info>{$module->getName()}</info>");
38
39
            $this->migrateStatus($module);
40
        }
41
    }
42
43
    private function migrateStatus(Module $module): void
44
    {
45
        $path = str_replace(base_path(), '', (new Migrator($module, $this->getLaravel()))->getPath());
46
47
        $this->call('migrate:status', [
48
            '--path'     => $path,
49
            '--database' => $this->option('database')
50
        ]);
51
    }
52
}
53