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 |
||
9 | trait TPropertyGroup |
||
10 | { |
||
11 | /** |
||
12 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType $complexProperty |
||
13 | */ |
||
14 | private $complexProperty = null; |
||
15 | |||
16 | /** |
||
17 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType $scalarProperty |
||
18 | */ |
||
19 | private $scalarProperty = null; |
||
20 | |||
21 | /** |
||
22 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType $condition |
||
23 | */ |
||
24 | private $condition = null; |
||
25 | |||
26 | /** |
||
27 | * Gets as complexProperty |
||
28 | * |
||
29 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType |
||
30 | */ |
||
31 | public function getComplexProperty() |
||
35 | |||
36 | /** |
||
37 | * Sets a new complexProperty |
||
38 | * |
||
39 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType $complexProperty |
||
40 | * @return self |
||
41 | */ |
||
42 | public function setComplexProperty(TComplexPropertyType $complexProperty) |
||
47 | |||
48 | /** |
||
49 | * Gets as scalarProperty |
||
50 | * |
||
51 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType |
||
52 | */ |
||
53 | public function getScalarProperty() |
||
57 | |||
58 | /** |
||
59 | * Sets a new scalarProperty |
||
60 | * |
||
61 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType $scalarProperty |
||
62 | * @return self |
||
63 | */ |
||
64 | public function setScalarProperty(TScalarPropertyType $scalarProperty) |
||
69 | |||
70 | /** |
||
71 | * Gets as condition |
||
72 | * |
||
73 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType |
||
74 | */ |
||
75 | public function getCondition() |
||
79 | |||
80 | /** |
||
81 | * Sets a new condition |
||
82 | * |
||
83 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType $condition |
||
84 | * @return self |
||
85 | */ |
||
86 | public function setCondition(TConditionType $condition) |
||
91 | |||
92 | View Code Duplication | public function isPropertyGroupOK(&$msg = null) |
|
105 | } |
||
106 |
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.