1 | <?php |
||
21 | class Host implements RuleInterface |
||
22 | { |
||
23 | /** |
||
24 | * |
||
25 | * Use this Route to build the regex. |
||
26 | * |
||
27 | * @var Route |
||
28 | * |
||
29 | */ |
||
30 | protected $route; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * The regular expression for the host. |
||
35 | * |
||
36 | * @var string |
||
37 | * |
||
38 | */ |
||
39 | protected $regex; |
||
40 | |||
41 | /** |
||
42 | * |
||
43 | * Checks that the Request host matches the Route host. |
||
44 | * |
||
45 | * @param ServerRequestInterface $request The HTTP request. |
||
46 | * |
||
47 | * @param Route $route The route. |
||
48 | * |
||
49 | * @return bool True on success, false on failure. |
||
50 | * |
||
51 | */ |
||
52 | 7 | public function __invoke(ServerRequestInterface $request, Route $route) |
|
71 | |||
72 | /** |
||
73 | * |
||
74 | * Gets the attributes out of the regex matches. |
||
75 | * |
||
76 | * @param array $matches The regex matches. |
||
77 | * |
||
78 | * @return array |
||
79 | * |
||
80 | */ |
||
81 | 2 | protected function getAttributes($matches) |
|
91 | |||
92 | /** |
||
93 | * |
||
94 | * Builds the regular expression for the route host. |
||
95 | * |
||
96 | * @param Route $route The Route. |
||
97 | * |
||
98 | * @return string |
||
99 | * |
||
100 | */ |
||
101 | 2 | protected function buildRegex(Route $route) |
|
109 | |||
110 | /** |
||
111 | * |
||
112 | * Expands attribute names in the regex to named subpatterns; adds default |
||
113 | * `null` values for attributes without defaults. |
||
114 | * |
||
115 | * @return null |
||
116 | * |
||
117 | */ |
||
118 | 2 | protected function setRegexAttributes() |
|
134 | |||
135 | /** |
||
136 | * |
||
137 | * Returns a named subpattern for a attribute name. |
||
138 | * |
||
139 | * @param string $name The attribute name. |
||
140 | * |
||
141 | * @return string The named subpattern. |
||
142 | * |
||
143 | */ |
||
144 | 1 | protected function getSubpattern($name) |
|
154 | } |
||
155 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.