Completed
Push — master ( 148261...6e27f1 )
by Nicolas
03:56
created

UpdateCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 25.86 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 13.33%

Importance

Changes 0
Metric Value
dl 15
loc 58
ccs 2
cts 15
cp 0.1333
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 15 15 3
A updateModule() 0 8 1
A getArguments() 0 6 1

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
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
9
class UpdateCommand extends Command
10
{
11
    use ModuleCommandTrait;
12
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'module:update';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Update dependencies for the specified module or for all modules.';
26
27
    /**
28
     * Execute the console command.
29
     */
30 View Code Duplication
    public function handle()
31
    {
32
        $name = $this->argument('module');
33
34
        if ($name) {
35
            $this->updateModule($name);
36
37
            return;
38
        }
39
40
        /** @var \Nwidart\Modules\Module $module */
41
        foreach ($this->laravel['modules']->getOrdered() as $module) {
42
            $this->updateModule($module->getName());
43
        }
44
    }
45
46
    protected function updateModule($name)
47
    {
48
        $this->line('Running for module: <info>'.$name.'</info>');
49
50
        $this->laravel['modules']->update($name);
51
52
        $this->info("Module [{$name}] updated successfully.");
53
    }
54
55
    /**
56
     * Get the console command arguments.
57
     *
58
     * @return array
59
     */
60 92
    protected function getArguments()
61
    {
62
        return [
63 92
            ['module', InputArgument::OPTIONAL, 'The name of module will be updated.'],
64
        ];
65
    }
66
}
67