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 GetSingleStayValueForUnit 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 GetSingleStayValueForUnit, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class GetSingleStayValueForUnit |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var int $intGUID |
||
10 | */ |
||
11 | protected $intGUID = null; |
||
12 | |||
13 | /** |
||
14 | * @var string $strISOLanguage |
||
15 | */ |
||
16 | protected $strISOLanguage = null; |
||
17 | |||
18 | /** |
||
19 | * @var int $intRoomType |
||
20 | */ |
||
21 | protected $intRoomType = null; |
||
22 | |||
23 | /** |
||
24 | * @var int $intRateID |
||
25 | */ |
||
26 | protected $intRateID = null; |
||
27 | |||
28 | /** |
||
29 | * @var string $strRateSpecial |
||
30 | */ |
||
31 | protected $strRateSpecial = null; |
||
32 | |||
33 | /** |
||
34 | * @var int $intGuestCount |
||
35 | */ |
||
36 | protected $intGuestCount = null; |
||
37 | |||
38 | /** |
||
39 | * @var string $strChildren |
||
40 | */ |
||
41 | protected $strChildren = null; |
||
42 | |||
43 | /** |
||
44 | * @var \DateTime $dArrDate |
||
45 | */ |
||
46 | protected $dArrDate = null; |
||
47 | |||
48 | /** |
||
49 | * @var \DateTime $dDepDate |
||
50 | */ |
||
51 | protected $dDepDate = null; |
||
52 | |||
53 | /** |
||
54 | * @var string $strAttributes |
||
55 | */ |
||
56 | protected $strAttributes = null; |
||
57 | |||
58 | /** |
||
59 | * @var string $strLocations |
||
60 | */ |
||
61 | protected $strLocations = null; |
||
62 | |||
63 | /** |
||
64 | * @var dstElements $dstElements |
||
65 | */ |
||
66 | protected $dstElements = null; |
||
67 | |||
68 | /** |
||
69 | * @var int $intRoomQty |
||
70 | */ |
||
71 | protected $intRoomQty = null; |
||
72 | |||
73 | /** |
||
74 | * @var boolean $IsInsuranceAccepted |
||
75 | */ |
||
76 | protected $IsInsuranceAccepted = null; |
||
77 | |||
78 | /** |
||
79 | * @var string $strAttributeGroupings |
||
80 | */ |
||
81 | protected $strAttributeGroupings = null; |
||
82 | |||
83 | /** |
||
84 | * @var string $strLocationsGroupings |
||
85 | */ |
||
86 | protected $strLocationsGroupings = null; |
||
87 | |||
88 | /** |
||
89 | * @var int $ID_Room |
||
90 | */ |
||
91 | protected $ID_Room = null; |
||
92 | |||
93 | /** |
||
94 | * @var int $intBusinessSourceID |
||
95 | */ |
||
96 | protected $intBusinessSourceID = null; |
||
97 | |||
98 | /** |
||
99 | * @param int $intGUID |
||
100 | * @param string $strISOLanguage |
||
101 | * @param int $intRoomType |
||
102 | * @param int $intRateID |
||
103 | * @param string $strRateSpecial |
||
104 | * @param int $intGuestCount |
||
105 | * @param string $strChildren |
||
106 | * @param \DateTime $dArrDate |
||
107 | * @param \DateTime $dDepDate |
||
108 | * @param string $strAttributes |
||
109 | * @param string $strLocations |
||
110 | * @param dstElements $dstElements |
||
111 | * @param int $intRoomQty |
||
112 | * @param boolean $IsInsuranceAccepted |
||
113 | * @param string $strAttributeGroupings |
||
114 | * @param string $strLocationsGroupings |
||
115 | * @param int $ID_Room |
||
116 | * @param int $intBusinessSourceID |
||
117 | */ |
||
118 | View Code Duplication | public function __construct($intGUID, $strISOLanguage, $intRoomType, $intRateID, $strRateSpecial, $intGuestCount, $strChildren, \DateTime $dArrDate, \DateTime $dDepDate, $strAttributes, $strLocations, $dstElements, $intRoomQty, $IsInsuranceAccepted, $strAttributeGroupings, $strLocationsGroupings, $ID_Room, $intBusinessSourceID) |
|
139 | |||
140 | /** |
||
141 | * @return int |
||
142 | */ |
||
143 | public function getIntGUID() |
||
147 | |||
148 | /** |
||
149 | * @param int $intGUID |
||
150 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
151 | */ |
||
152 | public function setIntGUID($intGUID) |
||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getStrISOLanguage() |
||
165 | |||
166 | /** |
||
167 | * @param string $strISOLanguage |
||
168 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
169 | */ |
||
170 | public function setStrISOLanguage($strISOLanguage) |
||
175 | |||
176 | /** |
||
177 | * @return int |
||
178 | */ |
||
179 | public function getIntRoomType() |
||
183 | |||
184 | /** |
||
185 | * @param int $intRoomType |
||
186 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
187 | */ |
||
188 | public function setIntRoomType($intRoomType) |
||
193 | |||
194 | /** |
||
195 | * @return int |
||
196 | */ |
||
197 | public function getIntRateID() |
||
201 | |||
202 | /** |
||
203 | * @param int $intRateID |
||
204 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
205 | */ |
||
206 | public function setIntRateID($intRateID) |
||
211 | |||
212 | /** |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getStrRateSpecial() |
||
219 | |||
220 | /** |
||
221 | * @param string $strRateSpecial |
||
222 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
223 | */ |
||
224 | public function setStrRateSpecial($strRateSpecial) |
||
229 | |||
230 | /** |
||
231 | * @return int |
||
232 | */ |
||
233 | public function getIntGuestCount() |
||
237 | |||
238 | /** |
||
239 | * @param int $intGuestCount |
||
240 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
241 | */ |
||
242 | public function setIntGuestCount($intGuestCount) |
||
247 | |||
248 | /** |
||
249 | * @return string |
||
250 | */ |
||
251 | public function getStrChildren() |
||
255 | |||
256 | /** |
||
257 | * @param string $strChildren |
||
258 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
259 | */ |
||
260 | public function setStrChildren($strChildren) |
||
265 | |||
266 | /** |
||
267 | * @return \DateTime |
||
268 | */ |
||
269 | public function getDArrDate() |
||
281 | |||
282 | /** |
||
283 | * @param \DateTime $dArrDate |
||
284 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
285 | */ |
||
286 | public function setDArrDate(\DateTime $dArrDate) |
||
291 | |||
292 | /** |
||
293 | * @return \DateTime |
||
294 | */ |
||
295 | public function getDDepDate() |
||
307 | |||
308 | /** |
||
309 | * @param \DateTime $dDepDate |
||
310 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
311 | */ |
||
312 | public function setDDepDate(\DateTime $dDepDate) |
||
317 | |||
318 | /** |
||
319 | * @return string |
||
320 | */ |
||
321 | public function getStrAttributes() |
||
325 | |||
326 | /** |
||
327 | * @param string $strAttributes |
||
328 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
329 | */ |
||
330 | public function setStrAttributes($strAttributes) |
||
335 | |||
336 | /** |
||
337 | * @return string |
||
338 | */ |
||
339 | public function getStrLocations() |
||
343 | |||
344 | /** |
||
345 | * @param string $strLocations |
||
346 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
347 | */ |
||
348 | public function setStrLocations($strLocations) |
||
353 | |||
354 | /** |
||
355 | * @return dstElements |
||
356 | */ |
||
357 | public function getDstElements() |
||
361 | |||
362 | /** |
||
363 | * @param dstElements $dstElements |
||
364 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
365 | */ |
||
366 | public function setDstElements($dstElements) |
||
371 | |||
372 | /** |
||
373 | * @return int |
||
374 | */ |
||
375 | public function getIntRoomQty() |
||
379 | |||
380 | /** |
||
381 | * @param int $intRoomQty |
||
382 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
383 | */ |
||
384 | public function setIntRoomQty($intRoomQty) |
||
389 | |||
390 | /** |
||
391 | * @return boolean |
||
392 | */ |
||
393 | public function getIsInsuranceAccepted() |
||
397 | |||
398 | /** |
||
399 | * @param boolean $IsInsuranceAccepted |
||
400 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
401 | */ |
||
402 | public function setIsInsuranceAccepted($IsInsuranceAccepted) |
||
407 | |||
408 | /** |
||
409 | * @return string |
||
410 | */ |
||
411 | public function getStrAttributeGroupings() |
||
415 | |||
416 | /** |
||
417 | * @param string $strAttributeGroupings |
||
418 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
419 | */ |
||
420 | public function setStrAttributeGroupings($strAttributeGroupings) |
||
425 | |||
426 | /** |
||
427 | * @return string |
||
428 | */ |
||
429 | public function getStrLocationsGroupings() |
||
433 | |||
434 | /** |
||
435 | * @param string $strLocationsGroupings |
||
436 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
437 | */ |
||
438 | public function setStrLocationsGroupings($strLocationsGroupings) |
||
443 | |||
444 | /** |
||
445 | * @return int |
||
446 | */ |
||
447 | public function getID_Room() |
||
451 | |||
452 | /** |
||
453 | * @param int $ID_Room |
||
454 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
455 | */ |
||
456 | public function setID_Room($ID_Room) |
||
461 | |||
462 | /** |
||
463 | * @return int |
||
464 | */ |
||
465 | public function getIntBusinessSourceID() |
||
469 | |||
470 | /** |
||
471 | * @param int $intBusinessSourceID |
||
472 | * @return \Gueststream\PMS\IQWare\API\GetSingleStayValueForUnit |
||
473 | */ |
||
474 | public function setIntBusinessSourceID($intBusinessSourceID) |
||
479 | } |
||
480 |
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.