Completed
Push — master ( f777a6...91e41e )
by Nicolas
11s
created

MigrateStatusCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 27.38 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 20%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 23
loc 84
ccs 4
cts 20
cp 0.2
rs 10
c 1
b 0
f 0
wmc 6
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A migrateStatus() 0 9 1
A getArguments() 0 6 1
A getOptions() 7 7 1
A handle() 16 16 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}