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 ( b16169...c8abb5 )
by Aden
12:12 queued 32s
created

AdminManager   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 19
c 4
b 0
f 0
lcom 1
cbo 2
dl 0
loc 154
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getAdminClasses() 0 12 2
A getSubAdminClasses() 0 18 4
A getAdminInstance() 0 8 2
A registerRoutes() 0 4 1
A registerSubRoutes() 0 14 4
A registerRoute() 0 4 1
A usableClass() 0 12 4
1
<?php
2
3
namespace LaravelFlare\Flare\Admin;
4
5
use Illuminate\Support\Collection;
6
use LaravelFlare\Flare\Permissions\Permissions;
7
8
class AdminManager extends Collection
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
        parent::__construct();
33
34
        $this->items = $this->getAdminClasses();
35
    }
36
37
    /**
38
     * Gets Admin classes based on the current users permissions
39
     * which have been set. If a Admin class has not had the
40
     * Permissions provided, it will be displayed by default.
41
     * 
42
     * @return 
43
     */
44
    public function getAdminClasses()
45
    {
46
        $classCollection = [];
47
48
        if (!defined('static::ADMIN_KEY')) {
49
            return $classCollection;
50
        }
51
52
        $classCollection = $this->getSubAdminClasses(\Flare::config(static::ADMIN_KEY));
53
54
        return $classCollection;
55
    }
56
57
    /**
58
     * Takes an array of classes and returns the 
59
     * classes which are available with the 
60
     * current permissions/policy set.
61
     * 
62
     * @param array $classes
63
     * 
64
     * @return array
65
     */
66
    public function getSubAdminClasses(array $classes)
67
    {
68
        $classCollection = [];
69
70
        foreach ($classes as $key => $class) {
71
            if ($this->usableClass($key)) {
72
                $classCollection[] = [$key => $this->getSubAdminClasses($class)];
73
                continue;
74
            }
75
76
            if ($this->usableClass($class)) {
77
                $classCollection[] = $class;
78
                continue;
79
            }
80
        }
81
82
        return $classCollection;
83
    }
84
85
    /**
86
     * Returns an instance of the Admin.
87
     * 
88
     * @return Admin
89
     */
90
    public static function getAdminInstance()
91
    {
92
        if (!$requested = Admin::getRequested()) {
93
            return;
94
        }
95
96
        return new $requested();
97
    }
98
99
    /**
100
     * Register Admin Routes.
101
     *
102
     * Loops through all of the Admin classes in the collection
103
     * and registers their Admin Routes.
104
     */
105
    public function registerRoutes()
106
    {
107
        $this->registerSubRoutes($this->items);
108
    }
109
110
    /**
111
     * Loops through an array of classes
112
     * and registers their Route recursively.
113
     * 
114
     * @param array $classes
115
     */
116
    public function registerSubRoutes(array $classes)
117
    {
118
        foreach ($classes as $key => $class) {
119
            if (is_array($class)) {
120
                if ($this->usableClass($key)) {
121
                    $this->registerRoute($key);
122
                }
123
124
                $this->registerSubRoutes($class);
125
                continue;
126
            }
127
            $this->registerRoute($class);
128
        }
129
    }
130
131
    /**
132
     * Registers an individual group of Admin routes.
133
     * 
134
     * @param string $class
135
     */
136
    public function registerRoute($class)
137
    {
138
        (new $class())->registerRoutes();
139
    }
140
141
    /**
142
     * Determines if a class is usable by the currently
143
     * defined user and their permission set.
144
     * 
145
     * @param string $class
146
     * 
147
     * @return bool
148
     */
149
    private function usableClass($class)
150
    {
151
        if (!is_scalar($class) || !class_exists($class)) {
152
            return false;
153
        }
154
155
        if ($class == static::BASE_CLASS) {
156
            return false;
157
        }
158
159
        return true;
160
    }
161
}
162