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 ( 876fe8...335247 )
by Aden
03:26
created

AdminManager::getAdminMenu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace LaravelFlare\Flare\Admin;
4
5
use LaravelFlare\Flare\Permissions\Permissions;
6
7
class AdminManager
8
{
9
    /**
10
     * Base Class.
11
     *
12
     * The Base Class for Model Admin's
13
     */
14
    const BASE_CLASS = 'LaravelFlare\Flare\Admin\Admin';
15
16
    /**
17
     * Admin Config Key.
18
     *
19
     * Key which defined where in the Flare Admin Config to
20
     * load the Admin classes from.
21
     *
22
     * @var string
23
     */
24
    const ADMIN_KEY = 'admin';
25
26
    /**
27
     * __construct.
28
     */
29
    public function __construct()
30
    {
31
32
    }
33
34
    public function getAdminMenu()
35
    {
36
        return $this->getAdminClasses();
37
    }
38
39
    /**
40
     * Gets Admin classes based on the current users permissions
41
     * which have been set. If a Admin class has not had the
42
     * Permissions provided, it will be displayed by default.
43
     * 
44
     * @return 
45
     */
46
    public function getAdminClasses()
47
    {
48
        $classCollection = [];
49
50
        if (!defined('static::ADMIN_KEY')) {
51
            return $classCollection;
52
        }
53
54
        $classCollection = $this->getSubAdminClasses(\Flare::config(static::ADMIN_KEY));
55
56
        return $classCollection;
57
    }
58
59
    /**
60
     * Takes an array of classes and returns the 
61
     * classes which are available with the 
62
     * current permissions/policy set.
63
     * 
64
     * @param array $classes
65
     * 
66
     * @return array
67
     */
68
    public function getSubAdminClasses(array $classes)
69
    {
70
        $classCollection = [];
71
72
        foreach ($classes as $key => $class) {
73
            if ($this->usableClass($key)) {
74
                $classCollection[] = [$key => $this->getSubAdminClasses($class)];
75
                continue;
76
            }
77
78
            if ($this->usableClass($class)) {
79
                $classCollection[] = $class;
80
                continue;
81
            }
82
        }
83
84
        return $classCollection;
85
    }
86
87
    /**
88
     * Returns an instance of the Admin.
89
     * 
90
     * @return Admin
91
     */
92
    public static function getAdminInstance()
93
    {
94
        if (!$requested = Admin::getRequested()) {
95
            return;
96
        }
97
98
        return new $requested();
99
    }
100
101
    /**
102
     * Register Admin Routes.
103
     *
104
     * Loops through all of the Admin classes in the collection
105
     * and registers their Admin Routes.
106
     */
107
    public function registerRoutes()
108
    {
109
        $this->registerSubRoutes($this->getAdminClasses());
110
    }
111
112
    /**
113
     * Loops through an array of classes
114
     * and registers their Route recursively.
115
     * 
116
     * @param array $classes
117
     */
118
    public function registerSubRoutes(array $classes)
119
    {
120
        foreach ($classes as $key => $class) {
121
            if (is_array($class)) {
122
                if ($this->usableClass($key)) {
123
                    $this->registerRoute($key);
124
                }
125
126
                $this->registerSubRoutes($class);
127
                continue;
128
            }
129
            $this->registerRoute($class);
130
        }
131
    }
132
133
    /**
134
     * Registers an individual group of Admin routes.
135
     * 
136
     * @param string $class
137
     */
138
    public function registerRoute($class)
139
    {
140
        (new $class())->registerRoutes();
141
    }
142
143
    /**
144
     * Determines if a class is usable by the currently
145
     * defined user and their permission set.
146
     * 
147
     * @param string $class
148
     * 
149
     * @return bool
150
     */
151
    private function usableClass($class)
152
    {
153
        if (!is_scalar($class) || !class_exists($class)) {
154
            return false;
155
        }
156
157
        if ($class == static::BASE_CLASS) {
158
            return false;
159
        }
160
161
        return true;
162
    }
163
}
164