GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ModuleListCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Caffeinated\Modules\Console\Commands;
4
5
use Caffeinated\Modules\Modules;
6
use Illuminate\Console\Command;
7
8
class ModuleListCommand 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 = 'List all application modules';
23
24
    /**
25
     * @var Modules
26
     */
27
    protected $module;
28
29
    /**
30
     * The table headers for the command.
31
     *
32
     * @var array
33
     */
34
    protected $headers = ['#', 'Name', 'Slug', 'Description', 'Status'];
35
36
    /**
37
     * Create a new command instance.
38
     *
39
     * @param Modules $module
40
     */
41
    public function __construct(Modules $module)
42
    {
43
        parent::__construct();
44
45
        $this->module = $module;
46
    }
47
48
    /**
49
     * Execute the console command.
50
     *
51
     * @return mixed
52
     */
53
    public function fire()
54
    {
55
        $modules = $this->module->all();
56
57
        if (count($modules) == 0) {
58
            return $this->error("Your application doesn't have any modules.");
59
        }
60
61
        $this->displayModules($this->getModules());
62
    }
63
64
    /**
65
     * Get all modules.
66
     *
67
     * @return array
68
     */
69
    protected function getModules()
70
    {
71
        $modules = $this->module->all();
72
        $results = [];
73
74
        foreach ($modules as $module) {
75
            $results[] = $this->getModuleInformation($module);
76
        }
77
78
        return array_filter($results);
79
    }
80
81
    /**
82
     * Returns module manifest information.
83
     *
84
     * @param string $module
85
     *
86
     * @return array
87
     */
88
    protected function getModuleInformation($module)
89
    {
90
        return [
91
            '#'           => $module['order'],
92
            'name'        => $module['name'],
93
            'slug'        => $module['slug'],
94
            'description' => $module['description'],
95
            'status'      => ($this->module->isEnabled($module['slug'])) ? 'Enabled' : 'Disabled',
96
        ];
97
    }
98
99
    /**
100
     * Display the module information on the console.
101
     *
102
     * @param array $modules
103
     */
104
    protected function displayModules(array $modules)
105
    {
106
        $this->table($this->headers, $modules);
107
    }
108
}
109