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 |
||
20 | class Gateway extends AbstractGateway |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | 2 | public function getName() |
|
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | 58 | public function getDefaultParameters() |
|
41 | |||
42 | /** |
||
43 | * Get the unified purse. |
||
44 | * |
||
45 | * @return string merchant purse |
||
46 | */ |
||
47 | 16 | public function getPurse() |
|
51 | |||
52 | /** |
||
53 | * Set the unified purse. |
||
54 | * |
||
55 | * @param $value |
||
56 | * @return self |
||
57 | */ |
||
58 | 58 | public function setPurse($value) |
|
62 | |||
63 | /** |
||
64 | * Get the merchant purse. |
||
65 | * |
||
66 | * @return string merchant purse |
||
67 | */ |
||
68 | 16 | public function getCheckoutId() |
|
72 | |||
73 | /** |
||
74 | * Set the merchant purse. |
||
75 | * |
||
76 | * @param string $value merchant purse |
||
77 | * |
||
78 | * @return self |
||
79 | */ |
||
80 | 58 | public function setCheckoutId($value) |
|
84 | |||
85 | /** |
||
86 | * Get the secret key. |
||
87 | * |
||
88 | * @return string secret |
||
89 | */ |
||
90 | 4 | public function getSecret() |
|
94 | |||
95 | /** |
||
96 | * Set the secret. |
||
97 | * |
||
98 | * @param string $value secret |
||
99 | * |
||
100 | * @return self |
||
101 | */ |
||
102 | 58 | public function setSecret($value) |
|
106 | |||
107 | /** |
||
108 | * @param array $parameters |
||
109 | * |
||
110 | * @return \Omnipay\InterKassa\Message\PurchaseRequest|\Omnipay\InterKassa\Message\OldPurchaseRequest |
||
111 | */ |
||
112 | 6 | View Code Duplication | public function purchase(array $parameters = []) |
122 | |||
123 | /** |
||
124 | * @param array $parameters |
||
125 | * |
||
126 | * @return \Omnipay\InterKassa\Message\CompletePurchaseRequest|\Omnipay\InterKassa\Message\OldCompletePurchaseRequest |
||
127 | */ |
||
128 | 6 | View Code Duplication | public function completePurchase(array $parameters = []) |
138 | |||
139 | /** |
||
140 | * Whether the request is designed for API v2. |
||
141 | * @return boolean |
||
142 | */ |
||
143 | 12 | public function isOldApi() |
|
147 | } |
||
148 |
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.