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

EnableCommand::enableAll()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 15
loc 15
ccs 7
cts 8
cp 0.875
crap 3.0175
rs 9.7666
c 0
b 0
f 0
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