Completed
Pull Request — master (#1032)
by
unknown
05:37
created

MigrateRefreshCommand::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Console\Command;
6
use Nwidart\Modules\Traits\ModuleCommandTrait;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class MigrateRefreshCommand extends Command
11
{
12
    use ModuleCommandTrait;
13
14
    /**
15
     * The console command name.
16
     *
17
     * @var string
18
     */
19
    protected $name = 'module:migrate-refresh';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Rollback & re-migrate the modules migrations.';
27
28
    /**
29
     * Execute the console command.
30
     */
31
    public function handle() : int
32
    {
33
        $module = $this->argument('module');
34
35
        if ($module && !$this->getModuleName()) {
36
            $this->error("Module [$module] does not exists.");
37
            return E_ERROR;
38
        }
39
40
        $this->call('module:migrate-reset', [
41
            'module' => $this->getModuleName(),
42
            '--database' => $this->option('database'),
43
            '--force' => $this->option('force'),
44
        ]);
45
46
        $this->call('module:migrate', [
47
            'module' => $this->getModuleName(),
48
            '--database' => $this->option('database'),
49
            '--force' => $this->option('force'),
50
        ]);
51
52
        if ($this->option('seed')) {
53
            $this->call('module:seed', [
54
                'module' => $this->getModuleName(),
55
            ]);
56
        }
57
58
        return 0;
59
    }
60
61
    /**
62
     * Get the console command arguments.
63
     *
64
     * @return array
65
     */
66 128
    protected function getArguments()
67
    {
68
        return [
69 128
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
70
        ];
71
    }
72
73
    /**
74
     * Get the console command options.
75
     *
76
     * @return array
77
     */
78 128 View Code Duplication
    protected function getOptions()
79
    {
80
        return [
81 128
            ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
82
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
83
            ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'],
84
        ];
85
    }
86
87
    public function getModuleName()
88
    {
89
        $module = $this->argument('module');
90
91
        if (!$module) {
92
            return null;
93
        }
94
95
        $module = app('modules')->find($module);
96
97
        if (!$module) {
98
            return null;
99
        }
100
101
        return $module->getStudlyName();
102
    }
103
}
104