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:
Complex classes like TEntityContainerMappingType often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TEntityContainerMappingType, and based on these observations, apply Extract Interface, too.
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) |
||
79 | |||
80 | /** |
||
81 | * Gets as storageEntityContainer |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getStorageEntityContainer() |
||
89 | |||
90 | /** |
||
91 | * Sets a new storageEntityContainer |
||
92 | * |
||
93 | * @param string $storageEntityContainer |
||
94 | * @return self |
||
95 | */ |
||
96 | public function setStorageEntityContainer($storageEntityContainer) |
||
105 | |||
106 | /** |
||
107 | * Gets as generateUpdateViews |
||
108 | * |
||
109 | * @return boolean |
||
110 | */ |
||
111 | public function getGenerateUpdateViews() |
||
115 | |||
116 | /** |
||
117 | * Sets a new generateUpdateViews |
||
118 | * |
||
119 | * @param boolean $generateUpdateViews |
||
120 | * @return self |
||
121 | */ |
||
122 | public function setGenerateUpdateViews($generateUpdateViews) |
||
127 | |||
128 | /** |
||
129 | * Adds as entitySetMapping |
||
130 | * |
||
131 | * @return self |
||
132 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType $entitySetMapping |
||
133 | */ |
||
134 | View Code Duplication | public function addToEntitySetMapping(TEntitySetMappingType $entitySetMapping) |
|
143 | |||
144 | /** |
||
145 | * isset entitySetMapping |
||
146 | * |
||
147 | * @param scalar $index |
||
148 | * @return boolean |
||
149 | */ |
||
150 | public function issetEntitySetMapping($index) |
||
154 | |||
155 | /** |
||
156 | * unset entitySetMapping |
||
157 | * |
||
158 | * @param scalar $index |
||
159 | * @return void |
||
160 | */ |
||
161 | public function unsetEntitySetMapping($index) |
||
165 | |||
166 | /** |
||
167 | * Gets as entitySetMapping |
||
168 | * |
||
169 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType[] |
||
170 | */ |
||
171 | public function getEntitySetMapping() |
||
175 | |||
176 | /** |
||
177 | * Sets a new entitySetMapping |
||
178 | * |
||
179 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType[] $entitySetMapping |
||
180 | * @return self |
||
181 | */ |
||
182 | View Code Duplication | public function setEntitySetMapping(array $entitySetMapping) |
|
196 | |||
197 | /** |
||
198 | * Adds as associationSetMapping |
||
199 | * |
||
200 | * @return self |
||
201 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType $associationSetMapping |
||
202 | */ |
||
203 | View Code Duplication | public function addToAssociationSetMapping(TAssociationSetMappingType $associationSetMapping) |
|
212 | |||
213 | /** |
||
214 | * isset associationSetMapping |
||
215 | * |
||
216 | * @param scalar $index |
||
217 | * @return boolean |
||
218 | */ |
||
219 | public function issetAssociationSetMapping($index) |
||
223 | |||
224 | /** |
||
225 | * unset associationSetMapping |
||
226 | * |
||
227 | * @param scalar $index |
||
228 | * @return void |
||
229 | */ |
||
230 | public function unsetAssociationSetMapping($index) |
||
234 | |||
235 | /** |
||
236 | * Gets as associationSetMapping |
||
237 | * |
||
238 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType[] |
||
239 | */ |
||
240 | public function getAssociationSetMapping() |
||
244 | |||
245 | /** |
||
246 | * Sets a new associationSetMapping |
||
247 | * |
||
248 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType[] |
||
249 | * $associationSetMapping |
||
250 | * @return self |
||
251 | */ |
||
252 | View Code Duplication | public function setAssociationSetMapping(array $associationSetMapping) |
|
266 | |||
267 | /** |
||
268 | * Adds as functionImportMapping |
||
269 | * |
||
270 | * @return self |
||
271 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType $functionImportMapping |
||
272 | */ |
||
273 | View Code Duplication | public function addToFunctionImportMapping(TFunctionImportMappingType $functionImportMapping) |
|
282 | |||
283 | /** |
||
284 | * isset functionImportMapping |
||
285 | * |
||
286 | * @param scalar $index |
||
287 | * @return boolean |
||
288 | */ |
||
289 | public function issetFunctionImportMapping($index) |
||
293 | |||
294 | /** |
||
295 | * unset functionImportMapping |
||
296 | * |
||
297 | * @param scalar $index |
||
298 | * @return void |
||
299 | */ |
||
300 | public function unsetFunctionImportMapping($index) |
||
304 | |||
305 | /** |
||
306 | * Gets as functionImportMapping |
||
307 | * |
||
308 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType[] |
||
309 | */ |
||
310 | public function getFunctionImportMapping() |
||
314 | |||
315 | /** |
||
316 | * Sets a new functionImportMapping |
||
317 | * |
||
318 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType[] |
||
319 | * $functionImportMapping |
||
320 | * @return self |
||
321 | */ |
||
322 | View Code Duplication | public function setFunctionImportMapping(array $functionImportMapping) |
|
336 | |||
337 | public function isOK(&$msg = null) |
||
386 | } |
||
387 |
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.