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 cRateDaily |
|
|
|
|||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var \DateTime $Date |
||
| 10 | */ |
||
| 11 | protected $Date = null; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var int $ID_RateCode |
||
| 15 | */ |
||
| 16 | protected $ID_RateCode = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param \DateTime $Date |
||
| 20 | * @param int $ID_RateCode |
||
| 21 | */ |
||
| 22 | public function __construct(\DateTime $Date, $ID_RateCode) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @return \DateTime |
||
| 30 | */ |
||
| 31 | public function getDate() |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param \DateTime $Date |
||
| 46 | * @return \Gueststream\PMS\IQWare\API\cRateDaily |
||
| 47 | */ |
||
| 48 | public function setDate(\DateTime $Date) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return int |
||
| 56 | */ |
||
| 57 | public function getID_RateCode() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @param int $ID_RateCode |
||
| 64 | * @return \Gueststream\PMS\IQWare\API\cRateDaily |
||
| 65 | */ |
||
| 66 | public function setID_RateCode($ID_RateCode) |
||
| 71 | } |
||
| 72 |
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.