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 |
||
5 | View Code Duplication | class EvaluationThreaded |
|
|
|||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var int $Guid |
||
10 | */ |
||
11 | protected $Guid = null; |
||
12 | |||
13 | /** |
||
14 | * @var string $strRateCodes |
||
15 | */ |
||
16 | protected $strRateCodes = null; |
||
17 | |||
18 | /** |
||
19 | * @var string $strRoomTypes |
||
20 | */ |
||
21 | protected $strRoomTypes = null; |
||
22 | |||
23 | /** |
||
24 | * @var \DateTime $dtArrivalDate |
||
25 | */ |
||
26 | protected $dtArrivalDate = null; |
||
27 | |||
28 | /** |
||
29 | * @var \DateTime $dtDepartureDate |
||
30 | */ |
||
31 | protected $dtDepartureDate = null; |
||
32 | |||
33 | /** |
||
34 | * @var int $intGuestCount |
||
35 | */ |
||
36 | protected $intGuestCount = null; |
||
37 | |||
38 | /** |
||
39 | * @var string $strChildrens |
||
40 | */ |
||
41 | protected $strChildrens = null; |
||
42 | |||
43 | /** |
||
44 | * @var int $intRateSpecial |
||
45 | */ |
||
46 | protected $intRateSpecial = null; |
||
47 | |||
48 | /** |
||
49 | * @var int $intBuilding |
||
50 | */ |
||
51 | protected $intBuilding = null; |
||
52 | |||
53 | /** |
||
54 | * @var int $intRoomQty |
||
55 | */ |
||
56 | protected $intRoomQty = null; |
||
57 | |||
58 | /** |
||
59 | * @var IAB2BMode $BackToBackMode |
||
60 | */ |
||
61 | protected $BackToBackMode = null; |
||
62 | |||
63 | /** |
||
64 | * @param int $Guid |
||
65 | * @param string $strRateCodes |
||
66 | * @param string $strRoomTypes |
||
67 | * @param \DateTime $dtArrivalDate |
||
68 | * @param \DateTime $dtDepartureDate |
||
69 | * @param int $intGuestCount |
||
70 | * @param string $strChildrens |
||
71 | * @param int $intRateSpecial |
||
72 | * @param int $intBuilding |
||
73 | * @param int $intRoomQty |
||
74 | * @param IAB2BMode $BackToBackMode |
||
75 | */ |
||
76 | public function __construct($Guid, $strRateCodes, $strRoomTypes, \DateTime $dtArrivalDate, \DateTime $dtDepartureDate, $intGuestCount, $strChildrens, $intRateSpecial, $intBuilding, $intRoomQty, $BackToBackMode) |
||
90 | |||
91 | /** |
||
92 | * @return int |
||
93 | */ |
||
94 | public function getGuid() |
||
98 | |||
99 | /** |
||
100 | * @param int $Guid |
||
101 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
102 | */ |
||
103 | public function setGuid($Guid) |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getStrRateCodes() |
||
116 | |||
117 | /** |
||
118 | * @param string $strRateCodes |
||
119 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
120 | */ |
||
121 | public function setStrRateCodes($strRateCodes) |
||
126 | |||
127 | /** |
||
128 | * @return string |
||
129 | */ |
||
130 | public function getStrRoomTypes() |
||
134 | |||
135 | /** |
||
136 | * @param string $strRoomTypes |
||
137 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
138 | */ |
||
139 | public function setStrRoomTypes($strRoomTypes) |
||
144 | |||
145 | /** |
||
146 | * @return \DateTime |
||
147 | */ |
||
148 | public function getDtArrivalDate() |
||
160 | |||
161 | /** |
||
162 | * @param \DateTime $dtArrivalDate |
||
163 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
164 | */ |
||
165 | public function setDtArrivalDate(\DateTime $dtArrivalDate) |
||
170 | |||
171 | /** |
||
172 | * @return \DateTime |
||
173 | */ |
||
174 | public function getDtDepartureDate() |
||
186 | |||
187 | /** |
||
188 | * @param \DateTime $dtDepartureDate |
||
189 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
190 | */ |
||
191 | public function setDtDepartureDate(\DateTime $dtDepartureDate) |
||
196 | |||
197 | /** |
||
198 | * @return int |
||
199 | */ |
||
200 | public function getIntGuestCount() |
||
204 | |||
205 | /** |
||
206 | * @param int $intGuestCount |
||
207 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
208 | */ |
||
209 | public function setIntGuestCount($intGuestCount) |
||
214 | |||
215 | /** |
||
216 | * @return string |
||
217 | */ |
||
218 | public function getStrChildrens() |
||
222 | |||
223 | /** |
||
224 | * @param string $strChildrens |
||
225 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
226 | */ |
||
227 | public function setStrChildrens($strChildrens) |
||
232 | |||
233 | /** |
||
234 | * @return int |
||
235 | */ |
||
236 | public function getIntRateSpecial() |
||
240 | |||
241 | /** |
||
242 | * @param int $intRateSpecial |
||
243 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
244 | */ |
||
245 | public function setIntRateSpecial($intRateSpecial) |
||
250 | |||
251 | /** |
||
252 | * @return int |
||
253 | */ |
||
254 | public function getIntBuilding() |
||
258 | |||
259 | /** |
||
260 | * @param int $intBuilding |
||
261 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
262 | */ |
||
263 | public function setIntBuilding($intBuilding) |
||
268 | |||
269 | /** |
||
270 | * @return int |
||
271 | */ |
||
272 | public function getIntRoomQty() |
||
276 | |||
277 | /** |
||
278 | * @param int $intRoomQty |
||
279 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
280 | */ |
||
281 | public function setIntRoomQty($intRoomQty) |
||
286 | |||
287 | /** |
||
288 | * @return IAB2BMode |
||
289 | */ |
||
290 | public function getBackToBackMode() |
||
294 | |||
295 | /** |
||
296 | * @param IAB2BMode $BackToBackMode |
||
297 | * @return \Gueststream\PMS\IQWare\API\EvaluationThreaded |
||
298 | */ |
||
299 | public function setBackToBackMode($BackToBackMode) |
||
304 | } |
||
305 |
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.