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 GetUnitReservations |
|
|
|
|||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var int $intGUID |
||
| 10 | */ |
||
| 11 | protected $intGUID = null; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var string $userName |
||
| 15 | */ |
||
| 16 | protected $userName = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var string $password |
||
| 20 | */ |
||
| 21 | protected $password = null; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var int $ID_CondoOwner |
||
| 25 | */ |
||
| 26 | protected $ID_CondoOwner = null; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var int $ID_Admin |
||
| 30 | */ |
||
| 31 | protected $ID_Admin = null; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var \DateTime $StartDate |
||
| 35 | */ |
||
| 36 | protected $StartDate = null; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var \DateTime $EndDate |
||
| 40 | */ |
||
| 41 | protected $EndDate = null; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param int $intGUID |
||
| 45 | * @param string $userName |
||
| 46 | * @param string $password |
||
| 47 | * @param int $ID_CondoOwner |
||
| 48 | * @param int $ID_Admin |
||
| 49 | * @param \DateTime $StartDate |
||
| 50 | * @param \DateTime $EndDate |
||
| 51 | */ |
||
| 52 | public function __construct($intGUID, $userName, $password, $ID_CondoOwner, $ID_Admin, \DateTime $StartDate, \DateTime $EndDate) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return int |
||
| 65 | */ |
||
| 66 | public function getIntGUID() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param int $intGUID |
||
| 73 | * @return \Gueststream\PMS\IQWare\API\GetUnitReservations |
||
| 74 | */ |
||
| 75 | public function setIntGUID($intGUID) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function getUserName() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param string $userName |
||
| 91 | * @return \Gueststream\PMS\IQWare\API\GetUnitReservations |
||
| 92 | */ |
||
| 93 | public function setUserName($userName) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | public function getPassword() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param string $password |
||
| 109 | * @return \Gueststream\PMS\IQWare\API\GetUnitReservations |
||
| 110 | */ |
||
| 111 | public function setPassword($password) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return int |
||
| 119 | */ |
||
| 120 | public function getID_CondoOwner() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param int $ID_CondoOwner |
||
| 127 | * @return \Gueststream\PMS\IQWare\API\GetUnitReservations |
||
| 128 | */ |
||
| 129 | public function setID_CondoOwner($ID_CondoOwner) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @return int |
||
| 137 | */ |
||
| 138 | public function getID_Admin() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @param int $ID_Admin |
||
| 145 | * @return \Gueststream\PMS\IQWare\API\GetUnitReservations |
||
| 146 | */ |
||
| 147 | public function setID_Admin($ID_Admin) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @return \DateTime |
||
| 155 | */ |
||
| 156 | public function getStartDate() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @param \DateTime $StartDate |
||
| 171 | * @return \Gueststream\PMS\IQWare\API\GetUnitReservations |
||
| 172 | */ |
||
| 173 | public function setStartDate(\DateTime $StartDate) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return \DateTime |
||
| 181 | */ |
||
| 182 | public function getEndDate() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @param \DateTime $EndDate |
||
| 197 | * @return \Gueststream\PMS\IQWare\API\GetUnitReservations |
||
| 198 | */ |
||
| 199 | public function setEndDate(\DateTime $EndDate) |
||
| 204 | } |
||
| 205 |
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.