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 |
||
36 | abstract class PayoneMethod extends BaseMethod |
||
37 | { |
||
38 | /** |
||
39 | * Returns clearingtype |
||
40 | * |
||
41 | * @return string |
||
42 | * @throws LocalizedException |
||
43 | */ |
||
44 | public function getClearingtype() |
||
48 | |||
49 | /** |
||
50 | * Returns authorization-mode |
||
51 | * preauthorization or authorization |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getAuthorizationMode() |
||
63 | |||
64 | /** |
||
65 | * Method handling the debit request and the response |
||
66 | * |
||
67 | * @param InfoInterface $payment |
||
68 | * @param float $amount |
||
69 | * @return void |
||
70 | * @throws LocalizedException |
||
71 | */ |
||
72 | View Code Duplication | protected function sendPayoneDebit(InfoInterface $payment, $amount) |
|
81 | |||
82 | /** |
||
83 | * Method handling the capture request and the response |
||
84 | * |
||
85 | * @param InfoInterface $payment |
||
86 | * @param float $amount |
||
87 | * @return void |
||
88 | * @throws LocalizedException |
||
89 | */ |
||
90 | View Code Duplication | protected function sendPayoneCapture(InfoInterface $payment, $amount) |
|
99 | |||
100 | /** |
||
101 | * Method handling the authorization request and the response |
||
102 | * |
||
103 | * @param InfoInterface $payment |
||
104 | * @param float $amount |
||
105 | * @return void |
||
106 | * @throws LocalizedException |
||
107 | */ |
||
108 | protected function sendPayoneAuthorization(InfoInterface $payment, $amount) |
||
125 | |||
126 | /** |
||
127 | * Perform certain actions with the response |
||
128 | * |
||
129 | * @param array $aResponse |
||
130 | * @return void |
||
131 | */ |
||
132 | protected function handleResponse($aResponse) |
||
136 | |||
137 | /** |
||
138 | * Returns operationmode live or test for this payment method |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getOperationMode() |
||
146 | |||
147 | /** |
||
148 | * Return parameters specific to this payment type |
||
149 | * |
||
150 | * @param Order $oOrder |
||
151 | * @return array |
||
152 | */ |
||
153 | public function getPaymentSpecificParameters(Order $oOrder) |
||
157 | |||
158 | /** |
||
159 | * Return success url for redirect payment types |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getSuccessUrl() |
||
167 | |||
168 | /** |
||
169 | * Return cancel url for redirect payment types |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getCancelUrl() |
||
177 | |||
178 | /** |
||
179 | * Return error url for redirect payment types |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | public function getErrorUrl() |
||
187 | |||
188 | /** |
||
189 | * Return if redirect urls have to be added to the authroization request |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function needsRedirectUrls() |
||
197 | |||
198 | /** |
||
199 | * Return if invoice data has to be added to the authroization request |
||
200 | * |
||
201 | * @return bool |
||
202 | */ |
||
203 | public function needsProductInfo() |
||
207 | |||
208 | /** |
||
209 | * Get config parameter for this payment type |
||
210 | * |
||
211 | * @param string $sParam |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getCustomConfigParam($sParam) |
||
218 | |||
219 | /** |
||
220 | * Returns if global PAYONE config is used for this payment type |
||
221 | * |
||
222 | * @return bool |
||
223 | */ |
||
224 | public function hasCustomConfig() |
||
231 | |||
232 | /** |
||
233 | * Return if this payment method is part of a group |
||
234 | * |
||
235 | * @return bool |
||
236 | */ |
||
237 | public function isGroupMethod() |
||
244 | |||
245 | /** |
||
246 | * Returns group identifier |
||
247 | * |
||
248 | * @return string|bool |
||
249 | */ |
||
250 | public function getGroupName() |
||
254 | |||
255 | /** |
||
256 | * Returns group identifier |
||
257 | * |
||
258 | * @return string|bool |
||
259 | */ |
||
260 | public function getSubType() |
||
264 | |||
265 | /** |
||
266 | * Return parameters specific to this payment sub type |
||
267 | * |
||
268 | * @param Order $oOrder |
||
269 | * @return array |
||
270 | */ |
||
271 | public function getSubTypeSpecificParameters(Order $oOrder) |
||
275 | |||
276 | /** |
||
277 | * Formats the reference number if needed for this payment method |
||
278 | * Needed for Paydirekt |
||
279 | * |
||
280 | * @param string $sRefNr |
||
281 | * @return string |
||
282 | */ |
||
283 | public function formatReferenceNumber($sRefNr) |
||
287 | |||
288 | /** |
||
289 | * Return max length of narrative text |
||
290 | * |
||
291 | * @return int |
||
292 | */ |
||
293 | public function getNarrativeTextMaxLength() |
||
297 | } |
||
298 |
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.