Passed
Push — master ( 517bd8...f7cc98 )
by Attila
06:55
created

ModulesCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 54
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 2
A showModules() 0 20 2
1
<?php
2
/**
3
 * Contains the Modules Command class.
4
 *
5
 * @copyright   Copyright (c) 2016 Attila Fulop
6
 * @author      Attila Fulop
7
 * @license     MIT
8
 * @since       2016-08-14
9
 */
10
11
12
namespace Konekt\Concord\Console\Commands;
13
14
use Illuminate\Console\Command;
15
use Illuminate\Support\Collection;
16
use Konekt\Concord\BaseModuleServiceProvider;
17
use Konekt\Concord\Contracts\Concord;
18
19
class ModulesCommand extends Command
20
{
21
    /** @var string  */
22
    protected $signature = 'concord:modules {--a|all : List all modules, including implicit ones}';
23
24
    /** @var string  */
25
    protected $description = 'List Concord Modules';
26
27
    /** @var array  */
28
    protected $headers = ['#', 'Name', 'Kind', 'Version', 'Id', 'Namespace'];
29
30
    /**
31
     * Execute the command.
32
     *
33
     * @param Concord $concord
34
     *
35
     * @return mixed
36
     */
37
    public function handle(Concord $concord)
38
    {
39
        $modules = $concord->getModules($this->option('all'));
0 ignored issues
show
Bug introduced by
$this->option('all') of type string is incompatible with the type boolean expected by parameter $includeImplicits of Konekt\Concord\Contracts\Concord::getModules(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        $modules = $concord->getModules(/** @scrutinizer ignore-type */ $this->option('all'));
Loading history...
40
41
        if ($modules->count()) {
42
            $this->showModules($modules);
43
        } else {
44
            $this->line('No modules have been registered. Add one in config/concord.php.');
45
        }
46
    }
47
48
    /**
49
     * Displays the list of modules on the output
50
     *
51
     * @param $modules Collection
52
     */
53
    protected function showModules(Collection $modules)
54
    {
55
        $table = [];
56
        $i     = 0;
57
58
        /** @var BaseModuleServiceProvider $module */
59
        foreach ($modules as $module) {
60
            $i++;
61
62
            $table[] = [
63
                'no'        => sprintf('%d.', $i),
64
                'name'      => $module->getManifest()->getName(),
65
                'kind'      => $module->getKind()->label(),
66
                'version'   => $module->getManifest()->getVersion(),
67
                'id'        => $module->getId(),
68
                'namespace' => $module->getNamespaceRoot()
69
            ];
70
        }
71
72
        $this->table($this->headers, $table);
73
    }
74
}
75