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 |
||
13 | class SectionLoader extends AbstractLoader |
||
14 | { |
||
15 | /** |
||
16 | * @var array $sectionRoutes The section's routes. |
||
17 | */ |
||
18 | protected $sectionRoutes; |
||
19 | |||
20 | /** |
||
21 | * @var integer $baseSection The id of the base section. |
||
22 | */ |
||
23 | protected $baseSection; |
||
24 | |||
25 | /** |
||
26 | * The cache of snake-cased words. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected static $snakeCache = []; |
||
31 | |||
32 | /** |
||
33 | * @param integer $id The section's id. |
||
34 | * @return mixed |
||
35 | */ |
||
36 | public function fromId($id) |
||
42 | |||
43 | /** |
||
44 | * @param string $slug The section's slug. |
||
45 | * @return mixed |
||
46 | */ |
||
47 | public function fromSlug($slug) |
||
52 | |||
53 | /** |
||
54 | * @return CollectionLoader |
||
55 | */ |
||
56 | View Code Duplication | public function all() |
|
66 | |||
67 | /** |
||
68 | * @return \ArrayAccess|\Traversable |
||
69 | */ |
||
70 | public function masters() |
||
81 | |||
82 | /** |
||
83 | * @return \ArrayAccess|\Traversable |
||
84 | */ |
||
85 | public function children() |
||
113 | |||
114 | /** |
||
115 | * Pair routes slug to sections ID |
||
116 | * @return array |
||
117 | */ |
||
118 | public function sectionRoutes() |
||
175 | |||
176 | /** |
||
177 | * Resolve latest route from route slug. |
||
178 | * @param string $route The route to resolve. |
||
179 | * @return string |
||
180 | */ |
||
181 | View Code Duplication | public function resolveRoute($route) |
|
192 | |||
193 | /** |
||
194 | * Resolve section ID from route slug. |
||
195 | * @param string $route The route to resolve. |
||
196 | * @return integer |
||
197 | */ |
||
198 | View Code Duplication | public function resolveSectionId($route) |
|
210 | |||
211 | // ========================================================================== |
||
212 | // GETTERS |
||
213 | // ========================================================================== |
||
214 | |||
215 | /** |
||
216 | * @return object |
||
217 | */ |
||
218 | public function objType() |
||
222 | |||
223 | /** |
||
224 | * @return integer |
||
225 | */ |
||
226 | public function baseSection() |
||
230 | |||
231 | /** |
||
232 | * @return array |
||
233 | */ |
||
234 | public function sectionTypes() |
||
238 | |||
239 | // ========================================================================== |
||
240 | // SETTERS |
||
241 | // ========================================================================== |
||
242 | |||
243 | /** |
||
244 | * @param object $objType The object type. |
||
245 | * @return self |
||
246 | */ |
||
247 | public function setObjType($objType) |
||
253 | |||
254 | /** |
||
255 | * @param integer $baseSection The base section id. |
||
256 | * @return self |
||
257 | */ |
||
258 | public function setBaseSection($baseSection) |
||
264 | |||
265 | /** |
||
266 | * @param array $sectionTypes Section types array | null. |
||
267 | * @return self |
||
268 | */ |
||
269 | public function setSectionTypes($sectionTypes) |
||
275 | |||
276 | // ========================================================================== |
||
277 | // UTILS |
||
278 | // ========================================================================== |
||
279 | |||
280 | /** |
||
281 | * Convert a string to snake case. |
||
282 | * |
||
283 | * @param string $value The value to convert. |
||
284 | * @param string $delimiter The word delimiter. |
||
285 | * @return string |
||
286 | */ |
||
287 | public static function snake($value, $delimiter = '-') |
||
301 | } |
||
302 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: