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 |
||
15 | class EnumMapench |
||
16 | { |
||
17 | /** |
||
18 | * @var mixed[] |
||
19 | */ |
||
20 | private $values; |
||
21 | |||
22 | /** |
||
23 | * @var Enum66[] |
||
24 | */ |
||
25 | private $enumerators; |
||
26 | |||
27 | /** |
||
28 | * @var EnumMap |
||
29 | */ |
||
30 | private $emptyMap; |
||
31 | |||
32 | /** |
||
33 | * @var EnumMap |
||
34 | */ |
||
35 | private $fullMap; |
||
36 | |||
37 | /** |
||
38 | * Will be called before every subject |
||
39 | */ |
||
40 | View Code Duplication | public function init() |
|
51 | |||
52 | public function benchOffsetSetEnumerator() |
||
58 | |||
59 | public function benchOffsetSetValue() |
||
65 | |||
66 | public function benchOffsetUnsetEnumerator() |
||
72 | |||
73 | public function benchOffsetUnsetValue() |
||
79 | |||
80 | public function benchOffsetExistsEnumeratorTrue() |
||
86 | |||
87 | public function benchOffsetExistsEnumeratorFalse() |
||
93 | |||
94 | public function benchOffsetExistsValueTrue() |
||
100 | |||
101 | public function benchOffsetExistsValueFalse() |
||
107 | |||
108 | public function benchIterateFull() |
||
114 | |||
115 | public function benchIterateEmpty() |
||
121 | |||
122 | public function benchCountFull() |
||
126 | |||
127 | public function benchCountEmpty() |
||
131 | } |
||
132 |
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.