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 OaccTelephone |
|
|
|||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var int $PhoneID |
||
10 | */ |
||
11 | protected $PhoneID = null; |
||
12 | |||
13 | /** |
||
14 | * @var int $PhoneType |
||
15 | */ |
||
16 | protected $PhoneType = null; |
||
17 | |||
18 | /** |
||
19 | * @var string $PhoneNo |
||
20 | */ |
||
21 | protected $PhoneNo = null; |
||
22 | |||
23 | /** |
||
24 | * @param int $PhoneID |
||
25 | * @param int $PhoneType |
||
26 | */ |
||
27 | public function __construct($PhoneID, $PhoneType) |
||
32 | |||
33 | /** |
||
34 | * @return int |
||
35 | */ |
||
36 | public function getPhoneID() |
||
40 | |||
41 | /** |
||
42 | * @param int $PhoneID |
||
43 | * |
||
44 | *@return \Gueststream\PMS\IQWare\API\OaccTelephone |
||
45 | */ |
||
46 | public function setPhoneID($PhoneID) |
||
51 | |||
52 | /** |
||
53 | * @return int |
||
54 | */ |
||
55 | public function getPhoneType() |
||
59 | |||
60 | /** |
||
61 | * @param int $PhoneType |
||
62 | * |
||
63 | *@return \Gueststream\PMS\IQWare\API\OaccTelephone |
||
64 | */ |
||
65 | public function setPhoneType($PhoneType) |
||
70 | |||
71 | /** |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getPhoneNo() |
||
78 | |||
79 | /** |
||
80 | * @param string $PhoneNo |
||
81 | * |
||
82 | *@return \Gueststream\PMS\IQWare\API\OaccTelephone |
||
83 | */ |
||
84 | public function setPhoneNo($PhoneNo) |
||
89 | } |
||
90 |
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.