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 | View Code Duplication | class TReferentialConstraintRoleElementType extends IsOK |
|
|
|||
16 | { |
||
17 | use IsOKToolboxTrait, TSimpleIdentifierTrait; |
||
18 | /** |
||
19 | * @property string $role |
||
20 | */ |
||
21 | private $role = null; |
||
22 | |||
23 | /** |
||
24 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType[] $propertyRef |
||
25 | */ |
||
26 | private $propertyRef = []; |
||
27 | |||
28 | /** |
||
29 | * Gets as role |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | public function getRole() |
||
37 | |||
38 | /** |
||
39 | * Sets a new role |
||
40 | * |
||
41 | * @param string $role |
||
42 | * @return self |
||
43 | */ |
||
44 | public function setRole($role) |
||
49 | |||
50 | /** |
||
51 | * Adds as propertyRef |
||
52 | * |
||
53 | * @return self |
||
54 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType $propertyRef |
||
55 | */ |
||
56 | public function addToPropertyRef(TPropertyRefType $propertyRef) |
||
61 | |||
62 | /** |
||
63 | * isset propertyRef |
||
64 | * |
||
65 | * @param scalar $index |
||
66 | * @return boolean |
||
67 | */ |
||
68 | public function issetPropertyRef($index) |
||
72 | |||
73 | /** |
||
74 | * unset propertyRef |
||
75 | * |
||
76 | * @param scalar $index |
||
77 | * @return void |
||
78 | */ |
||
79 | public function unsetPropertyRef($index) |
||
83 | |||
84 | /** |
||
85 | * Gets as propertyRef |
||
86 | * |
||
87 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType[] |
||
88 | */ |
||
89 | public function getPropertyRef() |
||
93 | |||
94 | /** |
||
95 | * Sets a new propertyRef |
||
96 | * |
||
97 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType[] $propertyRef |
||
98 | * @return self |
||
99 | */ |
||
100 | public function setPropertyRef(array $propertyRef) |
||
105 | |||
106 | public function isOK(&$msg = null) |
||
123 | } |
||
124 |
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.