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 |
||
25 | trait EquatableAssertionCapabilities |
||
26 | { |
||
27 | /** |
||
28 | * @param mixed $expected |
||
29 | * @param mixed $actual |
||
30 | * @param string $message |
||
31 | * @param float $delta |
||
32 | * @param int $maxDepth |
||
33 | * @param bool $canonicalize |
||
34 | * @param bool $ignoreCase |
||
35 | */ |
||
36 | public static function assertEquals( |
||
49 | |||
50 | /** |
||
51 | * @param mixed $expected |
||
52 | * @param mixed $actual |
||
53 | * @param string $message |
||
54 | * @param float $delta |
||
55 | * @param int $maxDepth |
||
56 | * @param bool $canonicalize |
||
57 | * @param bool $ignoreCase |
||
58 | */ |
||
59 | public static function assertNotEquals( |
||
74 | |||
75 | /** |
||
76 | * @param mixed $needle |
||
77 | * @param mixed $haystack |
||
78 | * @param string $message |
||
79 | * @param bool $ignoreCase |
||
80 | * @param bool $checkForObjectIdentity |
||
81 | * @param bool $checkForNonObjectIdentity |
||
82 | */ |
||
83 | View Code Duplication | public static function assertContains( |
|
105 | |||
106 | /** |
||
107 | * @param mixed $needle |
||
108 | * @param mixed $haystack |
||
109 | * @param string $message |
||
110 | * @param bool $ignoreCase |
||
111 | * @param bool $checkForObjectIdentity |
||
112 | * @param bool $checkForNonObjectIdentity |
||
113 | */ |
||
114 | View Code Duplication | public static function assertNotContains( |
|
140 | |||
141 | /** |
||
142 | * @param mixed $value |
||
143 | * @param float $delta |
||
144 | * @param int $maxDepth |
||
145 | * @param bool $canonicalize |
||
146 | * @param bool $ignoreCase |
||
147 | * |
||
148 | * @return PHPUnitIsEqual |
||
149 | */ |
||
150 | public static function equalTo( |
||
165 | |||
166 | /** |
||
167 | * @param string $attributeName |
||
168 | * @param mixed $value |
||
169 | * @param float $delta |
||
170 | * @param int $maxDepth |
||
171 | * @param bool $canonicalize |
||
172 | * @param bool $ignoreCase |
||
173 | * |
||
174 | * @return Attribute |
||
175 | */ |
||
176 | public static function attributeEqualTo( |
||
189 | |||
190 | /** |
||
191 | * @param mixed $value |
||
192 | * @param bool $checkForObjectIdentity |
||
193 | * @param bool $checkForNonObjectIdentity |
||
194 | * |
||
195 | * @return PHPUnitTraversableContains |
||
196 | */ |
||
197 | public static function contains( |
||
204 | } |
||
205 |
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.