Completed
Push — master ( de7438...b51e5e )
by Nicolas
12:59
created

MigrateRefreshCommand::getModuleName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 12
ccs 0
cts 6
cp 0
crap 6
rs 9.4285
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()
32
    {
33
        $this->call('module:migrate-reset', [
34
            'module' => $this->getModuleName(),
35
            '--database' => $this->option('database'),
36
            '--force' => $this->option('force'),
37
        ]);
38
39
        $this->call('module:migrate', [
40
            'module' => $this->getModuleName(),
41
            '--database' => $this->option('database'),
42
            '--force' => $this->option('force'),
43
        ]);
44
45
        if ($this->option('seed')) {
46
            $this->call('module:seed', [
47
                'module' => $this->getModuleName(),
48
            ]);
49
        }
50
    }
51
52
    /**
53
     * Get the console command arguments.
54
     *
55
     * @return array
56
     */
57 56
    protected function getArguments()
58
    {
59
        return array(
60 56
            array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
61
        );
62
    }
63
64
    /**
65
     * Get the console command options.
66
     *
67
     * @return array
68
     */
69 56
    protected function getOptions()
70
    {
71
        return array(
72 56
            array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
73
            array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
74
            array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'),
75
        );
76
    }
77
78
    public function getModuleName()
79
    {
80
        $module = $this->argument('module');
81
82
        app('modules')->find($module);
83
84
        if ($module === null) {
85
            return $module;
86
        }
87
88
        return $module->getStudlyName();
0 ignored issues
show
Bug introduced by
The method getStudlyName cannot be called on $module (of type string|array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
89
    }
90
}
91