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 |
||
29 | class ArrayLoader implements LoaderInterface |
||
30 | { |
||
31 | /** |
||
32 | * Checks if current loader supports provided resource. |
||
33 | * |
||
34 | * @param mixed $resource Resource to load |
||
35 | * |
||
36 | * @return Boolean |
||
37 | */ |
||
38 | 1 | public function supports($resource) |
|
42 | |||
43 | /** |
||
44 | * Loads features from provided resource. |
||
45 | * |
||
46 | * @param mixed $resource Resource to load |
||
47 | * |
||
48 | * @return FeatureNode[] |
||
49 | */ |
||
50 | 45 | public function load($resource) |
|
66 | |||
67 | /** |
||
68 | * Loads feature from provided feature hash. |
||
69 | * |
||
70 | * @param array $hash Feature hash |
||
71 | * @param integer $line |
||
72 | * |
||
73 | * @return FeatureNode |
||
74 | */ |
||
75 | 44 | protected function loadFeatureHash(array $hash, $line = 0) |
|
119 | |||
120 | /** |
||
121 | * Loads background from provided hash. |
||
122 | * |
||
123 | * @param array $hash Background hash |
||
124 | * |
||
125 | * @return BackgroundNode |
||
126 | */ |
||
127 | 10 | protected function loadBackgroundHash(array $hash) |
|
143 | |||
144 | /** |
||
145 | * Loads rule from provided hash. |
||
146 | * |
||
147 | * @param array $hash Background hash |
||
148 | * @param integer $line Background definition line |
||
149 | * |
||
150 | * @return RuleNode |
||
151 | */ |
||
152 | 2 | protected function loadRuleHash(array $hash, $line = 0) |
|
177 | |||
178 | /** |
||
179 | * Loads example from provided examplehash. |
||
180 | * |
||
181 | * @param array $hash Example hash |
||
182 | * @param integer $line Example definition line |
||
183 | * |
||
184 | * @return ExampleNode |
||
185 | */ |
||
186 | 2 | View Code Duplication | protected function loadExampleHash(array $hash, $line = 0) |
203 | |||
204 | /** |
||
205 | * Loads scenario from provided scenario hash. |
||
206 | * |
||
207 | * @param array $hash Scenario hash |
||
208 | * @param integer $line Scenario definition line |
||
209 | * |
||
210 | * @return ScenarioNode |
||
211 | */ |
||
212 | 28 | View Code Duplication | protected function loadScenarioHash(array $hash, $line = 0) |
229 | |||
230 | /** |
||
231 | * Loads outline from provided outline hash. |
||
232 | * |
||
233 | * @param array $hash Outline hash |
||
234 | * @param integer $line Outline definition line |
||
235 | * |
||
236 | * @return OutlineNode |
||
237 | */ |
||
238 | 12 | protected function loadOutlineHash(array $hash, $line = 0) |
|
265 | |||
266 | /** |
||
267 | * Loads steps from provided hash. |
||
268 | * |
||
269 | * @param array $hash |
||
270 | * |
||
271 | * @return StepNode[] |
||
272 | */ |
||
273 | 39 | private function loadStepsHash(array $hash) |
|
282 | |||
283 | /** |
||
284 | * Loads step from provided hash. |
||
285 | * |
||
286 | * @param array $hash Step hash |
||
287 | * @param integer $line Step definition line |
||
288 | * |
||
289 | * @return StepNode |
||
290 | */ |
||
291 | 32 | protected function loadStepHash(array $hash, $line = 0) |
|
316 | |||
317 | /** |
||
318 | * Loads table from provided hash. |
||
319 | * |
||
320 | * @param array $hash Table hash |
||
321 | * |
||
322 | * @return TableNode |
||
323 | */ |
||
324 | 4 | protected function loadTableHash(array $hash) |
|
328 | |||
329 | /** |
||
330 | * Loads PyString from provided hash. |
||
331 | * |
||
332 | * @param array $hash PyString hash |
||
333 | * @param integer $line |
||
334 | * |
||
335 | * @return PyStringNode |
||
336 | */ |
||
337 | 7 | protected function loadPyStringHash(array $hash, $line = 0) |
|
348 | } |
||
349 |
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: