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 |
||
23 | View Code Duplication | class Payone_Settings_Data_ConfigFile_PaymentMethod_AmazonPay |
|
24 | extends Payone_Settings_Data_ConfigFile_PaymentMethod_Abstract |
||
25 | implements Payone_Settings_Data_ConfigFile_Interface |
||
26 | { |
||
27 | /** @var string */ |
||
28 | protected $key = Payone_Enum_ClearingType::AMAZONPAY; |
||
29 | /** @var string */ |
||
30 | protected $active = ''; |
||
31 | /** @var string */ |
||
32 | protected $newOrderStatus = ''; |
||
33 | /** @var string */ |
||
34 | protected $countries = ''; |
||
35 | /** @var string */ |
||
36 | protected $authorization = ''; |
||
37 | /** @var string */ |
||
38 | protected $mode = ''; |
||
39 | /** |
||
40 | * @param string $active |
||
41 | */ |
||
42 | public function setActive($active) |
||
46 | /** |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getActive() |
||
53 | /** |
||
54 | * @param string $authorization |
||
55 | */ |
||
56 | public function setAuthorization($authorization) |
||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getAuthorization() |
||
67 | /** |
||
68 | * @param string $countries |
||
69 | */ |
||
70 | public function setCountries($countries) |
||
74 | /** |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getCountries() |
||
81 | /** |
||
82 | * @param string $mode |
||
83 | */ |
||
84 | public function setMode($mode) |
||
88 | /** |
||
89 | * @return string |
||
90 | */ |
||
91 | public function getMode() |
||
95 | /** |
||
96 | * @param string $newOrderStatus |
||
97 | */ |
||
98 | public function setNewOrderStatus($newOrderStatus) |
||
102 | /** |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getNewOrderStatus() |
||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getClearingType() |
||
116 | /** |
||
117 | * @return string |
||
118 | */ |
||
119 | public function getKey() |
||
123 | } |
||
124 |
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.