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 |
||
14 | final class RedisCacheTest extends \PHPUnit\Framework\TestCase |
||
15 | { |
||
16 | /** |
||
17 | * @var Client |
||
18 | */ |
||
19 | private $predis; |
||
20 | |||
21 | /** |
||
22 | * @var RedisCache |
||
23 | */ |
||
24 | private $cache; |
||
25 | |||
26 | /** |
||
27 | * @return void |
||
28 | */ |
||
29 | public function setUp() |
||
35 | |||
36 | /** |
||
37 | * @test |
||
38 | * @covers ::get |
||
39 | * |
||
40 | * @return void |
||
41 | */ |
||
42 | public function get() |
||
48 | |||
49 | /** |
||
50 | * @test |
||
51 | * @covers ::get |
||
52 | * |
||
53 | * @return void |
||
54 | */ |
||
55 | public function getKeyNotFound() |
||
60 | |||
61 | /** |
||
62 | * @test |
||
63 | * @covers ::getMultiple |
||
64 | * |
||
65 | * @return void |
||
66 | */ |
||
67 | public function getMultple() |
||
79 | |||
80 | /** |
||
81 | * @test |
||
82 | * @covers ::set |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | public function set() |
||
95 | |||
96 | /** |
||
97 | * @test |
||
98 | * @covers ::set |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | public function setFails() |
||
109 | |||
110 | /** |
||
111 | * @test |
||
112 | * @covers ::setMultiple |
||
113 | * |
||
114 | * @return void |
||
115 | */ |
||
116 | public function setMultple() |
||
124 | |||
125 | /** |
||
126 | * @test |
||
127 | * @covers ::setMultiple |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | public function setMultpleFails() |
||
150 | |||
151 | /** |
||
152 | * @test |
||
153 | * @covers ::delete |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | public function delete() |
||
164 | |||
165 | /** |
||
166 | * @test |
||
167 | * @covers ::deleteMultiple |
||
168 | * |
||
169 | * @return void |
||
170 | */ |
||
171 | View Code Duplication | public function deleteMultiple() |
|
182 | |||
183 | /** |
||
184 | * @test |
||
185 | * @covers ::clear |
||
186 | * |
||
187 | * @return void |
||
188 | */ |
||
189 | View Code Duplication | public function clear() |
|
200 | |||
201 | /** |
||
202 | * @test |
||
203 | * @covers ::has |
||
204 | * |
||
205 | * @return void |
||
206 | */ |
||
207 | public function has() |
||
213 | } |
||
214 |
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: