Completed
Pull Request — master (#322)
by Mathieu
03:43
created

ListCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 79
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
wmc 9
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRows() 0 15 3
A getModules() 0 20 4
A getOptions() 0 7 1
A handle() 0 4 1
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class ListCommand extends Command
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'module:list';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Show list of all modules.';
23
24
    /**
25
     * Execute the console command.
26
     */
27
    public function handle()
28
    {
29
        $this->table(['Name', 'Status', 'Order', 'Path'], $this->getRows());
30
    }
31
32
    /**
33
     * Get table rows.
34
     *
35
     * @return array
36
     */
37
    public function getRows()
38
    {
39
        $rows = [];
40
41
        foreach ($this->getModules() as $module) {
42
            $rows[] = [
43
                $module->getName(),
44
                $module->enabled() ? 'Enabled' : 'Disabled',
45
                $module->get('order'),
46
                $module->getPath(),
47
            ];
48
        }
49
50
        return $rows;
51
    }
52
53
    public function getModules()
54
    {
55
        switch ($this->option('only')) {
56
            case 'enabled':
57
                return $this->laravel['modules']->getByStatus(1);
58
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
59
60
            case 'disabled':
61
                return $this->laravel['modules']->getByStatus(0);
62
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
63
64
            case 'ordered':
65
                return $this->laravel['modules']->getOrdered($this->option('direction'));
66
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
67
68
            default:
69
                return $this->laravel['modules']->all();
70
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
71
        }
72
    }
73
74
    /**
75
     * Get the console command options.
76
     *
77
     * @return array
78
     */
79 56
    protected function getOptions()
80
    {
81
        return array(
82 56
            array('only', null, InputOption::VALUE_OPTIONAL, 'Types of modules will be displayed.', null),
83
            array('direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'),
84
        );
85
    }
86
}
87