Completed
Push — master ( cafb47...1e1424 )
by Nicolas
16s queued 11s
created

EnableCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
dl 76
loc 76
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 23 23 3
A enableAll() 15 15 3
A getArguments() 6 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\Module;
7
use Symfony\Component\Console\Input\InputArgument;
8
9 View Code Duplication
class EnableCommand extends Command
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'module:enable';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Enable the specified module.';
24
25
    /**
26
     * Execute the console command.
27
     */
28 2
    public function handle() : int
29
    {
30
        /**
31
         * check if user entred an argument
32
         */
33 2
        if ($this->argument('module') === null) {
34 1
            $this->enableAll();
35 1
            return 0;
36
        }
37
38
        /** @var Module $module */
39 1
        $module = $this->laravel['modules']->findOrFail($this->argument('module'));
40
41 1
        if ($module->isDisabled()) {
42 1
            $module->enable();
43
44 1
            $this->info("Module [{$module}] enabled successful.");
45
        } else {
46
            $this->comment("Module [{$module}] has already enabled.");
47
        }
48
49 1
        return 0;
50
    }
51
52
    /**
53
     * enableAll
54
     *
55
     * @return void
56
     */
57 1
    public function enableAll()
58
    {
59
        /** @var Modules $modules */
60 1
        $modules = $this->laravel['modules']->all();
61
62 1
        foreach ($modules as $module) {
63 1
            if ($module->isDisabled()) {
64 1
                $module->enable();
65
66 1
                $this->info("Module [{$module}] enabled successful.");
67
            } else {
68
                $this->comment("Module [{$module}] has already enabled.");
69
            }
70
        }
71 1
    }
72
73
    /**
74
     * Get the console command arguments.
75
     *
76
     * @return array
77
     */
78 128
    protected function getArguments()
79
    {
80
        return [
81 128
            ['module', InputArgument::OPTIONAL, 'Module name.'],
82
        ];
83
    }
84
}
85