Passed
Push — develop ( f6f117...adc6ed )
by Florian
02:08
created

RouteInfo   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 123
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A __construct() 0 5 1
A getHandler() 0 4 1
A get() 0 8 2
A offsetExists() 0 4 1
A offsetGet() 0 8 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Burzum\FastRouteMiddleware;
5
6
/**
7
 * Route Info Object
8
 */
9
class RouteInfo implements RouteInfoInterface
10
{
11
    /**
12
     * Route Handler
13
     *
14
     * @var mixed
15
     */
16
    protected $handler;
17
18
    /**
19
     * Route vars
20
     *
21
     * @var array
22
     */
23
    protected $vars;
24
25
    /**
26
     * Constructor
27
     *
28
     * @param mixed $handler
29
     * @param mixed $vars
30
     */
31 2
    public function __construct($handler, $vars)
32
    {
33 2
        $this->handler = $handler;
34 2
        $this->vars = $vars;
0 ignored issues
show
Documentation Bug introduced by
It seems like $vars of type * is incompatible with the declared type array of property $vars.

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...
35 2
    }
36
37
    /**
38
     * Gets the handler of the route
39
     *
40
     * @return mixed
41
     */
42 1
    public function getHandler(): string
43
    {
44 1
        return $this->handler;
45
    }
46
47
    /**
48
     * Returns a route var
49
     *
50
     * @param string $name
51
     * @return null|string
52
     */
53 1
    public function get($name): ?string
54
    {
55 1
        if (isset($this->vars[$name])) {
56 1
            return $this->vars[$name];
57
        }
58
59 1
        return null;
60
    }
61
62
    /**
63
     * Whether a offset exists
64
     *
65
     * @link https://php.net/manual/en/arrayaccess.offsetexists.php
66
     * @param mixed $offset <p>
67
     * An offset to check for.
68
     * </p>
69
     * @return boolean true on success or false on failure.
70
     * </p>
71
     * <p>
72
     * The return value will be casted to boolean if non-boolean was returned.
73
     * @since 5.0.0
74
     */
75 1
    public function offsetExists($offset)
76
    {
77 1
        return isset($this->vars[$offset]);
78
    }
79
80
    /**
81
     * Offset to retrieve
82
     *
83
     * @link https://php.net/manual/en/arrayaccess.offsetget.php
84
     * @param mixed $offset <p>
85
     * The offset to retrieve.
86
     * </p>
87
     * @return mixed Can return all value types.
88
     * @since 5.0.0
89
     */
90 1
    public function offsetGet($offset)
91
    {
92 1
        if ($this->offsetExists($offset)) {
93 1
            return $this->vars[$offset];
94
        }
95
96
        return null;
97
    }
98
99
    /**
100
     * Offset to set
101
     *
102
     * @link https://php.net/manual/en/arrayaccess.offsetset.php
103
     * @param mixed $offset <p>
104
     * The offset to assign the value to.
105
     * </p>
106
     * @param mixed $value <p>
107
     * The value to set.
108
     * </p>
109
     * @return void
110
     * @since 5.0.0
111
     */
112
    public function offsetSet($offset, $value)
113
    {
114
        throw new \RuntimeException();
115
    }
116
117
    /**
118
     * Offset to unset
119
     *
120
     * @link https://php.net/manual/en/arrayaccess.offsetunset.php
121
     * @param mixed $offset <p>
122
     * The offset to unset.
123
     * </p>
124
     * @return void
125
     * @since 5.0.0
126
     */
127
    public function offsetUnset($offset)
128
    {
129
        throw new \RuntimeException();
130
    }
131
}