Completed
Push — master ( d43b57...61b043 )
by Randall
07:54 queued 04:32
created

ListCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 21
c 1
b 0
f 0
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getModules() 0 11 4
A handle() 0 3 1
A getRows() 0 15 3
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Other;
4
5
use Illuminate\Console\Command;
6
7
class ListCommand extends Command
8
{
9
    /** @var string */
10
    protected $signature = 'module:list
11
                            {--o|only= : The types of modules to list (enabled, disabled, or ordered)}
12
                            {--d|direction=asc : he direction to order the modules (only applies to --only=ordered)}';
13
14
    /** @var string */
15
    protected $description = 'Show a list of all modules.';
16
17
    public function handle(): void
18
    {
19
        $this->table(['Name', 'Status', 'Order', 'Path'], $this->getRows());
20
    }
21
22
    private function getModules(): array
23
    {
24
        switch ($this->option('only')) {
25
            case 'disabled':
26
                return $this->laravel['modules']->getByStatus(false);
27
            case 'enabled':
28
                return $this->laravel['modules']->getByStatus(true);
29
            case 'ordered':
30
                return $this->laravel['modules']->getOrdered($this->option('direction'));
31
            default:
32
                return $this->laravel['modules']->all();
33
        }
34
    }
35
36
    private function getRows(): array
37
    {
38
        $rows = [];
39
40
        /** @var \Rawilk\LaravelModules\Module $module */
41
        foreach ($this->getModules() as $module) {
42
            $rows[] = [
43
                $module->getName(),
44
                $module->isEnabled() ? 'Enabled' : 'Disabled',
45
                $module->get('order'),
46
                $module->getPath()
47
            ];
48
        }
49
50
        return $rows;
51
    }
52
}
53