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 EntitySetAnonymousType extends IsOK |
||
16 | { |
||
17 | use IsOKToolboxTrait, TEntitySetAttributesTrait; |
||
18 | |||
19 | /** |
||
20 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType[] $documentation |
||
21 | */ |
||
22 | private $documentation = []; |
||
23 | |||
24 | /** |
||
25 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType[] $valueAnnotation |
||
26 | */ |
||
27 | private $valueAnnotation = []; |
||
28 | |||
29 | /** |
||
30 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType[] $typeAnnotation |
||
31 | */ |
||
32 | private $typeAnnotation = []; |
||
33 | |||
34 | /** |
||
35 | * Adds as documentation |
||
36 | * |
||
37 | * @return self |
||
38 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation |
||
39 | */ |
||
40 | public function addToDocumentation(TDocumentationType $documentation) |
||
45 | |||
46 | /** |
||
47 | * isset documentation |
||
48 | * |
||
49 | * @param scalar $index |
||
50 | * @return boolean |
||
51 | */ |
||
52 | public function issetDocumentation($index) |
||
56 | |||
57 | /** |
||
58 | * unset documentation |
||
59 | * |
||
60 | * @param scalar $index |
||
61 | * @return void |
||
62 | */ |
||
63 | public function unsetDocumentation($index) |
||
67 | |||
68 | /** |
||
69 | * Gets as documentation |
||
70 | * |
||
71 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType[] |
||
72 | */ |
||
73 | public function getDocumentation() |
||
77 | |||
78 | /** |
||
79 | * Sets a new documentation |
||
80 | * |
||
81 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType[] $documentation |
||
82 | * @return self |
||
83 | */ |
||
84 | public function setDocumentation(array $documentation) |
||
89 | |||
90 | /** |
||
91 | * Adds as valueAnnotation |
||
92 | * |
||
93 | * @return self |
||
94 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType $valueAnnotation |
||
95 | */ |
||
96 | public function addToValueAnnotation(TValueAnnotationType $valueAnnotation) |
||
101 | |||
102 | /** |
||
103 | * isset valueAnnotation |
||
104 | * |
||
105 | * @param scalar $index |
||
106 | * @return boolean |
||
107 | */ |
||
108 | public function issetValueAnnotation($index) |
||
112 | |||
113 | /** |
||
114 | * unset valueAnnotation |
||
115 | * |
||
116 | * @param scalar $index |
||
117 | * @return void |
||
118 | */ |
||
119 | public function unsetValueAnnotation($index) |
||
123 | |||
124 | /** |
||
125 | * Gets as valueAnnotation |
||
126 | * |
||
127 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType[] |
||
128 | */ |
||
129 | public function getValueAnnotation() |
||
133 | |||
134 | /** |
||
135 | * Sets a new valueAnnotation |
||
136 | * |
||
137 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType[] $valueAnnotation |
||
138 | * @return self |
||
139 | */ |
||
140 | public function setValueAnnotation(array $valueAnnotation) |
||
145 | |||
146 | /** |
||
147 | * Adds as typeAnnotation |
||
148 | * |
||
149 | * @return self |
||
150 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType $typeAnnotation |
||
151 | */ |
||
152 | public function addToTypeAnnotation(TTypeAnnotationType $typeAnnotation) |
||
157 | |||
158 | /** |
||
159 | * isset typeAnnotation |
||
160 | * |
||
161 | * @param scalar $index |
||
162 | * @return boolean |
||
163 | */ |
||
164 | public function issetTypeAnnotation($index) |
||
168 | |||
169 | /** |
||
170 | * unset typeAnnotation |
||
171 | * |
||
172 | * @param scalar $index |
||
173 | * @return void |
||
174 | */ |
||
175 | public function unsetTypeAnnotation($index) |
||
179 | |||
180 | /** |
||
181 | * Gets as typeAnnotation |
||
182 | * |
||
183 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType[] |
||
184 | */ |
||
185 | public function getTypeAnnotation() |
||
189 | |||
190 | /** |
||
191 | * Sets a new typeAnnotation |
||
192 | * |
||
193 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType[] $typeAnnotation |
||
194 | * @return self |
||
195 | */ |
||
196 | public function setTypeAnnotation(array $typeAnnotation) |
||
201 | |||
202 | View Code Duplication | public function isOK(&$msg = null) |
|
232 | } |
||
233 |
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.