Completed
Push — master ( 6b0e91...baa484 )
by ARCANEDEV
03:10
created

Manager::getMethodColors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 11
ccs 0
cts 11
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Arcanesoft\Foundation\Services\RoutesViewer;
2
3
use Illuminate\Contracts\Routing\Registrar as RouterContract;
4
5
/**
6
 * Class     Manager
7
 *
8
 * @package  Arcanesoft\Foundation\Services
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class Manager
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /** @var  \Illuminate\Routing\Router */
18
    protected $router;
19
20
    /* ------------------------------------------------------------------------------------------------
21
     |  Constructor
22
     | ------------------------------------------------------------------------------------------------
23
     */
24
    /**
25
     * Manager constructor.
26
     *
27
     * @param  \Illuminate\Contracts\Routing\Registrar  $router
28
     */
29
    public function __construct(RouterContract $router)
30
    {
31
        $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...
32
    }
33
34
    /* ------------------------------------------------------------------------------------------------
35
     |  Main Functions
36
     | ------------------------------------------------------------------------------------------------
37
     */
38
    public function all()
39
    {
40
        return Entities\RouteCollection::load(
41
            $this->router->getRoutes()->getRoutes(),
42
            $this->getExcludedUris(),
43
            $this->getExcludedMethods(),
44
            $this->getMethodColors()
45
        );
46
    }
47
48
    public function getExcludedUris()
49
    {
50
        return $this->getConfig('uris.excluded', []);
51
    }
52
53
    public function getExcludedMethods()
54
    {
55
        return $this->getConfig('methods.excluded', ['HEAD']);
56
    }
57
58
    private function getMethodColors()
59
    {
60
        return $this->getConfig('methods.colors', [
61
            'GET'    => 'success',
62
            'HEAD'   => 'default',
63
            'POST'   => 'primary',
64
            'PUT'    => 'warning',
65
            'PATCH'  => 'info',
66
            'DELETE' => 'danger',
67
        ]);
68
    }
69
70
    /* ------------------------------------------------------------------------------------------------
71
     |  Other Functions
72
     | ------------------------------------------------------------------------------------------------
73
     */
74
    public function getConfig($key, $default = null)
75
    {
76
        return config("arcanesoft.foundation.routes-viewer.{$key}", $default);
77
    }
78
}
79