Total Complexity | 55 |
Total Lines | 427 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like PayoneMethod often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PayoneMethod, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
38 | abstract class PayoneMethod extends BaseMethod |
||
39 | { |
||
40 | /** |
||
41 | * Returns clearingtype |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | public function getClearingtype() |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Returns wallettype |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getWallettype() |
||
56 | { |
||
57 | return $this->sWallettype; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Returns authorization-mode |
||
62 | * preauthorization or authorization |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | public function getAuthorizationMode() |
||
67 | { |
||
68 | $sRequestType = $this->shopHelper->getConfigParam('request_type'); |
||
69 | if ($this->hasCustomConfig()) { |
||
70 | $sCustomRequestType = $this->getCustomConfigParam('request_type'); |
||
71 | if (!empty($sCustomRequestType)) { |
||
72 | $sRequestType = $sCustomRequestType; |
||
73 | } |
||
74 | } |
||
75 | return $sRequestType; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Method handling the debit request and the response |
||
80 | * |
||
81 | * @param InfoInterface $payment |
||
82 | * @param float $amount |
||
83 | * @return void |
||
84 | * @throws LocalizedException |
||
85 | */ |
||
86 | protected function sendPayoneDebit(InfoInterface $payment, $amount) |
||
87 | { |
||
88 | $aResponse = $this->debitRequest->sendRequest($this, $payment, $amount); |
||
89 | if (!$aResponse) { |
||
90 | throw new LocalizedException(__('Unkown error')); |
||
91 | } elseif ($aResponse['status'] == 'ERROR') { |
||
92 | $this->checkoutSession->setPayoneDebitRequest($this->debitRequest->getParameters()); |
||
93 | $this->checkoutSession->setPayoneDebitResponse($this->debitRequest->getResponse()); |
||
94 | $this->checkoutSession->setPayoneDebitOrderId($this->debitRequest->getOrderId()); |
||
95 | throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage'])); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Method handling the capture request and the response |
||
101 | * |
||
102 | * @param InfoInterface $payment |
||
103 | * @param float $amount |
||
104 | * @return void |
||
105 | * @throws LocalizedException |
||
106 | */ |
||
107 | protected function sendPayoneCapture(InfoInterface $payment, $amount) |
||
108 | { |
||
109 | $aResponse = $this->captureRequest->sendRequest($this, $payment, $amount); |
||
110 | if (!$aResponse) {// response not existing |
||
111 | throw new LocalizedException(__('Unkown error')); |
||
112 | } elseif ($aResponse['status'] == 'ERROR') {// request returned an error |
||
113 | throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage'])); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Removes status flag used during checkout process from session |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | protected function unsetSessionStatusFlags() { |
||
123 | $this->checkoutSession->unsPayoneRedirectUrl(); |
||
124 | $this->checkoutSession->unsPayoneRedirectedPaymentMethod(); |
||
125 | $this->checkoutSession->unsPayoneCanceledPaymentMethod(); |
||
126 | $this->checkoutSession->unsPayoneIsError(); |
||
127 | $this->checkoutSession->unsShowAmazonPendingNotice(); |
||
128 | $this->checkoutSession->unsAmazonRetryAsync(); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Method handling the authorization request and the response |
||
133 | * |
||
134 | * @param InfoInterface $payment |
||
135 | * @param float $amount |
||
136 | * @return void |
||
137 | * @throws LocalizedException |
||
138 | */ |
||
139 | protected function sendPayoneAuthorization(InfoInterface $payment, $amount) |
||
164 | } |
||
165 | } |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Perform certain actions with the response |
||
170 | * Extension hook for certain payment methods |
||
171 | * |
||
172 | * @param array $aResponse |
||
173 | * @param Order $oOrder |
||
174 | * @param float $amount |
||
175 | * @return array |
||
176 | */ |
||
177 | protected function handleResponse($aResponse, Order $oOrder, $amount) |
||
178 | { |
||
179 | $aAddData = $oOrder->getPayment()->getAdditionalInformation(); |
||
180 | if (!empty($aAddData['iban'])) { |
||
181 | $oOrder->getPayment()->setAdditionalInformation('iban', $this->toolkitHelper->maskIban($aAddData['iban'])); |
||
182 | } |
||
183 | return $aResponse; |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Convert DataObject to needed array format |
||
188 | * Hook for overriding in specific payment type class |
||
189 | * |
||
190 | * @param DataObject $data |
||
191 | * @return array |
||
192 | */ |
||
193 | protected function getPaymentStorageData(DataObject $data) |
||
194 | { |
||
195 | return []; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * Check config and save payment data |
||
200 | * |
||
201 | * @param DataObject $data |
||
202 | * @return void |
||
203 | */ |
||
204 | protected function handlePaymentDataStorage(DataObject $data) |
||
205 | { |
||
206 | if ((bool)$this->getCustomConfigParam('save_data_enabled') === true) { |
||
207 | $aPaymentData = $this->getPaymentStorageData($data); |
||
208 | $iCustomerId = $this->checkoutSession->getQuote()->getCustomerId(); |
||
209 | if (!empty($aPaymentData) && $iCustomerId) { |
||
210 | $this->savedPaymentData->addSavedPaymentData($iCustomerId, $this->getCode(), $aPaymentData); |
||
211 | } |
||
212 | } |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Returns operationmode live or test for this payment method |
||
217 | * |
||
218 | * @return string |
||
219 | */ |
||
220 | public function getOperationMode() |
||
221 | { |
||
222 | return $this->getCustomConfigParam('mode'); |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * Return parameters specific to this payment type |
||
227 | * |
||
228 | * @param Order $oOrder |
||
229 | * @return array |
||
230 | */ |
||
231 | public function getPaymentSpecificParameters(Order $oOrder) |
||
232 | { |
||
233 | return []; // filled in child classes |
||
234 | } |
||
235 | |||
236 | /** |
||
237 | * Return capture parameters specific to this payment type |
||
238 | * |
||
239 | * @param Order $oOrder |
||
240 | * @return array |
||
241 | */ |
||
242 | public function getPaymentSpecificCaptureParameters(Order $oOrder) |
||
243 | { |
||
244 | return []; // filled in child classes |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * Return debit parameters specific to this payment type |
||
249 | * |
||
250 | * @param Order $oOrder |
||
251 | * @return array |
||
252 | */ |
||
253 | public function getPaymentSpecificDebitParameters(Order $oOrder) |
||
254 | { |
||
255 | return []; // filled in child classes |
||
256 | } |
||
257 | |||
258 | /** |
||
259 | * Return success url for redirect payment types |
||
260 | * |
||
261 | * @param Order $oOrder |
||
262 | * @return string |
||
263 | */ |
||
264 | public function getSuccessUrl(?Order $oOrder = null) |
||
265 | { |
||
266 | $sAddedParams = ''; |
||
267 | if ($oOrder !== null) { |
||
268 | $sAddedParams = '?incrementId='.$oOrder->getIncrementId(); |
||
269 | } |
||
270 | return $this->url->getUrl('payone/onepage/returned').$sAddedParams; |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Return cancel url for redirect payment types |
||
275 | * |
||
276 | * @return string |
||
277 | */ |
||
278 | public function getCancelUrl() |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * Return error url for redirect payment types |
||
285 | * |
||
286 | * @return string |
||
287 | */ |
||
288 | public function getErrorUrl() |
||
289 | { |
||
290 | return $this->url->getUrl('payone/onepage/cancel?error=1'); |
||
291 | } |
||
292 | |||
293 | /** |
||
294 | * Return if redirect urls have to be added to the authroization request |
||
295 | * |
||
296 | * @return bool |
||
297 | */ |
||
298 | public function needsRedirectUrls() |
||
299 | { |
||
300 | return $this->blNeedsRedirectUrls; |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * Return if transaction_param has to be added to the authroization request |
||
305 | * |
||
306 | * @return bool |
||
307 | */ |
||
308 | public function needsTransactionParam() |
||
309 | { |
||
310 | return $this->blNeedsTransactionParam; |
||
311 | } |
||
312 | |||
313 | /** |
||
314 | * Return if invoice data has to be added to the authroization request |
||
315 | * |
||
316 | * @return bool |
||
317 | */ |
||
318 | public function needsProductInfo() |
||
321 | } |
||
322 | |||
323 | |||
324 | /** |
||
325 | * Return if bank data has to be added to the debit request |
||
326 | * |
||
327 | * @return bool |
||
328 | */ |
||
329 | public function needsSepaDataOnDebit() |
||
330 | { |
||
331 | return $this->blNeedsSepaDataOnDebit; |
||
332 | } |
||
333 | |||
334 | /** |
||
335 | * Get config parameter for this payment type |
||
336 | * |
||
337 | * @param string $sParam |
||
338 | * @param string $sStoreCode |
||
339 | * @return string |
||
340 | */ |
||
341 | public function getCustomConfigParam($sParam, $sStoreCode = null) |
||
342 | { |
||
343 | if ($sStoreCode === null) { |
||
344 | $sStoreCode = $this->getStoreCode(); |
||
345 | } |
||
346 | return $this->shopHelper->getConfigParam($sParam, $this->getCode(), 'payone_payment', $sStoreCode); |
||
347 | } |
||
348 | |||
349 | /** |
||
350 | * Trys to retrieve the storecode from the order |
||
351 | * |
||
352 | * @return string|null |
||
353 | */ |
||
354 | protected function getStoreCode() |
||
355 | { |
||
356 | try { |
||
357 | $oInfoInstance = $this->getInfoInstance(); |
||
358 | if (empty($oInfoInstance)) { |
||
359 | return null; |
||
360 | } |
||
361 | } catch (\Exception $oExc) { |
||
362 | return null; |
||
363 | } |
||
364 | |||
365 | $oOrder = $oInfoInstance->getOrder(); |
||
366 | if (empty($oOrder)) { |
||
367 | $oOrder = $oInfoInstance->getQuote(); |
||
368 | if (empty($oOrder)) { |
||
369 | return null; |
||
370 | } |
||
371 | } |
||
372 | |||
373 | $oStore = $oOrder->getStore(); |
||
374 | if (empty($oStore)) { |
||
375 | return null; |
||
376 | } |
||
377 | return $oStore->getCode(); |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * Returns if global PAYONE config is used for this payment type |
||
382 | * |
||
383 | * @return bool |
||
384 | */ |
||
385 | public function hasCustomConfig() |
||
386 | { |
||
387 | if ($this->getCustomConfigParam('use_global') == '0') {// has non-global config |
||
388 | return true; |
||
389 | } |
||
390 | return false; |
||
391 | } |
||
392 | |||
393 | /** |
||
394 | * Return if this payment method is part of a group |
||
395 | * |
||
396 | * @return bool |
||
397 | */ |
||
398 | public function isGroupMethod() |
||
399 | { |
||
400 | if ($this->sGroupName === false) { |
||
401 | return false; |
||
402 | } |
||
403 | return true; |
||
404 | } |
||
405 | |||
406 | /** |
||
407 | * Returns group identifier |
||
408 | * |
||
409 | * @return string|bool |
||
410 | */ |
||
411 | public function getGroupName() |
||
412 | { |
||
413 | return $this->sGroupName; |
||
414 | } |
||
415 | |||
416 | /** |
||
417 | * Returns group identifier |
||
418 | * |
||
419 | * @return string|bool |
||
420 | */ |
||
421 | public function getSubType() |
||
424 | } |
||
425 | |||
426 | /** |
||
427 | * Return parameters specific to this payment sub type |
||
428 | * |
||
429 | * @param Order $oOrder |
||
430 | * @return array |
||
431 | */ |
||
432 | public function getSubTypeSpecificParameters(Order $oOrder) |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * Formats the reference number if needed for this payment method |
||
439 | * |
||
440 | * @param string $sRefNr |
||
441 | * @return string |
||
442 | */ |
||
443 | public function formatReferenceNumber($sRefNr) |
||
444 | { |
||
445 | return $sRefNr; |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * Return max length of narrative text |
||
450 | * |
||
451 | * @return int |
||
452 | */ |
||
453 | public function getNarrativeTextMaxLength() |
||
454 | { |
||
455 | return $this->iNarrativeTextMax; |
||
456 | } |
||
457 | |||
458 | /** |
||
459 | * @return array |
||
460 | */ |
||
461 | public function getFrontendConfig() |
||
465 | } |
||
466 | } |
||
467 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths