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.
Completed
Push — master ( cc6f9b...9d997c )
by Aden
03:12
created

AdminManager::getAdminInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace LaravelFlare\Flare\Admin;
4
5
use Illuminate\Routing\Router;
6
use LaravelFlare\Flare\Permissions\Permissions;
7
8
class AdminManager
9
{
10
    /**
11
     * Base Class.
12
     *
13
     * The Base Class for Model Admin's
14
     */
15
    const BASE_CLASS = 'LaravelFlare\Flare\Admin\Admin';
16
17
    /**
18
     * Admin Config Key.
19
     *
20
     * Key which defined where in the Flare Admin Config to
21
     * load the Admin classes from.
22
     *
23
     * @var string
24
     */
25
    const ADMIN_KEY = 'admin';
26
27
    /**
28
     * __construct.
29
     */
30
    public function __construct()
31
    {
32
    }
33
34
    /**
35
     * Returns the array used for the Admin Menu.
36
     *
37
     * This is temporary but it shouldn't be a breaking
38
     * change when it is altered or removed.
39
     * 
40
     * @return 
41
     */
42
    public function getAdminMenu()
43
    {
44
        return $this->getAdminClasses();
45
    }
46
47
    /**
48
     * Gets Admin classes based on the current users permissions
49
     * which have been set. If a Admin class has not had the
50
     * Permissions provided, it will be displayed by default.
51
     * 
52
     * @return 
53
     */
54
    public function getAdminClasses()
55
    {
56
        $classCollection = [];
57
58
        if (!defined('static::ADMIN_KEY')) {
59
            return $classCollection;
60
        }
61
62
        $classCollection = $this->getSubAdminClasses(\Flare::config(static::ADMIN_KEY));
63
64
        return $classCollection;
65
    }
66
67
    /**
68
     * Takes an array of classes and returns the 
69
     * classes which are available with the 
70
     * current permissions/policy set.
71
     * 
72
     * @param array $classes
73
     * 
74
     * @return array
75
     */
76
    public function getSubAdminClasses(array $classes)
77
    {
78
        $classCollection = [];
79
80
        foreach ($classes as $key => $class) {
81
            if ($this->usableClass($key)) {
82
                $classCollection[] = [$key => $this->getSubAdminClasses($class)];
83
                continue;
84
            }
85
86
            if ($this->usableClass($class)) {
87
                $classCollection[] = $class;
88
                continue;
89
            }
90
        }
91
92
        return $classCollection;
93
    }
94
95
    /**
96
     * Returns an instance of the Admin.
97
     * 
98
     * @return Admin
99
     */
100
    public static function getAdminInstance()
101
    {
102
        if (!$requested = Admin::getRequested()) {
103
            return;
104
        }
105
106
        return new $requested();
107
    }
108
109
    /**
110
     * Register Admin Routes.
111
     *
112
     * Loops through all of the Admin classes in the collection
113
     * and registers their Admin Routes.
114
     */
115
    public function registerRoutes(Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
116
    {
117
        $this->registerSubRoutes($this->getAdminClasses());
118
    }
119
120
    /**
121
     * Loops through an array of classes
122
     * and registers their Route recursively.
123
     * 
124
     * @param array $classes
125
     */
126
    public function registerSubRoutes(array $classes)
127
    {
128
        foreach ($classes as $key => $class) {
129
            if (is_array($class)) {
130
                if ($this->usableClass($key)) {
131
                    $this->registerAdminRoutes($key);
132
                }
133
134
                $this->registerSubRoutes($class);
135
                continue;
136
            }
137
            $this->registerAdminRoutes($class);
138
        }
139
    }
140
141
    /**
142
     * Registers an individual group of Admin routes.
143
     * 
144
     * @param string $class
145
     */
146
    public function registerAdminRoutes($class)
147
    {
148
        (new $class())->registerRoutes(\App::make(\Illuminate\Routing\Router::class));
149
    }
150
151
    /**
152
     * Determines if a class is usable.
153
     * 
154
     * @param string $class
155
     * 
156
     * @return bool
157
     */
158
    private function usableClass($class)
159
    {
160
        if (!is_scalar($class) || !class_exists($class)) {
161
            return false;
162
        }
163
164
        if ($class == static::BASE_CLASS) {
165
            return false;
166
        }
167
168
        return true;
169
    }
170
171
    /**
172
     * Determines if a class is available for the current User.
173
     * 
174
     * @param  string $class 
175
     * 
176
     * @return boolean
177
     */
178
    private function availableClass($class)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
179
    {
180
        if (!Permissions::check($class)) {
181
            return false;
182
        }
183
184
        return true;
185
    }
186
}
187