Completed
Push — master ( d43b57...61b043 )
by Randall
07:54 queued 04:32
created

MigrateRefreshCommand::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 17
rs 9.9
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Other;
4
5
use Illuminate\Console\Command;
6
use Rawilk\LaravelModules\Traits\ModuleCommands;
7
8
class MigrateRefreshCommand extends Command
9
{
10
    use ModuleCommands;
11
12
    /** @var string */
13
    protected $signature = 'module:migrate-refresh
14
                            {module? : The name of the module to refresh migrations for}
15
                            {--database= : The database connection to use}
16
                            {--force : Force the operation to run when in production}
17
                            {--seed : Indicates if the seed task should be re-run}';
18
19
    /** @var string */
20
    protected $description = 'Rollback & re-migrate the migrations for the specified module.';
21
22
    public function handle(): void
23
    {
24
        $this->call('module:migrate-reset', [
25
            'module'     => $this->getModuleName(),
26
            '--database' => $this->option('database'),
27
            '--force'    => $this->option('force')
28
        ]);
29
30
        $this->call('module:migrate', [
31
            'module'     => $this->getModuleName(),
32
            '--database' => $this->option('database'),
33
            '--force'    => $this->option('force')
34
        ]);
35
36
        if ($this->option('seed')) {
37
            $this->call('module:seed', [
38
                'module' => $this->getModuleName()
39
            ]);
40
        }
41
    }
42
43
    private function getModuleName(): ?string
44
    {
45
        $module = $this->argument('module');
46
47
        /** @var \Rawilk\LaravelModules\Module $module */
48
        $module = $this->laravel['modules']->find($module);
49
50
        if ($module === null) {
51
            return $module;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $module returns the type void which is incompatible with the type-hinted return null|string.
Loading history...
52
        }
53
54
        return $module->getStudlyName();
55
    }
56
}
57