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 | class TComplexTypeMappingType extends IsOK |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @property string $typeName |
||
19 | */ |
||
20 | private $typeName = null; |
||
21 | |||
22 | /** |
||
23 | * @property boolean $isPartial |
||
24 | */ |
||
25 | private $isPartial = null; |
||
26 | |||
27 | /** |
||
28 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType[] $scalarProperty |
||
29 | */ |
||
30 | private $scalarProperty = []; |
||
31 | |||
32 | /** |
||
33 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType[] $complexProperty |
||
34 | */ |
||
35 | private $complexProperty = []; |
||
36 | |||
37 | /** |
||
38 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] $condition |
||
39 | */ |
||
40 | private $condition = []; |
||
41 | |||
42 | /** |
||
43 | * Gets as typeName |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | public function getTypeName() |
||
51 | |||
52 | /** |
||
53 | * Sets a new typeName |
||
54 | * |
||
55 | * @param string $typeName |
||
56 | * @return self |
||
57 | */ |
||
58 | View Code Duplication | public function setTypeName($typeName) |
|
69 | |||
70 | /** |
||
71 | * Gets as isPartial |
||
72 | * |
||
73 | * @return boolean |
||
74 | */ |
||
75 | public function getIsPartial() |
||
79 | |||
80 | /** |
||
81 | * Sets a new isPartial |
||
82 | * |
||
83 | * @param boolean $isPartial |
||
84 | * @return self |
||
85 | */ |
||
86 | public function setIsPartial($isPartial) |
||
91 | |||
92 | /** |
||
93 | * Adds as scalarProperty |
||
94 | * |
||
95 | * @return self |
||
96 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType $scalarProperty |
||
97 | */ |
||
98 | View Code Duplication | public function addToScalarProperty(TScalarPropertyType $scalarProperty) |
|
107 | |||
108 | /** |
||
109 | * isset scalarProperty |
||
110 | * |
||
111 | * @param scalar $index |
||
112 | * @return boolean |
||
113 | */ |
||
114 | public function issetScalarProperty($index) |
||
118 | |||
119 | /** |
||
120 | * unset scalarProperty |
||
121 | * |
||
122 | * @param scalar $index |
||
123 | * @return void |
||
124 | */ |
||
125 | public function unsetScalarProperty($index) |
||
129 | |||
130 | /** |
||
131 | * Gets as scalarProperty |
||
132 | * |
||
133 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType[] |
||
134 | */ |
||
135 | public function getScalarProperty() |
||
139 | |||
140 | /** |
||
141 | * Sets a new scalarProperty |
||
142 | * |
||
143 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType[] $scalarProperty |
||
144 | * @return self |
||
145 | */ |
||
146 | View Code Duplication | public function setScalarProperty(array $scalarProperty) |
|
159 | |||
160 | /** |
||
161 | * Adds as complexProperty |
||
162 | * |
||
163 | * @return self |
||
164 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType $complexProperty |
||
165 | */ |
||
166 | View Code Duplication | public function addToComplexProperty(TComplexPropertyType $complexProperty) |
|
175 | |||
176 | /** |
||
177 | * isset complexProperty |
||
178 | * |
||
179 | * @param scalar $index |
||
180 | * @return boolean |
||
181 | */ |
||
182 | public function issetComplexProperty($index) |
||
186 | |||
187 | /** |
||
188 | * unset complexProperty |
||
189 | * |
||
190 | * @param scalar $index |
||
191 | * @return void |
||
192 | */ |
||
193 | public function unsetComplexProperty($index) |
||
197 | |||
198 | /** |
||
199 | * Gets as complexProperty |
||
200 | * |
||
201 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType[] |
||
202 | */ |
||
203 | public function getComplexProperty() |
||
207 | |||
208 | /** |
||
209 | * Sets a new complexProperty |
||
210 | * |
||
211 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType[] $complexProperty |
||
212 | * @return self |
||
213 | */ |
||
214 | View Code Duplication | public function setComplexProperty(array $complexProperty) |
|
227 | |||
228 | /** |
||
229 | * Adds as condition |
||
230 | * |
||
231 | * @return self |
||
232 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType $condition |
||
233 | */ |
||
234 | View Code Duplication | public function addToCondition(TConditionType $condition) |
|
243 | |||
244 | /** |
||
245 | * isset condition |
||
246 | * |
||
247 | * @param scalar $index |
||
248 | * @return boolean |
||
249 | */ |
||
250 | public function issetCondition($index) |
||
254 | |||
255 | /** |
||
256 | * unset condition |
||
257 | * |
||
258 | * @param scalar $index |
||
259 | * @return void |
||
260 | */ |
||
261 | public function unsetCondition($index) |
||
265 | |||
266 | /** |
||
267 | * Gets as condition |
||
268 | * |
||
269 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] |
||
270 | */ |
||
271 | public function getCondition() |
||
275 | |||
276 | /** |
||
277 | * Sets a new condition |
||
278 | * |
||
279 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] $condition |
||
280 | * @return self |
||
281 | */ |
||
282 | View Code Duplication | public function setCondition(array $condition) |
|
295 | |||
296 | public function isOK(&$msg = null) |
||
342 | } |
||
343 |
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.