RouteManager::isAdminArea()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 3
cp 0
crap 6
rs 10
c 2
b 0
f 0
1
<?php
2
3
namespace Terranet\Administrator\Providers\Handlers;
4
5
use Illuminate\Routing\Events\RouteMatched;
6
use Illuminate\Support\Arr;
7
8
class RouteManager
9
{
10
    public function handle()
11
    {
12
        app('router')->matched(function (RouteMatched $event) {
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

12
        /** @scrutinizer ignore-call */ 
13
        app('router')->matched(function (RouteMatched $event) {
Loading history...
13
            if (!$this->isAdminArea($event)) {
14
                return false;
15
            }
16
17
            $route = $event->route;
18
            $request = $event->request;
19
20
            if ($route->parameter('module')) {
21
                return true;
22
            }
23
            if ($resolver = app('scaffold.config')->get('resource.resolver')) {
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
            if ($resolver = /** @scrutinizer ignore-call */ app('scaffold.config')->get('resource.resolver')) {
Loading history...
24
                $module = \call_user_func_array($resolver, [$route, $request]);
25
            } else {
26
                $module = $request->segment(app('scaffold.config')->get('resource.segment', 2));
27
            }
28
29
            $route->setParameter('module', $module);
30
31
            return $module;
32
        });
33
    }
34
35
    /**
36
     * Check if running under admin area.
37
     *
38
     * @param RouteMatched $event
39
     *
40
     * @return bool
41
     */
42
    protected function isAdminArea(RouteMatched $event)
43
    {
44
        if ($action = $event->route->getAction()) {
45
            return config('administrator.prefix') === Arr::get($action, 'prefix');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
            return /** @scrutinizer ignore-call */ config('administrator.prefix') === Arr::get($action, 'prefix');
Loading history...
46
        }
47
48
        return false;
49
    }
50
}
51