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 getRateElements |
|
|
|
|||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var int $intGUID |
||
| 10 | */ |
||
| 11 | protected $intGUID = null; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var int $intRateCodeID |
||
| 15 | */ |
||
| 16 | protected $intRateCodeID = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var \DateTime $arrDate |
||
| 20 | */ |
||
| 21 | protected $arrDate = null; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var \DateTime $depDate |
||
| 25 | */ |
||
| 26 | protected $depDate = null; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string $strISOLanguage |
||
| 30 | */ |
||
| 31 | protected $strISOLanguage = null; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param int $intGUID |
||
| 35 | * @param int $intRateCodeID |
||
| 36 | * @param \DateTime $arrDate |
||
| 37 | * @param \DateTime $depDate |
||
| 38 | * @param string $strISOLanguage |
||
| 39 | */ |
||
| 40 | public function __construct($intGUID, $intRateCodeID, \DateTime $arrDate, \DateTime $depDate, $strISOLanguage) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @return int |
||
| 51 | */ |
||
| 52 | public function getIntGUID() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param int $intGUID |
||
| 59 | * @return \Gueststream\PMS\IQWare\API\getRateElements |
||
| 60 | */ |
||
| 61 | public function setIntGUID($intGUID) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return int |
||
| 69 | */ |
||
| 70 | public function getIntRateCodeID() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param int $intRateCodeID |
||
| 77 | * @return \Gueststream\PMS\IQWare\API\getRateElements |
||
| 78 | */ |
||
| 79 | public function setIntRateCodeID($intRateCodeID) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return \DateTime |
||
| 87 | */ |
||
| 88 | public function getArrDate() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @param \DateTime $arrDate |
||
| 103 | * @return \Gueststream\PMS\IQWare\API\getRateElements |
||
| 104 | */ |
||
| 105 | public function setArrDate(\DateTime $arrDate) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @return \DateTime |
||
| 113 | */ |
||
| 114 | public function getDepDate() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param \DateTime $depDate |
||
| 129 | * @return \Gueststream\PMS\IQWare\API\getRateElements |
||
| 130 | */ |
||
| 131 | public function setDepDate(\DateTime $depDate) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | public function getStrISOLanguage() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param string $strISOLanguage |
||
| 147 | * @return \Gueststream\PMS\IQWare\API\getRateElements |
||
| 148 | */ |
||
| 149 | public function setStrISOLanguage($strISOLanguage) |
||
| 154 | } |
||
| 155 |
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.