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 |
||
11 | View Code Duplication | class ReferenceType |
|
|
|||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @property string $uRI |
||
16 | */ |
||
17 | private $uRI = null; |
||
18 | |||
19 | /** |
||
20 | * @property string $valueType |
||
21 | */ |
||
22 | private $valueType = null; |
||
23 | |||
24 | /** |
||
25 | * @property mixed[] $anyAttribute |
||
26 | */ |
||
27 | private $anyAttribute = array( |
||
28 | |||
29 | ); |
||
30 | |||
31 | /** |
||
32 | * Gets as uRI |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | public function getURI() |
||
40 | |||
41 | /** |
||
42 | * Sets a new uRI |
||
43 | * |
||
44 | * @param string $uRI |
||
45 | * @return self |
||
46 | */ |
||
47 | public function setURI($uRI) |
||
52 | |||
53 | /** |
||
54 | * Gets as valueType |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getValueType() |
||
62 | |||
63 | /** |
||
64 | * Sets a new valueType |
||
65 | * |
||
66 | * @param string $valueType |
||
67 | * @return self |
||
68 | */ |
||
69 | public function setValueType($valueType) |
||
74 | |||
75 | /** |
||
76 | * Adds as array |
||
77 | * |
||
78 | * @return self |
||
79 | * @param mixed $array |
||
80 | */ |
||
81 | public function addToAnyAttribute($array) |
||
86 | |||
87 | /** |
||
88 | * isset anyAttribute |
||
89 | * |
||
90 | * @param scalar $index |
||
91 | * @return boolean |
||
92 | */ |
||
93 | public function issetAnyAttribute($index) |
||
97 | |||
98 | /** |
||
99 | * unset anyAttribute |
||
100 | * |
||
101 | * @param scalar $index |
||
102 | * @return void |
||
103 | */ |
||
104 | public function unsetAnyAttribute($index) |
||
108 | |||
109 | /** |
||
110 | * Gets as anyAttribute |
||
111 | * |
||
112 | * @return mixed[] |
||
113 | */ |
||
114 | public function getAnyAttribute() |
||
118 | |||
119 | /** |
||
120 | * Sets a new anyAttribute |
||
121 | * |
||
122 | * @param mixed[] $anyAttribute |
||
123 | * @return self |
||
124 | */ |
||
125 | public function setAnyAttribute(array $anyAttribute) |
||
130 | |||
131 | |||
132 | } |
||
133 | |||
134 |
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.