Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
21 | class Url extends StringLiteral |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $scheme; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $user; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $password; |
||
37 | |||
38 | /** |
||
39 | * @var Host |
||
40 | */ |
||
41 | protected $host; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $path; |
||
47 | |||
48 | /** |
||
49 | * @var Port |
||
50 | */ |
||
51 | protected $port; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $queryString; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $fragmentId; |
||
62 | |||
63 | /** |
||
64 | * @param string $url |
||
65 | * |
||
66 | * @throws \InvalidArgumentException |
||
67 | */ |
||
68 | public function __construct($url) |
||
85 | |||
86 | protected function createUrl() |
||
111 | |||
112 | /** |
||
113 | * @param string $url |
||
114 | * |
||
115 | * @throws \InvalidArgumentException |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | protected function parseScheme($url) |
||
131 | |||
132 | /** |
||
133 | * @param string $url |
||
134 | * |
||
135 | * @throws \InvalidArgumentException |
||
136 | * |
||
137 | * @return Host |
||
138 | */ |
||
139 | protected function parseHost($url) |
||
145 | |||
146 | /** |
||
147 | * @param string $url |
||
148 | * |
||
149 | * @throws \InvalidArgumentException |
||
150 | * |
||
151 | * @return Path | null |
||
152 | */ |
||
153 | protected function parsePath($url) |
||
166 | |||
167 | /** |
||
168 | * @param string $url |
||
169 | * |
||
170 | * @return Port | NULL |
||
171 | */ |
||
172 | protected function parsePort($url) |
||
181 | |||
182 | /** |
||
183 | * @param string $url |
||
184 | * |
||
185 | * @throws \InvalidArgumentException |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | protected function parseQueryString($url) |
||
200 | |||
201 | /** |
||
202 | * @param string $url |
||
203 | * |
||
204 | * @throws \InvalidArgumentException |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | protected function parseFragmentIdentifier($url) |
||
225 | |||
226 | /** |
||
227 | * @return Host |
||
228 | */ |
||
229 | public function host() |
||
233 | |||
234 | /** |
||
235 | * @return string |
||
236 | */ |
||
237 | public function fragmentId() |
||
241 | |||
242 | /** |
||
243 | * @return string |
||
244 | */ |
||
245 | public function password() |
||
249 | |||
250 | /** |
||
251 | * @return string |
||
252 | */ |
||
253 | public function path() |
||
257 | |||
258 | /** |
||
259 | * @return int |
||
260 | */ |
||
261 | public function port() |
||
265 | |||
266 | /** |
||
267 | * @return string |
||
268 | */ |
||
269 | public function queryString() |
||
273 | |||
274 | /** |
||
275 | * @return string |
||
276 | */ |
||
277 | public function scheme() |
||
281 | |||
282 | /** |
||
283 | * @return string |
||
284 | */ |
||
285 | public function user() |
||
289 | } |
||
290 |
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..