Completed
Push — master ( b92470...5197c4 )
by Nicolas
60:52 queued 58:20
created

EnableCommand::enableAll()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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