RouteManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 41
ccs 0
cts 18
cp 0
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isAdminArea() 0 7 2
A handle() 0 22 4
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