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 declare(strict_types=1); |
||
23 | abstract class AbstractObjectMapInterfaceTest extends TestCase |
||
24 | { |
||
25 | /** |
||
26 | * @param int $behavior |
||
27 | * |
||
28 | * @return ObjectMapInterface | ObjectBiMapInterface |
||
29 | */ |
||
30 | abstract public function buildMap(int $behavior = ObjectMapInterface::DEFAULT); |
||
31 | |||
32 | View Code Duplication | public function testMap() |
|
49 | |||
50 | View Code Duplication | public function testWeakKeyMap() |
|
67 | |||
68 | View Code Duplication | public function testWeakValueMap() |
|
85 | |||
86 | public function testWeakKeyValueMap() |
||
111 | |||
112 | View Code Duplication | public function testPutAndGet() |
|
122 | |||
123 | /** |
||
124 | * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException |
||
125 | * @expectedExceptionMessage Key is not an object |
||
126 | */ |
||
127 | public function testPutKeyNotAnObjectFails() |
||
133 | |||
134 | /** |
||
135 | * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException |
||
136 | * @expectedExceptionMessage Value is not an object |
||
137 | */ |
||
138 | public function testPutValueNotAnObjectFails() |
||
144 | |||
145 | /** |
||
146 | * @expectedException \Pinepain\ObjectMaps\Exceptions\OverflowException |
||
147 | * @expectedExceptionMessage Value with such key already exists |
||
148 | */ |
||
149 | View Code Duplication | public function testPutExistentKeyFails() |
|
159 | |||
160 | /** |
||
161 | * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException |
||
162 | * @expectedExceptionMessage Key is not an object |
||
163 | */ |
||
164 | public function testGetByNonObjectFails() |
||
170 | |||
171 | /** |
||
172 | * @expectedException \Pinepain\ObjectMaps\Exceptions\OutOfBoundsException |
||
173 | * @expectedExceptionMessage Value with such key not found |
||
174 | */ |
||
175 | public function testGetNonexistentKeyFails() |
||
181 | |||
182 | /** |
||
183 | * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException |
||
184 | * @expectedExceptionMessage Key is not an object |
||
185 | */ |
||
186 | public function testHasByNonObjectFails() |
||
192 | |||
193 | public function testHasNonexistentKey() |
||
199 | |||
200 | public function testHasExistentKey() |
||
209 | |||
210 | /** |
||
211 | * @expectedException \Pinepain\ObjectMaps\Exceptions\UnexpectedValueException |
||
212 | * @expectedExceptionMessage Key is not an object |
||
213 | */ |
||
214 | public function testRemoveByNonObjectFails() |
||
220 | |||
221 | /** |
||
222 | * @expectedException \Pinepain\ObjectMaps\Exceptions\OutOfBoundsException |
||
223 | * @expectedExceptionMessage Value with such key not found |
||
224 | */ |
||
225 | public function testRemoveNonexistentKeyFails() |
||
231 | |||
232 | public function testRemove() |
||
245 | |||
246 | public function testCount() |
||
261 | |||
262 | public function testClear() |
||
277 | } |
||
278 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.