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 AvailabilityOverview |
|
|
|
|||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var int $ID_RateCode |
||
| 10 | */ |
||
| 11 | protected $ID_RateCode = null; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var float $RateAmount |
||
| 15 | */ |
||
| 16 | protected $RateAmount = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param int $ID_RateCode |
||
| 20 | * @param float $RateAmount |
||
| 21 | */ |
||
| 22 | public function __construct($ID_RateCode, $RateAmount) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @return int |
||
| 30 | */ |
||
| 31 | public function getID_RateCode() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param int $ID_RateCode |
||
| 38 | * @return \Gueststream\PMS\IQWare\API\AvailabilityOverview |
||
| 39 | */ |
||
| 40 | public function setID_RateCode($ID_RateCode) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return float |
||
| 48 | */ |
||
| 49 | public function getRateAmount() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param float $RateAmount |
||
| 56 | * @return \Gueststream\PMS\IQWare\API\AvailabilityOverview |
||
| 57 | */ |
||
| 58 | public function setRateAmount($RateAmount) |
||
| 63 | } |
||
| 64 |
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.