Completed
Pull Request — master (#5)
by ARCANEDEV
05:39
created

RouteViewer::getExcludedMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\RouteViewer;
2
3
use Arcanedev\RouteViewer\Contracts\RouteViewer as RouteViewerContract;
4
use Illuminate\Contracts\Config\Repository as Config;
5
use Illuminate\Contracts\Routing\Registrar as Router;
6
7
/**
8
 * Class     RouteViewer
9
 *
10
 * @package  Arcanedev\RouteViewer
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class RouteViewer implements RouteViewerContract
14
{
15
    /* -----------------------------------------------------------------
16
     |  Properties
17
     | -----------------------------------------------------------------
18
     */
19
20
    /**
21
     * The router instance.
22
     *
23
     * @var  \Illuminate\Routing\Router
24
     */
25
    private $router;
26
27
    /**
28
     * The config repository.
29
     *
30
     * @var \Illuminate\Contracts\Config\Repository
31
     */
32
    private $config;
33
34
    /**
35
     * The route collection.
36
     *
37
     * @var \Arcanedev\RouteViewer\Entities\RouteCollection
38
     */
39
    protected $routes;
40
41
    /* -----------------------------------------------------------------
42
     |  Constructor
43
     | -----------------------------------------------------------------
44
     */
45
46
    /**
47
     * RouteViewer constructor.
48
     *
49
     * @param  \Illuminate\Contracts\Routing\Registrar  $router
50
     * @param  \Illuminate\Contracts\Config\Repository  $config
51
     */
52
    public function __construct(Router $router, Config $config)
53
    {
54
        $this->router = $router;
0 ignored issues
show
Documentation Bug introduced by
$router is of type object<Illuminate\Contracts\Routing\Registrar>, but the property $router was declared to be of type object<Illuminate\Routing\Router>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
55
        $this->config = $config;
56
    }
57
58
    /* -----------------------------------------------------------------
59
     |  Main Methods
60
     | -----------------------------------------------------------------
61
     */
62
63
    /**
64
     * Get all routes.
65
     *
66
     * @return \Arcanedev\RouteViewer\Entities\RouteCollection
67
     */
68
    public function all()
69
    {
70
        if (is_null($this->routes)) {
71
            $this->routes = Entities\RouteCollection::load(
72
                $this->router->getRoutes()->getRoutes(),
73
                $this->getExcludedUris(),
74
                $this->getExcludedMethods(),
75
                $this->getMethodColors()
76
            );
77
        }
78
79
        return $this->routes;
80
    }
81
82
    /**
83
     * Get the excluded URIs.
84
     *
85
     * @return array
86
     */
87
    public function getExcludedUris()
88
    {
89
        return $this->getConfig('uris.excluded', []);
90
    }
91
92
    /**
93
     * Get the excluded methods.
94
     *
95
     * @return array
96
     */
97
    public function getExcludedMethods()
98
    {
99
        return $this->getConfig('methods.excluded', ['HEAD']);
100
    }
101
102
    /**
103
     * Get method colors.
104
     *
105
     * @return array
106
     */
107
    private function getMethodColors()
108
    {
109
        return $this->getConfig('methods.colors', [
110
            'GET'    => 'success',
111
            'HEAD'   => 'default',
112
            'POST'   => 'primary',
113
            'PUT'    => 'warning',
114
            'PATCH'  => 'info',
115
            'DELETE' => 'danger',
116
        ]);
117
    }
118
119
    /* -----------------------------------------------------------------
120
     |  Other Methods
121
     | -----------------------------------------------------------------
122
     */
123
124
    /**
125
     * Get a config value.
126
     *
127
     * @param  string      $key
128
     * @param  mixed|null  $default
129
     *
130
     * @return mixed
131
     */
132
    private function getConfig($key, $default = null)
133
    {
134
        return $this->config->get("route-viewer.{$key}", $default);
135
    }
136
}
137