ModulesCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 21
c 0
b 0
f 0
dl 0
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 2
A showModules() 0 20 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Contains the Modules Command class.
7
 *
8
 * @copyright   Copyright (c) 2016 Attila Fulop
9
 * @author      Attila Fulop
10
 * @license     MIT
11
 * @since       2016-08-14
12
 */
13
14
namespace Konekt\Concord\Console\Commands;
15
16
use Illuminate\Console\Command;
17
use Illuminate\Support\Collection;
18
use Konekt\Concord\BaseModuleServiceProvider;
19
use Konekt\Concord\Contracts\Concord;
20
21
class ModulesCommand extends Command
22
{
23
    /** @var string  */
24
    protected $signature = 'concord:modules {--a|all : List all modules, including implicit ones}';
25
26
    /** @var string  */
27
    protected $description = 'List Concord Modules';
28
29
    /** @var array  */
30
    protected $headers = ['#', 'Name', 'Kind', 'Version', 'Id', 'Namespace'];
31
32
    public function handle(Concord $concord)
33
    {
34
        $modules = $concord->getModules((bool) $this->option('all'));
35
36
        if ($modules->count()) {
37
            $this->showModules($modules);
38
        } else {
39
            $this->line('No modules have been registered. Add one in config/concord.php.');
40
        }
41
    }
42
43
    /**
44
     * Displays the list of modules on the output
45
     *
46
     * @param $modules Collection
47
     */
48
    protected function showModules(Collection $modules)
49
    {
50
        $table = [];
51
        $i = 0;
52
53
        /** @var BaseModuleServiceProvider $module */
54
        foreach ($modules as $module) {
55
            $i++;
56
57
            $table[] = [
58
                'no' => sprintf('%d.', $i),
59
                'name' => $module->getManifest()->getName(),
60
                'kind' => $module->getKind()->label(),
61
                'version' => $module->getManifest()->getVersion(),
62
                'id' => $module->getId(),
63
                'namespace' => $module->getNamespaceRoot()
64
            ];
65
        }
66
67
        $this->table($this->headers, $table);
68
    }
69
}
70