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 TEntityContainerMappingType extends IsOK |
||
16 | { |
||
17 | use TSimpleIdentifierTrait; |
||
18 | /** |
||
19 | * @property string $cdmEntityContainer |
||
20 | */ |
||
21 | private $cdmEntityContainer = null; |
||
22 | |||
23 | /** |
||
24 | * @property string $storageEntityContainer |
||
25 | */ |
||
26 | private $storageEntityContainer = null; |
||
27 | |||
28 | /** |
||
29 | * @property boolean $generateUpdateViews |
||
30 | */ |
||
31 | private $generateUpdateViews = null; |
||
32 | |||
33 | /** |
||
34 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType[] $entitySetMapping |
||
35 | */ |
||
36 | private $entitySetMapping = []; |
||
37 | |||
38 | /** |
||
39 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType[] |
||
40 | * $associationSetMapping |
||
41 | */ |
||
42 | private $associationSetMapping = []; |
||
43 | |||
44 | /** |
||
45 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType[] |
||
46 | * $functionImportMapping |
||
47 | */ |
||
48 | private $functionImportMapping = []; |
||
49 | |||
50 | /** |
||
51 | * Gets as cdmEntityContainer |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getCdmEntityContainer() |
||
59 | |||
60 | /** |
||
61 | * Sets a new cdmEntityContainer |
||
62 | * |
||
63 | * @param string $cdmEntityContainer |
||
64 | * @return self |
||
65 | */ |
||
66 | public function setCdmEntityContainer($cdmEntityContainer) |
||
71 | |||
72 | /** |
||
73 | * Gets as storageEntityContainer |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getStorageEntityContainer() |
||
81 | |||
82 | /** |
||
83 | * Sets a new storageEntityContainer |
||
84 | * |
||
85 | * @param string $storageEntityContainer |
||
86 | * @return self |
||
87 | */ |
||
88 | public function setStorageEntityContainer($storageEntityContainer) |
||
93 | |||
94 | /** |
||
95 | * Gets as generateUpdateViews |
||
96 | * |
||
97 | * @return boolean |
||
98 | */ |
||
99 | public function getGenerateUpdateViews() |
||
103 | |||
104 | /** |
||
105 | * Sets a new generateUpdateViews |
||
106 | * |
||
107 | * @param boolean $generateUpdateViews |
||
108 | * @return self |
||
109 | */ |
||
110 | public function setGenerateUpdateViews($generateUpdateViews) |
||
115 | |||
116 | /** |
||
117 | * Adds as entitySetMapping |
||
118 | * |
||
119 | * @return self |
||
120 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType $entitySetMapping |
||
121 | */ |
||
122 | View Code Duplication | public function addToEntitySetMapping(TEntitySetMappingType $entitySetMapping) |
|
|
|||
123 | { |
||
124 | $msg = null; |
||
125 | if (!$entitySetMapping->isOK($msg)) { |
||
126 | throw new \InvalidArgumentException($msg); |
||
127 | } |
||
128 | $this->entitySetMapping[] = $entitySetMapping; |
||
129 | return $this; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * isset entitySetMapping |
||
134 | * |
||
135 | * @param scalar $index |
||
136 | * @return boolean |
||
137 | */ |
||
138 | public function issetEntitySetMapping($index) |
||
142 | |||
143 | /** |
||
144 | * unset entitySetMapping |
||
145 | * |
||
146 | * @param scalar $index |
||
147 | * @return void |
||
148 | */ |
||
149 | public function unsetEntitySetMapping($index) |
||
153 | |||
154 | /** |
||
155 | * Gets as entitySetMapping |
||
156 | * |
||
157 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType[] |
||
158 | */ |
||
159 | public function getEntitySetMapping() |
||
163 | |||
164 | /** |
||
165 | * Sets a new entitySetMapping |
||
166 | * |
||
167 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType[] $entitySetMapping |
||
168 | * @return self |
||
169 | */ |
||
170 | View Code Duplication | public function setEntitySetMapping(array $entitySetMapping) |
|
183 | |||
184 | /** |
||
185 | * Adds as associationSetMapping |
||
186 | * |
||
187 | * @return self |
||
188 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType $associationSetMapping |
||
189 | */ |
||
190 | View Code Duplication | public function addToAssociationSetMapping(TAssociationSetMappingType $associationSetMapping) |
|
199 | |||
200 | /** |
||
201 | * isset associationSetMapping |
||
202 | * |
||
203 | * @param scalar $index |
||
204 | * @return boolean |
||
205 | */ |
||
206 | public function issetAssociationSetMapping($index) |
||
210 | |||
211 | /** |
||
212 | * unset associationSetMapping |
||
213 | * |
||
214 | * @param scalar $index |
||
215 | * @return void |
||
216 | */ |
||
217 | public function unsetAssociationSetMapping($index) |
||
221 | |||
222 | /** |
||
223 | * Gets as associationSetMapping |
||
224 | * |
||
225 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType[] |
||
226 | */ |
||
227 | public function getAssociationSetMapping() |
||
231 | |||
232 | /** |
||
233 | * Sets a new associationSetMapping |
||
234 | * |
||
235 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType[] |
||
236 | * $associationSetMapping |
||
237 | * @return self |
||
238 | */ |
||
239 | View Code Duplication | public function setAssociationSetMapping(array $associationSetMapping) |
|
252 | |||
253 | /** |
||
254 | * Adds as functionImportMapping |
||
255 | * |
||
256 | * @return self |
||
257 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType $functionImportMapping |
||
258 | */ |
||
259 | View Code Duplication | public function addToFunctionImportMapping(TFunctionImportMappingType $functionImportMapping) |
|
268 | |||
269 | /** |
||
270 | * isset functionImportMapping |
||
271 | * |
||
272 | * @param scalar $index |
||
273 | * @return boolean |
||
274 | */ |
||
275 | public function issetFunctionImportMapping($index) |
||
279 | |||
280 | /** |
||
281 | * unset functionImportMapping |
||
282 | * |
||
283 | * @param scalar $index |
||
284 | * @return void |
||
285 | */ |
||
286 | public function unsetFunctionImportMapping($index) |
||
290 | |||
291 | /** |
||
292 | * Gets as functionImportMapping |
||
293 | * |
||
294 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType[] |
||
295 | */ |
||
296 | public function getFunctionImportMapping() |
||
300 | |||
301 | /** |
||
302 | * Sets a new functionImportMapping |
||
303 | * |
||
304 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType[] |
||
305 | * $functionImportMapping |
||
306 | * @return self |
||
307 | */ |
||
308 | View Code Duplication | public function setFunctionImportMapping(array $functionImportMapping) |
|
321 | |||
322 | public function isOK(&$msg = null) |
||
368 | } |
||
369 |
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.