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 | class cInfo |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var boolean $IsMarried |
||
10 | */ |
||
11 | protected $IsMarried = null; |
||
12 | |||
13 | /** |
||
14 | * @var int $Sex |
||
15 | */ |
||
16 | protected $Sex = null; |
||
17 | |||
18 | /** |
||
19 | * @var \DateTime $DateOfBirth |
||
20 | */ |
||
21 | protected $DateOfBirth = null; |
||
22 | |||
23 | /** |
||
24 | * @var string $PassportID |
||
25 | */ |
||
26 | protected $PassportID = null; |
||
27 | |||
28 | /** |
||
29 | * @var int $ID_Nationality |
||
30 | */ |
||
31 | protected $ID_Nationality = null; |
||
32 | |||
33 | /** |
||
34 | * @var string $PassportIssuingLocation |
||
35 | */ |
||
36 | protected $PassportIssuingLocation = null; |
||
37 | |||
38 | /** |
||
39 | * @var \DateTime $PassportExpireDate |
||
40 | */ |
||
41 | protected $PassportExpireDate = null; |
||
42 | |||
43 | /** |
||
44 | * @param boolean $IsMarried |
||
45 | * @param int $Sex |
||
46 | * @param \DateTime $DateOfBirth |
||
47 | * @param int $ID_Nationality |
||
48 | * @param \DateTime $PassportExpireDate |
||
49 | */ |
||
50 | View Code Duplication | public function __construct($IsMarried, $Sex, \DateTime $DateOfBirth, $ID_Nationality, \DateTime $PassportExpireDate) |
|
58 | |||
59 | /** |
||
60 | * @return boolean |
||
61 | */ |
||
62 | public function getIsMarried() |
||
66 | |||
67 | /** |
||
68 | * @param boolean $IsMarried |
||
69 | * @return \Gueststream\PMS\IQWare\API\cInfo |
||
70 | */ |
||
71 | public function setIsMarried($IsMarried) |
||
76 | |||
77 | /** |
||
78 | * @return int |
||
79 | */ |
||
80 | public function getSex() |
||
84 | |||
85 | /** |
||
86 | * @param int $Sex |
||
87 | * @return \Gueststream\PMS\IQWare\API\cInfo |
||
88 | */ |
||
89 | public function setSex($Sex) |
||
94 | |||
95 | /** |
||
96 | * @return \DateTime |
||
97 | */ |
||
98 | public function getDateOfBirth() |
||
110 | |||
111 | /** |
||
112 | * @param \DateTime $DateOfBirth |
||
113 | * @return \Gueststream\PMS\IQWare\API\cInfo |
||
114 | */ |
||
115 | public function setDateOfBirth(\DateTime $DateOfBirth) |
||
120 | |||
121 | /** |
||
122 | * @return string |
||
123 | */ |
||
124 | public function getPassportID() |
||
128 | |||
129 | /** |
||
130 | * @param string $PassportID |
||
131 | * @return \Gueststream\PMS\IQWare\API\cInfo |
||
132 | */ |
||
133 | public function setPassportID($PassportID) |
||
138 | |||
139 | /** |
||
140 | * @return int |
||
141 | */ |
||
142 | public function getID_Nationality() |
||
146 | |||
147 | /** |
||
148 | * @param int $ID_Nationality |
||
149 | * @return \Gueststream\PMS\IQWare\API\cInfo |
||
150 | */ |
||
151 | public function setID_Nationality($ID_Nationality) |
||
156 | |||
157 | /** |
||
158 | * @return string |
||
159 | */ |
||
160 | public function getPassportIssuingLocation() |
||
164 | |||
165 | /** |
||
166 | * @param string $PassportIssuingLocation |
||
167 | * @return \Gueststream\PMS\IQWare\API\cInfo |
||
168 | */ |
||
169 | public function setPassportIssuingLocation($PassportIssuingLocation) |
||
174 | |||
175 | /** |
||
176 | * @return \DateTime |
||
177 | */ |
||
178 | public function getPassportExpireDate() |
||
190 | |||
191 | /** |
||
192 | * @param \DateTime $PassportExpireDate |
||
193 | * @return \Gueststream\PMS\IQWare\API\cInfo |
||
194 | */ |
||
195 | public function setPassportExpireDate(\DateTime $PassportExpireDate) |
||
200 | } |
||
201 |
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.