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 Detail |
|
|
|
|||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var \DateTime $Date |
||
| 10 | */ |
||
| 11 | protected $Date = null; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var float $Amount |
||
| 15 | */ |
||
| 16 | protected $Amount = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var boolean $IsPecent |
||
| 20 | */ |
||
| 21 | protected $IsPecent = null; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param \DateTime $Date |
||
| 25 | * @param float $Amount |
||
| 26 | * @param boolean $IsPecent |
||
| 27 | */ |
||
| 28 | public function __construct(\DateTime $Date, $Amount, $IsPecent) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @return \DateTime |
||
| 37 | */ |
||
| 38 | public function getDate() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param \DateTime $Date |
||
| 53 | * @return \Gueststream\PMS\IQWare\API\Detail |
||
| 54 | */ |
||
| 55 | public function setDate(\DateTime $Date) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return float |
||
| 63 | */ |
||
| 64 | public function getAmount() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param float $Amount |
||
| 71 | * @return \Gueststream\PMS\IQWare\API\Detail |
||
| 72 | */ |
||
| 73 | public function setAmount($Amount) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return boolean |
||
| 81 | */ |
||
| 82 | public function getIsPecent() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param boolean $IsPecent |
||
| 89 | * @return \Gueststream\PMS\IQWare\API\Detail |
||
| 90 | */ |
||
| 91 | public function setIsPecent($IsPecent) |
||
| 96 | } |
||
| 97 |
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.