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 TAssociationSetMappingType 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 TAssociationSetMappingType, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class TAssociationSetMappingType extends IsOK |
||
17 | { |
||
18 | use TSimpleIdentifierTrait, TQualifiedNameTrait; |
||
19 | /** |
||
20 | * @property string $name |
||
21 | */ |
||
22 | private $name = null; |
||
23 | |||
24 | /** |
||
25 | * @property string $typeName |
||
26 | */ |
||
27 | private $typeName = null; |
||
28 | |||
29 | /** |
||
30 | * @property string $storeEntitySet |
||
31 | */ |
||
32 | private $storeEntitySet = null; |
||
33 | |||
34 | /** |
||
35 | * @property string $queryView |
||
36 | */ |
||
37 | private $queryView = null; |
||
38 | |||
39 | /** |
||
40 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEndPropertyType[] $endProperty |
||
41 | */ |
||
42 | private $endProperty = []; |
||
43 | |||
44 | /** |
||
45 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] $condition |
||
46 | */ |
||
47 | private $condition = []; |
||
48 | |||
49 | /** |
||
50 | * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetModificationFunctionMappingType |
||
51 | * $modificationFunctionMapping |
||
52 | */ |
||
53 | private $modificationFunctionMapping = null; |
||
54 | |||
55 | /** |
||
56 | * Gets as name |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getName() |
||
64 | |||
65 | /** |
||
66 | * Sets a new name |
||
67 | * |
||
68 | * @param string $name |
||
69 | * @return self |
||
70 | */ |
||
71 | public function setName($name) |
||
84 | |||
85 | /** |
||
86 | * Gets as typeName |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getTypeName() |
||
94 | |||
95 | /** |
||
96 | * Sets a new typeName |
||
97 | * |
||
98 | * @param string $typeName |
||
99 | * @return self |
||
100 | */ |
||
101 | public function setTypeName($typeName) |
||
114 | |||
115 | /** |
||
116 | * Gets as storeEntitySet |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getStoreEntitySet() |
||
124 | |||
125 | /** |
||
126 | * Sets a new storeEntitySet |
||
127 | * |
||
128 | * @param string $storeEntitySet |
||
129 | * @return self |
||
130 | */ |
||
131 | View Code Duplication | public function setStoreEntitySet($storeEntitySet) |
|
140 | |||
141 | /** |
||
142 | * Gets as queryView |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | public function getQueryView() |
||
150 | |||
151 | /** |
||
152 | * Sets a new queryView |
||
153 | * |
||
154 | * @param string $queryView |
||
155 | * @return self |
||
156 | */ |
||
157 | View Code Duplication | public function setQueryView($queryView) |
|
166 | |||
167 | /** |
||
168 | * Adds as endProperty |
||
169 | * |
||
170 | * @return self |
||
171 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEndPropertyType $endProperty |
||
172 | */ |
||
173 | View Code Duplication | public function addToEndProperty(TEndPropertyType $endProperty) |
|
182 | |||
183 | /** |
||
184 | * isset endProperty |
||
185 | * |
||
186 | * @param scalar $index |
||
187 | * @return boolean |
||
188 | */ |
||
189 | public function issetEndProperty($index) |
||
193 | |||
194 | /** |
||
195 | * unset endProperty |
||
196 | * |
||
197 | * @param scalar $index |
||
198 | * @return void |
||
199 | */ |
||
200 | public function unsetEndProperty($index) |
||
204 | |||
205 | /** |
||
206 | * Gets as endProperty |
||
207 | * |
||
208 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEndPropertyType[] |
||
209 | */ |
||
210 | public function getEndProperty() |
||
214 | |||
215 | /** |
||
216 | * Sets a new endProperty |
||
217 | * |
||
218 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEndPropertyType[] $endProperty |
||
219 | * @return self |
||
220 | */ |
||
221 | public function setEndProperty(array $endProperty) |
||
236 | |||
237 | /** |
||
238 | * Adds as condition |
||
239 | * |
||
240 | * @return self |
||
241 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType $condition |
||
242 | */ |
||
243 | View Code Duplication | public function addToCondition(TConditionType $condition) |
|
252 | |||
253 | /** |
||
254 | * isset condition |
||
255 | * |
||
256 | * @param scalar $index |
||
257 | * @return boolean |
||
258 | */ |
||
259 | public function issetCondition($index) |
||
263 | |||
264 | /** |
||
265 | * unset condition |
||
266 | * |
||
267 | * @param scalar $index |
||
268 | * @return void |
||
269 | */ |
||
270 | public function unsetCondition($index) |
||
274 | |||
275 | /** |
||
276 | * Gets as condition |
||
277 | * |
||
278 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] |
||
279 | */ |
||
280 | public function getCondition() |
||
284 | |||
285 | /** |
||
286 | * Sets a new condition |
||
287 | * |
||
288 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] $condition |
||
289 | * @return self |
||
290 | */ |
||
291 | View Code Duplication | public function setCondition(array $condition) |
|
304 | |||
305 | /** |
||
306 | * Gets as modificationFunctionMapping |
||
307 | * |
||
308 | * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetModificationFunctionMappingType |
||
309 | */ |
||
310 | public function getModificationFunctionMapping() |
||
314 | |||
315 | /** |
||
316 | * Sets a new modificationFunctionMapping |
||
317 | * |
||
318 | * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetModificationFunctionMappingType |
||
319 | * $modificationFunctionMapping |
||
320 | * @return self |
||
321 | */ |
||
322 | public function setModificationFunctionMapping(TAssociationSetModificationFunctionMappingType $modificationFunctionMapping) |
||
331 | |||
332 | public function isOK(&$msg = null) |
||
387 | } |
||
388 |
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.