1 | <?php |
||
8 | class UrlParser implements Parser |
||
9 | { |
||
10 | /** |
||
11 | * @var Locale |
||
12 | */ |
||
13 | private $locale; |
||
14 | |||
15 | /** |
||
16 | * If locale is explicitly passed, we will set it |
||
17 | * If null is passed it means the default locale must be used. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | private $localeslug = false; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private $parsed; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $secure = false; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | private $parameters = []; |
||
37 | |||
38 | /** |
||
39 | * Internal flag to keep track of schemeless url. |
||
40 | * |
||
41 | * @var bool |
||
42 | */ |
||
43 | private $schemeless = false; |
||
44 | |||
45 | /** |
||
46 | * @var UrlGenerator |
||
47 | */ |
||
48 | private $generator; |
||
49 | |||
50 | 50 | public function __construct(Locale $locale, UrlGenerator $generator) |
|
55 | |||
56 | /** |
||
57 | * Set the original url/uri. |
||
58 | * |
||
59 | * @param $url |
||
60 | * |
||
61 | * @return $this |
||
62 | * @throws \InvalidArgumentException |
||
63 | */ |
||
64 | 47 | public function set($url) |
|
78 | |||
79 | /** |
||
80 | * Get the localized url. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 47 | public function get() |
|
103 | |||
104 | /** |
||
105 | * Resolve the route via the Illuminate UrlGenerator. |
||
106 | * |
||
107 | * @param $routekey |
||
108 | * @param array $parameters |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 27 | public function resolveRoute($routekey, $parameters = []) |
|
116 | |||
117 | /** |
||
118 | * Place locale segment in front of url path |
||
119 | * e.g. /foo/bar is transformed into /en/foo/bar. |
||
120 | * |
||
121 | * @param null $localeslug |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | 45 | public function localize($localeslug = null) |
|
131 | |||
132 | /** |
||
133 | * @param array $parameters |
||
134 | * |
||
135 | * @return $this |
||
136 | */ |
||
137 | 11 | public function parameters(array $parameters = []) |
|
143 | |||
144 | /** |
||
145 | * @param bool $secure |
||
146 | * |
||
147 | * @return $this |
||
148 | */ |
||
149 | 13 | public function secure($secure = true) |
|
155 | |||
156 | /** |
||
157 | * Inject the locale slug in the uri. |
||
158 | * |
||
159 | * @param null $locale |
||
160 | */ |
||
161 | 43 | private function localizePath($locale = null) |
|
167 | |||
168 | /** |
||
169 | * @return array |
||
170 | */ |
||
171 | 43 | private function delocalizePath() |
|
189 | |||
190 | /** |
||
191 | * Construct a full url with the parsed url elements |
||
192 | * resulted from a parse_url() function call. |
||
193 | * |
||
194 | * @param array $parsed |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | 46 | private function reassemble(array $parsed) |
|
211 | |||
212 | 47 | private function assertUrlExists() |
|
218 | } |
||
219 |
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.