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 WebRes_getAccountInfos |
|
|
|||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var int $intGUID |
||
10 | */ |
||
11 | protected $intGUID = null; |
||
12 | |||
13 | /** |
||
14 | * @var int $intAccNo |
||
15 | */ |
||
16 | protected $intAccNo = null; |
||
17 | |||
18 | /** |
||
19 | * @var string $strPassword |
||
20 | */ |
||
21 | protected $strPassword = null; |
||
22 | |||
23 | /** |
||
24 | * @param int $intGUID |
||
25 | * @param int $intAccNo |
||
26 | * @param string $strPassword |
||
27 | */ |
||
28 | public function __construct($intGUID, $intAccNo, $strPassword) |
||
34 | |||
35 | /** |
||
36 | * @return int |
||
37 | */ |
||
38 | public function getIntGUID() |
||
42 | |||
43 | /** |
||
44 | * @param int $intGUID |
||
45 | * @return \Gueststream\PMS\IQWare\API\WebRes_getAccountInfos |
||
46 | */ |
||
47 | public function setIntGUID($intGUID) |
||
52 | |||
53 | /** |
||
54 | * @return int |
||
55 | */ |
||
56 | public function getIntAccNo() |
||
60 | |||
61 | /** |
||
62 | * @param int $intAccNo |
||
63 | * @return \Gueststream\PMS\IQWare\API\WebRes_getAccountInfos |
||
64 | */ |
||
65 | public function setIntAccNo($intAccNo) |
||
70 | |||
71 | /** |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getStrPassword() |
||
78 | |||
79 | /** |
||
80 | * @param string $strPassword |
||
81 | * @return \Gueststream\PMS\IQWare\API\WebRes_getAccountInfos |
||
82 | */ |
||
83 | public function setStrPassword($strPassword) |
||
88 | } |
||
89 |
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.