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 TEntityTypeType 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 TEntityTypeType, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class TEntityTypeType extends IsOK |
||
16 | { |
||
17 | use TDerivableTypeAttributesTrait, AccessTypeTraits; |
||
18 | /** |
||
19 | * @property boolean $openType |
||
20 | */ |
||
21 | private $openType = false; |
||
22 | |||
23 | /** |
||
24 | * @property string $typeAccess |
||
25 | */ |
||
26 | private $typeAccess = null; |
||
27 | |||
28 | /** |
||
29 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation |
||
30 | */ |
||
31 | private $documentation = null; |
||
32 | |||
33 | /** |
||
34 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType[] $key |
||
35 | */ |
||
36 | private $key = null; |
||
37 | |||
38 | /** |
||
39 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType[] $property |
||
40 | */ |
||
41 | private $property = []; |
||
42 | |||
43 | /** |
||
44 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType[] $navigationProperty |
||
45 | */ |
||
46 | private $navigationProperty = []; |
||
47 | |||
48 | /** |
||
49 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType[] $valueAnnotation |
||
50 | */ |
||
51 | private $valueAnnotation = []; |
||
52 | |||
53 | /** |
||
54 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType[] $typeAnnotation |
||
55 | */ |
||
56 | private $typeAnnotation = []; |
||
57 | |||
58 | /** |
||
59 | * Gets as openType |
||
60 | * |
||
61 | * @return boolean |
||
62 | */ |
||
63 | public function getOpenType() |
||
67 | |||
68 | /** |
||
69 | * Sets a new openType |
||
70 | * |
||
71 | * @param boolean $openType |
||
72 | * @return self |
||
73 | */ |
||
74 | public function setOpenType($openType) |
||
79 | |||
80 | /** |
||
81 | * Gets as typeAccess |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getTypeAccess() |
||
89 | |||
90 | /** |
||
91 | * Sets a new typeAccess |
||
92 | * |
||
93 | * @param string $typeAccess |
||
94 | * @return self |
||
95 | */ |
||
96 | View Code Duplication | public function setTypeAccess($typeAccess) |
|
105 | |||
106 | /** |
||
107 | * Gets as documentation |
||
108 | * |
||
109 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType |
||
110 | */ |
||
111 | public function getDocumentation() |
||
115 | |||
116 | /** |
||
117 | * Sets a new documentation |
||
118 | * |
||
119 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation |
||
120 | * @return self |
||
121 | */ |
||
122 | View Code Duplication | public function setDocumentation(TDocumentationType $documentation) |
|
131 | |||
132 | /** |
||
133 | * Adds as propertyRef |
||
134 | * |
||
135 | * @return self |
||
136 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType $propertyRef |
||
137 | */ |
||
138 | public function addToKey(TPropertyRefType $propertyRef) |
||
147 | |||
148 | /** |
||
149 | * isset key |
||
150 | * |
||
151 | * @param scalar $index |
||
152 | * @return boolean |
||
153 | */ |
||
154 | public function issetKey($index) |
||
158 | |||
159 | /** |
||
160 | * unset key |
||
161 | * |
||
162 | * @param scalar $index |
||
163 | * @return void |
||
164 | */ |
||
165 | public function unsetKey($index) |
||
169 | |||
170 | /** |
||
171 | * Gets as key |
||
172 | * |
||
173 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType[] |
||
174 | */ |
||
175 | public function getKey() |
||
179 | |||
180 | /** |
||
181 | * Sets a new key |
||
182 | * |
||
183 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType[] $key |
||
184 | * @return self |
||
185 | */ |
||
186 | View Code Duplication | public function setKey(array $key) |
|
198 | |||
199 | /** |
||
200 | * Adds as property |
||
201 | * |
||
202 | * @return self |
||
203 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType $property |
||
204 | */ |
||
205 | View Code Duplication | public function addToProperty(TEntityPropertyType $property) |
|
214 | |||
215 | /** |
||
216 | * isset property |
||
217 | * |
||
218 | * @param scalar $index |
||
219 | * @return boolean |
||
220 | */ |
||
221 | public function issetProperty($index) |
||
225 | |||
226 | /** |
||
227 | * unset property |
||
228 | * |
||
229 | * @param scalar $index |
||
230 | * @return void |
||
231 | */ |
||
232 | public function unsetProperty($index) |
||
236 | |||
237 | /** |
||
238 | * Adds as navigationProperty |
||
239 | * |
||
240 | * @return self |
||
241 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType $navigationProperty |
||
242 | */ |
||
243 | public function addToNavigationProperty(TNavigationPropertyType $navigationProperty) |
||
252 | |||
253 | /** |
||
254 | * isset navigationProperty |
||
255 | * |
||
256 | * @param scalar $index |
||
257 | * @return boolean |
||
258 | */ |
||
259 | public function issetNavigationProperty($index) |
||
263 | |||
264 | /** |
||
265 | * unset navigationProperty |
||
266 | * |
||
267 | * @param scalar $index |
||
268 | * @return void |
||
269 | */ |
||
270 | public function unsetNavigationProperty($index) |
||
274 | |||
275 | /** |
||
276 | * Adds as valueAnnotation |
||
277 | * |
||
278 | * @return self |
||
279 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType $valueAnnotation |
||
280 | */ |
||
281 | View Code Duplication | public function addToValueAnnotation(TValueAnnotationType $valueAnnotation) |
|
290 | |||
291 | /** |
||
292 | * isset valueAnnotation |
||
293 | * |
||
294 | * @param scalar $index |
||
295 | * @return boolean |
||
296 | */ |
||
297 | public function issetValueAnnotation($index) |
||
301 | |||
302 | /** |
||
303 | * unset valueAnnotation |
||
304 | * |
||
305 | * @param scalar $index |
||
306 | * @return void |
||
307 | */ |
||
308 | public function unsetValueAnnotation($index) |
||
312 | |||
313 | /** |
||
314 | * Gets as valueAnnotation |
||
315 | * |
||
316 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType[] |
||
317 | */ |
||
318 | public function getValueAnnotation() |
||
322 | |||
323 | /** |
||
324 | * Sets a new valueAnnotation |
||
325 | * |
||
326 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType[] $valueAnnotation |
||
327 | * @return self |
||
328 | */ |
||
329 | View Code Duplication | public function setValueAnnotation(array $valueAnnotation) |
|
341 | |||
342 | /** |
||
343 | * Adds as typeAnnotation |
||
344 | * |
||
345 | * @return self |
||
346 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType $typeAnnotation |
||
347 | */ |
||
348 | View Code Duplication | public function addToTypeAnnotation(TTypeAnnotationType $typeAnnotation) |
|
357 | |||
358 | /** |
||
359 | * isset typeAnnotation |
||
360 | * |
||
361 | * @param scalar $index |
||
362 | * @return boolean |
||
363 | */ |
||
364 | public function issetTypeAnnotation($index) |
||
368 | |||
369 | /** |
||
370 | * unset typeAnnotation |
||
371 | * |
||
372 | * @param scalar $index |
||
373 | * @return void |
||
374 | */ |
||
375 | public function unsetTypeAnnotation($index) |
||
379 | |||
380 | /** |
||
381 | * Gets as typeAnnotation |
||
382 | * |
||
383 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType[] |
||
384 | */ |
||
385 | public function getTypeAnnotation() |
||
389 | |||
390 | /** |
||
391 | * Sets a new typeAnnotation |
||
392 | * |
||
393 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType[] $typeAnnotation |
||
394 | * @return self |
||
395 | */ |
||
396 | View Code Duplication | public function setTypeAnnotation(array $typeAnnotation) |
|
408 | |||
409 | public function isOK(&$msg = null) |
||
464 | |||
465 | public function isStructureOK(&$msg = null) |
||
488 | |||
489 | /** |
||
490 | * Gets as property |
||
491 | * |
||
492 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType[] |
||
493 | */ |
||
494 | public function getProperty() |
||
498 | |||
499 | /** |
||
500 | * Sets a new property |
||
501 | * |
||
502 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType[] $property |
||
503 | * @return self |
||
504 | */ |
||
505 | public function setProperty(array $property) |
||
518 | |||
519 | /** |
||
520 | * Gets as navigationProperty |
||
521 | * |
||
522 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType[] |
||
523 | */ |
||
524 | public function getNavigationProperty() |
||
528 | |||
529 | /** |
||
530 | * Sets a new navigationProperty |
||
531 | * |
||
532 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType[] $navigationProperty |
||
533 | * @return self |
||
534 | */ |
||
535 | public function setNavigationProperty(array $navigationProperty) |
||
548 | } |
||
549 |
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.