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 Evaluation |
|
|
|
|||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var int $ID_Stay |
||
| 10 | */ |
||
| 11 | protected $ID_Stay = null; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var int $ID_RoomType |
||
| 15 | */ |
||
| 16 | protected $ID_RoomType = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var int $ID_RateCode |
||
| 20 | */ |
||
| 21 | protected $ID_RateCode = null; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var float $TotalStay |
||
| 25 | */ |
||
| 26 | protected $TotalStay = null; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var float $TotalStayTx |
||
| 30 | */ |
||
| 31 | protected $TotalStayTx = null; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var float $FirstNight |
||
| 35 | */ |
||
| 36 | protected $FirstNight = null; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var float $FirstNightTx |
||
| 40 | */ |
||
| 41 | protected $FirstNightTx = null; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var float $FirstNightOthers |
||
| 45 | */ |
||
| 46 | protected $FirstNightOthers = null; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var float $AvgNight |
||
| 50 | */ |
||
| 51 | protected $AvgNight = null; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var float $AvgNightTx |
||
| 55 | */ |
||
| 56 | protected $AvgNightTx = null; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var float $TotalRate |
||
| 60 | */ |
||
| 61 | protected $TotalRate = null; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var float $TotalOthers |
||
| 65 | */ |
||
| 66 | protected $TotalOthers = null; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var ArrayOfDailyEvaluation $DailyEvaluations |
||
| 70 | */ |
||
| 71 | protected $DailyEvaluations = null; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param int $ID_Stay |
||
| 75 | * @param int $ID_RoomType |
||
| 76 | * @param int $ID_RateCode |
||
| 77 | * @param float $TotalStay |
||
| 78 | * @param float $TotalStayTx |
||
| 79 | * @param float $FirstNight |
||
| 80 | * @param float $FirstNightTx |
||
| 81 | * @param float $FirstNightOthers |
||
| 82 | * @param float $AvgNight |
||
| 83 | * @param float $AvgNightTx |
||
| 84 | * @param float $TotalRate |
||
| 85 | * @param float $TotalOthers |
||
| 86 | */ |
||
| 87 | public function __construct($ID_Stay, $ID_RoomType, $ID_RateCode, $TotalStay, $TotalStayTx, $FirstNight, $FirstNightTx, $FirstNightOthers, $AvgNight, $AvgNightTx, $TotalRate, $TotalOthers) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @return int |
||
| 105 | */ |
||
| 106 | public function getID_Stay() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param int $ID_Stay |
||
| 113 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 114 | */ |
||
| 115 | public function setID_Stay($ID_Stay) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return int |
||
| 123 | */ |
||
| 124 | public function getID_RoomType() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param int $ID_RoomType |
||
| 131 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 132 | */ |
||
| 133 | public function setID_RoomType($ID_RoomType) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return int |
||
| 141 | */ |
||
| 142 | public function getID_RateCode() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param int $ID_RateCode |
||
| 149 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 150 | */ |
||
| 151 | public function setID_RateCode($ID_RateCode) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return float |
||
| 159 | */ |
||
| 160 | public function getTotalStay() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @param float $TotalStay |
||
| 167 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 168 | */ |
||
| 169 | public function setTotalStay($TotalStay) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return float |
||
| 177 | */ |
||
| 178 | public function getTotalStayTx() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param float $TotalStayTx |
||
| 185 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 186 | */ |
||
| 187 | public function setTotalStayTx($TotalStayTx) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return float |
||
| 195 | */ |
||
| 196 | public function getFirstNight() |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @param float $FirstNight |
||
| 203 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 204 | */ |
||
| 205 | public function setFirstNight($FirstNight) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @return float |
||
| 213 | */ |
||
| 214 | public function getFirstNightTx() |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @param float $FirstNightTx |
||
| 221 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 222 | */ |
||
| 223 | public function setFirstNightTx($FirstNightTx) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return float |
||
| 231 | */ |
||
| 232 | public function getFirstNightOthers() |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @param float $FirstNightOthers |
||
| 239 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 240 | */ |
||
| 241 | public function setFirstNightOthers($FirstNightOthers) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @return float |
||
| 249 | */ |
||
| 250 | public function getAvgNight() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @param float $AvgNight |
||
| 257 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 258 | */ |
||
| 259 | public function setAvgNight($AvgNight) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @return float |
||
| 267 | */ |
||
| 268 | public function getAvgNightTx() |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @param float $AvgNightTx |
||
| 275 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 276 | */ |
||
| 277 | public function setAvgNightTx($AvgNightTx) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @return float |
||
| 285 | */ |
||
| 286 | public function getTotalRate() |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @param float $TotalRate |
||
| 293 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 294 | */ |
||
| 295 | public function setTotalRate($TotalRate) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @return float |
||
| 303 | */ |
||
| 304 | public function getTotalOthers() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @param float $TotalOthers |
||
| 311 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 312 | */ |
||
| 313 | public function setTotalOthers($TotalOthers) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @return ArrayOfDailyEvaluation |
||
| 321 | */ |
||
| 322 | public function getDailyEvaluations() |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @param ArrayOfDailyEvaluation $DailyEvaluations |
||
| 329 | * @return \Gueststream\PMS\IQWare\API\Evaluation |
||
| 330 | */ |
||
| 331 | public function setDailyEvaluations($DailyEvaluations) |
||
| 336 | } |
||
| 337 |
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.