Completed
Pull Request — master (#1)
by ARCANEDEV
23:03 queued 21:37
created

RouteViewer::getExcludedUris()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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
     * The router instance.
21
     *
22
     * @var  \Illuminate\Routing\Router
23
     */
24
    private $router;
25
26
    /**
27
     * The config repository.
28
     *
29
     * @var \Illuminate\Contracts\Config\Repository
30
     */
31
    private $config;
32
33
    /**
34
     * The route collection.
35
     *
36
     * @var \Arcanedev\RouteViewer\Entities\RouteCollection
37
     */
38
    protected $routes;
39
40
    /* ------------------------------------------------------------------------------------------------
41
     |  Constructor
42
     | ------------------------------------------------------------------------------------------------
43
     */
44
    /**
45
     * RouteViewer constructor.
46
     *
47
     * @param  \Illuminate\Contracts\Routing\Registrar  $router
48
     * @param  \Illuminate\Contracts\Config\Repository  $config
49
     */
50 27
    public function __construct(Router $router, Config $config)
51
    {
52 27
        $this->router = $router;
0 ignored issues
show
Documentation Bug introduced by
It seems like $router of type object<Illuminate\Contracts\Routing\Registrar> is incompatible with the declared type object<Illuminate\Routing\Router> of property $router.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

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