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 cAddresses |
|
|
|||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var cAddress $Profile |
||
10 | */ |
||
11 | protected $Profile = null; |
||
12 | |||
13 | /** |
||
14 | * @var cAddress $BkgContact |
||
15 | */ |
||
16 | protected $BkgContact = null; |
||
17 | |||
18 | /** |
||
19 | * @var cAddress $Billing |
||
20 | */ |
||
21 | protected $Billing = null; |
||
22 | |||
23 | |||
24 | public function __construct() |
||
28 | |||
29 | /** |
||
30 | * @return cAddress |
||
31 | */ |
||
32 | public function getProfile() |
||
36 | |||
37 | /** |
||
38 | * @param cAddress $Profile |
||
39 | * @return \Gueststream\PMS\IQWare\API\cAddresses |
||
40 | */ |
||
41 | public function setProfile($Profile) |
||
46 | |||
47 | /** |
||
48 | * @return cAddress |
||
49 | */ |
||
50 | public function getBkgContact() |
||
54 | |||
55 | /** |
||
56 | * @param cAddress $BkgContact |
||
57 | * @return \Gueststream\PMS\IQWare\API\cAddresses |
||
58 | */ |
||
59 | public function setBkgContact($BkgContact) |
||
64 | |||
65 | /** |
||
66 | * @return cAddress |
||
67 | */ |
||
68 | public function getBilling() |
||
72 | |||
73 | /** |
||
74 | * @param cAddress $Billing |
||
75 | * @return \Gueststream\PMS\IQWare\API\cAddresses |
||
76 | */ |
||
77 | public function setBilling($Billing) |
||
82 | } |
||
83 |
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.