Completed
Push — master ( 15e02a...758c52 )
by Nicolas
05:13
created

ListCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 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
     * @return mixed
28
     */
29
    public function fire()
30
    {
31
        $this->table(['Name', 'Status', 'Order', 'Path'], $this->getRows());
32
    }
33
34
    /**
35
     * Get table rows.
36
     *
37
     * @return array
38
     */
39
    public function getRows()
40
    {
41
        $rows = [];
42
43
        foreach ($this->getModules() as $module) {
44
            $rows[] = [
45
                $module->getStudlyName(),
46
                $module->enabled() ? 'Enabled' : 'Disabled',
47
                $module->get('order'),
48
                $module->getPath(),
49
            ];
50
        }
51
52
        return $rows;
53
    }
54
55
    public function getModules()
56
    {
57
        switch ($this->option('only')) {
58
            case 'enabled':
59
                return $this->laravel['modules']->getByStatus(1);
60
                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...
61
62
            case 'disabled':
63
                return $this->laravel['modules']->getByStatus(0);
64
                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...
65
66
            case 'ordered':
67
                return $this->laravel['modules']->getOrdered($this->option('direction'));
68
                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...
69
70
            default:
71
                return $this->laravel['modules']->all();
72
                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...
73
        }
74
    }
75
76
    /**
77
     * Get the console command options.
78
     *
79
     * @return array
80
     */
81 16
    protected function getOptions()
82
    {
83
        return array(
84 16
            array('only', null, InputOption::VALUE_OPTIONAL, 'Types of modules will be displayed.', null),
85 16
            array('direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'),
86 16
        );
87
    }
88
}
89