Completed
Pull Request — master (#978)
by
unknown
02:37
created

EnableCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
dl 73
loc 73
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getArguments() 6 6 1
A handle() 20 20 3
A enableAll() 15 15 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
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()
29
    {
30
        /**
31
         * check if user entred an argument
32
         */
33 2
        if ($this->argument('module') === null) {
34 1
            return $this->enableAll();
35
        }
36
37
        /** @var Module $module */
38 1
        $module = $this->laravel['modules']->findOrFail($this->argument('module'));
39
40 1
        if ($module->isDisabled()) {
41 1
            $module->enable();
42
43 1
            $this->info("Module [{$module}] enabled successful.");
44
        } else {
45
            $this->comment("Module [{$module}] has already enabled.");
46
        }
47 1
    }
48
49
    /**
50
     * enableAll
51
     *
52
     * @return void
53
     */
54 1
    public function enableAll()
55
    {
56
        /** @var Modules $modules */
57 1
        $modules = $this->laravel['modules']->all();
58
59 1
        foreach ($modules as $module) {
60 1
            if ($module->isDisabled()) {
61 1
                $module->enable();
62
63 1
                $this->info("Module [{$module}] enabled successful.");
64
            } else {
65
                $this->comment("Module [{$module}] has already enabled.");
66
            }
67
        }
68 1
    }
69
70
    /**
71
     * Get the console command arguments.
72
     *
73
     * @return array
74
     */
75 128
    protected function getArguments()
76
    {
77
        return [
78 128
            ['module', InputArgument::OPTIONAL, 'Module name.'],
79
        ];
80
    }
81
}
82