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 DailyManualRates |
|
|
|||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var \DateTime $Date |
||
10 | */ |
||
11 | protected $Date = null; |
||
12 | |||
13 | /** |
||
14 | * @var float $ManualRate |
||
15 | */ |
||
16 | protected $ManualRate = null; |
||
17 | |||
18 | /** |
||
19 | * @var int $ID_RateReason |
||
20 | */ |
||
21 | protected $ID_RateReason = null; |
||
22 | |||
23 | /** |
||
24 | * @var int $ManualRateType |
||
25 | */ |
||
26 | protected $ManualRateType = null; |
||
27 | |||
28 | /** |
||
29 | * @param \DateTime $Date |
||
30 | * @param float $ManualRate |
||
31 | * @param int $ID_RateReason |
||
32 | * @param int $ManualRateType |
||
33 | */ |
||
34 | public function __construct(\DateTime $Date, $ManualRate, $ID_RateReason, $ManualRateType) |
||
41 | |||
42 | /** |
||
43 | * @return \DateTime |
||
44 | */ |
||
45 | public function getDate() |
||
57 | |||
58 | /** |
||
59 | * @param \DateTime $Date |
||
60 | * @return \Gueststream\PMS\IQWare\API\DailyManualRates |
||
61 | */ |
||
62 | public function setDate(\DateTime $Date) |
||
67 | |||
68 | /** |
||
69 | * @return float |
||
70 | */ |
||
71 | public function getManualRate() |
||
75 | |||
76 | /** |
||
77 | * @param float $ManualRate |
||
78 | * @return \Gueststream\PMS\IQWare\API\DailyManualRates |
||
79 | */ |
||
80 | public function setManualRate($ManualRate) |
||
85 | |||
86 | /** |
||
87 | * @return int |
||
88 | */ |
||
89 | public function getID_RateReason() |
||
93 | |||
94 | /** |
||
95 | * @param int $ID_RateReason |
||
96 | * @return \Gueststream\PMS\IQWare\API\DailyManualRates |
||
97 | */ |
||
98 | public function setID_RateReason($ID_RateReason) |
||
103 | |||
104 | /** |
||
105 | * @return int |
||
106 | */ |
||
107 | public function getManualRateType() |
||
111 | |||
112 | /** |
||
113 | * @param int $ManualRateType |
||
114 | * @return \Gueststream\PMS\IQWare\API\DailyManualRates |
||
115 | */ |
||
116 | public function setManualRateType($ManualRateType) |
||
121 | } |
||
122 |
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.