1 | <?php |
||
8 | final class QueryString |
||
9 | { |
||
10 | /** |
||
11 | * @var array |
||
12 | */ |
||
13 | private $params = []; |
||
14 | |||
15 | /** |
||
16 | * @var QueryStringRendererInterface |
||
17 | */ |
||
18 | private $renderer; |
||
19 | |||
20 | /** |
||
21 | * QueryString constructor. |
||
22 | * @param array|null $params |
||
23 | * @param QueryStringRendererInterface|null $renderer |
||
24 | * @throws \InvalidArgumentException |
||
25 | */ |
||
26 | protected function __construct(?array $params = [], QueryStringRendererInterface $renderer = null) |
||
34 | |||
35 | /** |
||
36 | * @param array $params |
||
37 | * @param QueryStringRendererInterface|null $renderer |
||
38 | * @return QueryString |
||
39 | */ |
||
40 | private static function createFromParams(array $params, QueryStringRendererInterface $renderer = null): self |
||
44 | |||
45 | /** |
||
46 | * @param \Psr\Http\Message\UriInterface $uri |
||
47 | * @param QueryStringRendererInterface|null $renderer |
||
48 | * @return QueryString |
||
49 | * @throws \TypeError |
||
50 | */ |
||
51 | private static function createFromUri($uri, QueryStringRendererInterface $renderer = null): self |
||
67 | |||
68 | /** |
||
69 | * @param string $qs |
||
70 | * @param QueryStringRendererInterface|null $renderer |
||
71 | * @return QueryString |
||
72 | */ |
||
73 | private static function createFromString(string $qs, QueryStringRendererInterface $renderer = null): self |
||
79 | |||
80 | /** |
||
81 | * @param QueryStringRendererInterface|null $renderer |
||
82 | * @return QueryString |
||
83 | * @throws \RuntimeException |
||
84 | */ |
||
85 | public static function createFromCurrentLocation(QueryStringRendererInterface $renderer = null): self |
||
92 | |||
93 | /** |
||
94 | * @return QueryString |
||
95 | * @throws \RuntimeException |
||
96 | */ |
||
97 | public function withCurrentLocation(): self |
||
101 | |||
102 | /** |
||
103 | * @param $input |
||
104 | * @return QueryString |
||
105 | * @throws \InvalidArgumentException |
||
106 | */ |
||
107 | public static function factory($input = null, QueryStringRendererInterface $renderer = null): self |
||
120 | |||
121 | /** |
||
122 | * @return array |
||
123 | */ |
||
124 | public function getParams(): ?array |
||
128 | |||
129 | /** |
||
130 | * @param string $key |
||
131 | * @param array ...$deepKeys |
||
132 | * @return mixed|null |
||
133 | */ |
||
134 | public function getParam(string $key, ...$deepKeys) |
||
145 | |||
146 | /** |
||
147 | * @param string $key |
||
148 | * @return bool |
||
149 | */ |
||
150 | public function hasParam(string $key, ...$deepKeys): bool |
||
154 | |||
155 | /** |
||
156 | * @param string $key |
||
157 | * @param $value |
||
158 | * @return QueryString |
||
159 | */ |
||
160 | public function withParam(string $key, $value): self |
||
166 | |||
167 | /** |
||
168 | * @param array $params |
||
169 | * @return QueryString |
||
170 | */ |
||
171 | public function withParams(array $params): self |
||
180 | |||
181 | /** |
||
182 | * @param string $key |
||
183 | * @param array ...$deepKeys |
||
184 | * @return QueryString |
||
185 | */ |
||
186 | public function withoutParam(string $key, ...$deepKeys): self |
||
205 | |||
206 | /** |
||
207 | * @return QueryStringRendererInterface |
||
208 | */ |
||
209 | public function getRenderer(): QueryStringRendererInterface |
||
213 | |||
214 | /** |
||
215 | * @param QueryStringRendererInterface $renderer |
||
216 | * @return QueryString |
||
217 | */ |
||
218 | public function withRenderer(QueryStringRendererInterface $renderer): self |
||
224 | |||
225 | /** |
||
226 | * @return string |
||
227 | */ |
||
228 | public function __toString(): string |
||
232 | |||
233 | /** |
||
234 | * @param array $array |
||
235 | * @return bool |
||
236 | */ |
||
237 | private function isAnIndexedArray(array $array): bool |
||
242 | |||
243 | /** |
||
244 | * @param array $params |
||
245 | * @param array ...$keys |
||
246 | * @return array |
||
247 | */ |
||
248 | private function removeFromPath(array $params, ...$keys): array |
||
272 | } |
||
273 |
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 mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.