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 ( 2802ed...786417 )
by Aden
04:46
created

Admin::__callStatic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace LaravelFlare\Flare\Admin;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Routing\Router;
7
8
abstract class Admin
9
{
10
    /**
11
     * Admin Section Icon.
12
     *
13
     * Font Awesome Defined Icon, eg 'user' = 'fa-user'
14
     *
15
     * @var string
16
     */
17
    protected $icon;
18
19
    /**
20
     * Title of Admin Section.
21
     *
22
     * @var string
23
     */
24
    protected $title;
25
26
    /**
27
     * Plural Title of Admin Section.
28
     *
29
     * @var string
30
     */
31
    protected $pluralTitle;
32
33
    /**
34
     * URL Prefix of Admin Section.
35
     *
36
     * @var string
37
     */
38
    protected $urlPrefix;
39
40
    /**
41
     * The Controller to be used by the Admin.
42
     *
43
     * This defaults to parent::getController()
44
     * if it has been left undefined. 
45
     * 
46
     * @var string
47
     */
48
    protected $controller = \LaravelFlare\Flare\Http\Controllers\AdminController::class;
49
50
    /**
51
     * The Policy used for the Admin Authorization logic.
52
     * 
53
     * @var string
54
     */
55
    protected $policy = '\LaravelFlare\Flare\Permissions\AdminPolicy';
56
57
    /**
58
     * An array of subclasses of Admin
59
     * which allows hierachy in a Module.
60
     * 
61
     * @var array
62
     */
63
    protected $subAdmin = [];
64
65
    /**
66
     * The Admin Default View.
67
     *
68
     * By Default this is the 404 page
69
     *
70
     * @var string
71
     */
72
    protected $view = 'admin.404';
73
74
    /**
75
     * Array of View Data to Render.
76
     * 
77
     * @var array
78
     */
79
    protected $viewData = [];
80
81
    /**
82
     * Class Suffix used for matching and removing term
83
     * from user provided Admin sections.
84
     *
85
     * @var string
86
     */
87
    const CLASS_SUFFIX = 'Admin';
88
89
    /**
90
     * __construct.
91
     */
92
    public function __construct()
93
    {
94
    }
95
96
    /**
97
     * Register the routes for this Admin Section.
98
     *
99
     * Default routes include, create:, read:, update:, delete:
100
     *
101
     * Also attempts to load in ModelAdminController
102
     * based on the shortName of the class, for
103
     * overloading and adding additional routes
104
     *
105
     * @param \Illuminate\Routing\Router $router
106
     */
107
    public function registerRoutes(Router $router)
108
    {
109
        // We will need to throw an exception if a ModelAdmin manages a Model which conflicts with an internal flare endpoint
110
        // such as (create, edit, view, delete etc) 
111
        $router->group(['prefix' => $this->urlPrefix(), 'namespace' => get_called_class(), 'as' => $this->urlPrefix()], function ($router) {
112
            $this->registerSubRoutes();
113
            $router->controller('/', $this->getController());
114
        });
115
    }
116
117
    /**
118
     * Register subRoutes for Defined Admin instances.
119
     *
120
     * @return
121
     */
122
    public function registerSubRoutes()
123
    {
124
        if (!is_array($this->subAdmin)) {
125
            return;
126
        }
127
128
        foreach ($this->subAdmin as $adminItem) {
129
            $this->registerRoute($adminItem->getController(), $adminItem->routeParameters());
130
        }
131
    }
132
133
    /**
134
     * Register an individual route.
135
     *
136
     * @param string $controller
137
     * @param array  $parameters
138
     *
139
     * @return
140
     */
141
    public static function registerRoute($controller, $parameters = [])
0 ignored issues
show
Unused Code introduced by
The parameter $controller 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...
142
    {
143
        \Route::group($parameters, function ($controller) {
144
            \Route::controller('/', $controller);
0 ignored issues
show
Deprecated Code introduced by
The method Illuminate\Routing\Router::controller() has been deprecated with message: since version 5.2.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
145
        });
146
    }
147
148
    /**
149
     * Returns the Route Paramets.
150
     * 
151
     * @return array
152
     */
153
    public function routeParameters()
154
    {
155
        return [
156
            'prefix' => $this->urlPrefix(),
157
            'as' => $this->urlPrefix(),
158
        ];
159
    }
160
161
    /**
162
     * Returns the Requested Route Action as a
163
     * string, namespace is returned by default.
164
     *
165
     * @param string $key
166
     * 
167
     * @return string|void
168
     */
169
    public static function getRequested($key = 'namespace')
170
    {
171
        if (!\Route::current()) {
172
            return;
173
        }
174
175
        $currentAction = \Route::current()->getAction();
176
177
        if (isset($currentAction[$key])) {
178
            return $currentAction[$key];
179
        }
180
181
        return;
182
    }
183
184
    /**
185
     * Returns the Controller Class for the current Admin section.
186
     * 
187
     * @return string
188
     */
189
    public function getController()
190
    {
191
        return $this->controller;
192
    }
193
194
    /**
195
     * Set the Controller Class for the current Admin section.
196
     * 
197
     * @return string
198
     */
199
    public function setController($controller = null)
200
    {
201
        $this->controller = $controller;
202
    }
203
204
    /**
205
     * Returns the Module Admin View.
206
     * 
207
     * @return string
208
     */
209
    public function getView()
210
    {
211
        if (view()->exists($this->view)) {
0 ignored issues
show
Bug introduced by
The method exists does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
212
            return $this->view;
213
        }
214
215
        return 'flare::'.$this->view;
216
    }
217
218
    /**
219
     * Set the Module Admin View.
220
     * 
221
     * @param string $view
222
     */
223
    public function setView($view = null)
224
    {
225
        $this->view = $view;
226
    }
227
228
    /**
229
     * Returns the View Data.
230
     * 
231
     * @return array
232
     */
233
    public function getViewData()
234
    {
235
        return $this->viewData;
236
    }
237
238
    /**
239
     * Set the View Data.
240
     * 
241
     * @param array $viewData
242
     */
243
    public function setViewData($viewData = [])
244
    {
245
        $this->viewData = $viewData;
246
    }
247
248
    /**
249
     * Menu Items.
250
     * 
251
     * @return array
252
     */
253
    public function menuItems()
254
    {
255
        return [];
256
    }
257
258
    /**
259
     * Icon of a Admin Section Class.
260
     *
261
     * @return string
262
     */
263
    public function getIcon()
264
    {
265
        return $this->icon;
266
    }
267
268
    /**
269
     * Set Icon of a Admin Section Class.
270
     *
271
     * @param string $icon
272
     */
273
    public function setIcon($icon = null)
274
    {
275
        $this->icon = $icon;
276
    }
277
278
    /**
279
     * Shortname of a Admin Section Class.
280
     *
281
     * @return string
282
     */
283
    public static function shortName()
284
    {
285
        return (new \ReflectionClass(new static()))->getShortName();
286
    }
287
288
    /**
289
     * Title of a Admin Section Class.
290
     *
291
     * @return string
292
     */
293
    public function getTitle()
294
    {
295
        if (!isset($this->title) || !$this->title) {
296
            return Str::title(str_replace('_', ' ', snake_case(str_replace(static::CLASS_SUFFIX, '', static::shortName()))));
297
        }
298
299
        return $this->title;
300
    }
301
302
    /**
303
     * Set Title of a Admin Section Class.
304
     *
305
     * @param string $title
306
     */
307
    public function setTitle($title = null)
308
    {
309
        $this->title = $title;
310
    }
311
312
    /**
313
     * Plural of the Admin Section Class Title.
314
     *
315
     * @return string
316
     */
317
    public function getPluralTitle()
318
    {
319
        if (!isset($this->getPluralTitle) || !$this->getPluralTitle) {
0 ignored issues
show
Bug introduced by
The property getPluralTitle does not seem to exist. Did you mean pluralTitle?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
320
            return Str::plural($this->getTitle());
321
        }
322
323
        return $this->getPluralTitle;
0 ignored issues
show
Bug introduced by
The property getPluralTitle does not seem to exist. Did you mean pluralTitle?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
324
    }
325
326
    /**
327
     * Set Plural Title.
328
     * 
329
     * @param string $pluralTitle
330
     */
331
    public function setPluralTitle($pluralTitle = null)
332
    {
333
        $this->getPluralTitle = $pluralTitle;
0 ignored issues
show
Bug introduced by
The property getPluralTitle does not seem to exist. Did you mean pluralTitle?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
334
    }
335
336
    /**
337
     * URL Prefix to a Admin Section Top Level Page.
338
     *
339
     * @return string
340
     */
341
    public function urlPrefix()
342
    {
343
        if (!isset($this->urlPrefix) || !$this->urlPrefix) {
344
            return str_slug($this->getPluralTitle());
345
        }
346
347
        return $this->urlPrefix;
348
    }
349
350
    /**
351
     * URL to a Admin Top Level Page.
352
     *
353
     * @param string $path
354
     *
355
     * @return string
356
     */
357
    public function url($path = '')
358
    {
359
        return url($this->relativeUrl($path));
360
    }
361
362
    /**
363
     * Relative URL to an Admin Top Level Page.
364
     *
365
     * @param string $path
366
     *
367
     * @return string
368
     */
369
    public function relativeUrl($path = '')
370
    {
371
        return \Flare::relativeAdminUrl($this->urlPrefix().($path ? '/'.$path : ''));
372
    }
373
374
    /**
375
     * Retrieves the Current Admin Route URL.
376
     *
377
     * @param string $path
378
     *
379
     * @return string
380
     */
381
    public function currentUrl($path = '')
382
    {
383
        return url($this->relativeCurrentUrl($path));
384
    }
385
386
    /**
387
     * Retrieves the Current Admin Route URL.
388
     *
389
     * @param string $path
390
     *
391
     * @return string
392
     */
393
    public function relativeCurrentUrl($path)
394
    {
395
        return \Route::current() ? \Route::current()->getPrefix().'/'.$path : null;
396
    }
397
398
    /**
399
     * Handle dynamic static method calls into the Admin.
400
     *
401
     * @param string $method
402
     * @param array  $parameters
403
     * 
404
     * @return mixed
405
     */
406
    // public static function __callStatic($method, $parameters)
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
407
    // {
408
    //     $instance = new static();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
409
410
    //     return call_user_func_array([$instance, $method], $parameters);
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
411
    // }
412
}
413