Completed
Pull Request — master (#384)
by
unknown
03:06
created

MigrateStatusCommand::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 16
loc 16
ccs 0
cts 10
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Nwidart\Modules\Commands;
3
4
use Illuminate\Console\Command;
5
use Nwidart\Modules\Migrations\Migrator;
6
use Nwidart\Modules\Module;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class MigrateStatusCommand extends Command
11
{
12
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'module:migrate-status';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Status for all migrations';
26
27
    /**
28
     * @var \Nwidart\Modules\Repository
29
     */
30
    protected $module;
31
32
    /**
33
     * Execute the console command.
34
     *
35
     * @return mixed
36
     */
37 View Code Duplication
    public function handle()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $this->module = $this->laravel['modules'];
40
41
        $name = $this->argument('module');
42
43
        if ($name) {
44
            $module = $this->module->findOrFail($name);
45
            return $this->migrateStatus($module);
46
        }
47
48
        foreach ($this->module->getOrdered($this->option('direction')) as $module) {
49
            $this->line('Running for module: <info>' . $module->getName() . '</info>');
50
            $this->migrateStatus($module);
51
        }
52
    }
53
54
    /**
55
     * Run the migration from the specified module.
56
     *
57
     * @param Module $module
58
     */
59
    protected function migrateStatus(Module $module)
60
    {
61
        $path = str_replace(base_path(), '', (new Migrator($module))->getPath());
62
63
        $this->call('migrate:status', [
64
            '--path' => $path,
65
            '--database' => $this->option('database')
66
        ]);
67
    }
68
69
    /**
70
     * Get the console command arguments.
71
     *
72
     * @return array
73
     */
74 91
    protected function getArguments()
75
    {
76
        return [
77 91
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
78
        ];
79
    }
80
81
    /**
82
     * Get the console command options.
83
     *
84
     * @return array
85
     */
86 91 View Code Duplication
    protected function getOptions()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        return [
89 91
            ['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'],
90
            ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
91
        ];
92
    }
93
}