Completed
Pull Request — master (#546)
by Xander
02:09
created

CheckRouteRole   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B getRouteInformation() 0 16 5
1
<?php namespace Spatie\Permission\Commands;
2
 
3
use Illuminate\Routing\Route;
4
use Illuminate\Foundation\Console\RouteListCommand;
5
 
6
class CheckRouteRole extends RouteListCommand
7
{
8
 
9
    /**
10
     * {@inheritdoc}
11
     */
12
    protected $name = 'permission:route:role';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected $description = 'Table of all routes that do not have a role';
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected $headers = ['method', 'uri', 'name', 'controller', 'action', 'middleware'];
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function getRouteInformation(Route $route)
28
    {
29
        $actions = explode('@',$route->getActionName());
30
        $middleware = implode(',',$route->middleware());
31
32
        if(!strpos($middleware, 'role')) {
33
            return $this->filterRoute([
34
                'method' => implode('|', $route->methods()),
35
                'uri'    => $route->uri(),
36
                'name'   => is_string($route->getName()) ? "<fg=green>{$route->getName()}</>" : "-",
37
                'controller' => isset($actions[0]) ? "<fg=cyan>{$actions[0]}</>" : "-",
38
                'action' => isset($actions[1]) ? "<fg=red>{$actions[1]}</>" : "-",
39
                'middleware' => $middleware
40
            ]);
41
        }
42
    }
43
}
44