Completed
Pull Request — master (#546)
by Xander
03:35 queued 21s
created

CheckRouteRole::getRouteInformation()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 2
nop 1
dl 16
loc 16
rs 8.8571
c 0
b 0
f 0
1
<?php namespace Spatie\Permission\Commands;
2
 
3
use Illuminate\Routing\Route;
4
use Illuminate\Foundation\Console\RouteListCommand;
5
 
6 View Code Duplication
class CheckRouteRole extends RouteListCommand
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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