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 |
||
10 | final class ArraysTest extends TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @test |
||
14 | * @covers ::filter |
||
15 | */ |
||
16 | public function filterBasicPass() |
||
20 | |||
21 | /** |
||
22 | * @test |
||
23 | * @covers ::filter |
||
24 | * @expectedException \TraderInteractive\Filter\Exception |
||
25 | * @expectedExceptionMessage Value '1' is not an array |
||
26 | */ |
||
27 | public function filterFailNotArray() |
||
31 | |||
32 | /** |
||
33 | * @test |
||
34 | * @covers ::filter |
||
35 | * @expectedException \TraderInteractive\Filter\Exception |
||
36 | * @expectedExceptionMessage $value count of 0 is less than 1 |
||
37 | */ |
||
38 | public function filterFailEmpty() |
||
42 | |||
43 | /** |
||
44 | * @test |
||
45 | * @covers ::filter |
||
46 | * @expectedException \TraderInteractive\Filter\Exception |
||
47 | * @expectedExceptionMessage $value count of 1 is less than 2 |
||
48 | */ |
||
49 | public function filterCountLessThanMin() |
||
53 | |||
54 | /** |
||
55 | * @test |
||
56 | * @covers ::filter |
||
57 | * @expectedException \TraderInteractive\Filter\Exception |
||
58 | * @expectedExceptionMessage $value count of 2 is greater than 1 |
||
59 | */ |
||
60 | public function filterCountGreaterThanMax() |
||
64 | |||
65 | /** |
||
66 | * @test |
||
67 | * @covers ::filter |
||
68 | * @expectedException \InvalidArgumentException |
||
69 | * @expectedExceptionMessage $minCount was not an int |
||
70 | */ |
||
71 | public function filterMinCountNotInt() |
||
75 | |||
76 | /** |
||
77 | * @test |
||
78 | * @covers ::filter |
||
79 | * @expectedException \InvalidArgumentException |
||
80 | * @expectedExceptionMessage $maxCount was not an int |
||
81 | */ |
||
82 | public function filterMaxCountNotInt() |
||
86 | |||
87 | /** |
||
88 | * @test |
||
89 | * @covers ::in |
||
90 | */ |
||
91 | public function inPassStrict() |
||
95 | |||
96 | /** |
||
97 | * @test |
||
98 | * @covers ::in |
||
99 | */ |
||
100 | View Code Duplication | public function inFailStrict() |
|
109 | |||
110 | /** |
||
111 | * @test |
||
112 | * @covers ::in |
||
113 | */ |
||
114 | View Code Duplication | public function inFailNotStrict() |
|
123 | |||
124 | /** |
||
125 | * @test |
||
126 | * @covers ::in |
||
127 | */ |
||
128 | public function inPassNotStrict() |
||
132 | |||
133 | /** |
||
134 | * @test |
||
135 | * @covers ::in |
||
136 | * @expectedException \InvalidArgumentException |
||
137 | * @expectedExceptionMessage $strict was not a bool |
||
138 | */ |
||
139 | public function inStrictNotBool() |
||
143 | |||
144 | /** |
||
145 | * @test |
||
146 | * @covers ::ofScalars |
||
147 | */ |
||
148 | public function ofScalars() |
||
152 | |||
153 | /** |
||
154 | * @test |
||
155 | * @covers ::ofScalars |
||
156 | */ |
||
157 | public function ofScalarsChained() |
||
161 | |||
162 | /** |
||
163 | * @test |
||
164 | * @covers ::ofScalars |
||
165 | */ |
||
166 | public function ofScalarsWithMeaninglessKeys() |
||
170 | |||
171 | /** |
||
172 | * @test |
||
173 | * @covers ::ofScalars |
||
174 | */ |
||
175 | View Code Duplication | public function ofScalarsFail() |
|
192 | |||
193 | /** |
||
194 | * @test |
||
195 | * @covers ::ofArrays |
||
196 | */ |
||
197 | public function ofArrays() |
||
202 | |||
203 | /** |
||
204 | * @test |
||
205 | * @covers ::ofArrays |
||
206 | */ |
||
207 | public function ofArraysChained() |
||
213 | |||
214 | /** |
||
215 | * @test |
||
216 | * @covers ::ofArrays |
||
217 | */ |
||
218 | View Code Duplication | public function ofArraysRequiredAndUnknown() |
|
228 | |||
229 | /** |
||
230 | * @test |
||
231 | * @covers ::ofArrays |
||
232 | */ |
||
233 | public function ofArraysFail() |
||
255 | |||
256 | /** |
||
257 | * @test |
||
258 | * @covers ::ofArray |
||
259 | */ |
||
260 | public function ofArray() |
||
266 | |||
267 | /** |
||
268 | * @test |
||
269 | * @covers ::ofArray |
||
270 | */ |
||
271 | public function ofArrayChained() |
||
277 | |||
278 | /** |
||
279 | * @test |
||
280 | * @covers ::ofArray |
||
281 | */ |
||
282 | public function ofArrayRequiredSuccess() |
||
288 | |||
289 | /** |
||
290 | * @test |
||
291 | * @covers ::ofArray |
||
292 | */ |
||
293 | View Code Duplication | public function ofArrayRequiredFail() |
|
303 | |||
304 | /** |
||
305 | * @test |
||
306 | * @covers ::ofArray |
||
307 | */ |
||
308 | View Code Duplication | public function ofArrayUnknown() |
|
318 | |||
319 | /** |
||
320 | * Verifies the basic behavior of the flatten filter. |
||
321 | * |
||
322 | * @test |
||
323 | * @covers ::flatten |
||
324 | */ |
||
325 | public function flatten() |
||
329 | } |
||
330 |
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: