| Total Complexity | 54 |
| Total Lines | 384 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 authorization-mode |
||
| 52 | * preauthorization or authorization |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function getAuthorizationMode() |
||
| 57 | { |
||
| 58 | $sRequestType = $this->shopHelper->getConfigParam('request_type'); |
||
| 59 | if ($this->hasCustomConfig()) { |
||
| 60 | $sCustomRequestType = $this->getCustomConfigParam('request_type'); |
||
| 61 | if (!empty($sCustomRequestType)) { |
||
| 62 | $sRequestType = $sCustomRequestType; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | return $sRequestType; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Method handling the debit request and the response |
||
| 70 | * |
||
| 71 | * @param InfoInterface $payment |
||
| 72 | * @param float $amount |
||
| 73 | * @return void |
||
| 74 | * @throws LocalizedException |
||
| 75 | */ |
||
| 76 | protected function sendPayoneDebit(InfoInterface $payment, $amount) |
||
| 77 | { |
||
| 78 | if ($this->shopHelper->getConfigParam('currency') == 'display' && $payment->getCreditmemo()) { |
||
| 79 | $amount = $payment->getCreditmemo()->getGrandTotal(); // send display amount instead of base amount |
||
| 80 | } |
||
| 81 | $aResponse = $this->debitRequest->sendRequest($this, $payment, $amount); |
||
| 82 | if ($aResponse['status'] == 'ERROR') { |
||
| 83 | $this->checkoutSession->setPayoneDebitRequest($this->debitRequest->getParameters()); |
||
| 84 | $this->checkoutSession->setPayoneDebitResponse($this->debitRequest->getResponse()); |
||
| 85 | $this->checkoutSession->setPayoneDebitOrderId($this->debitRequest->getOrderId()); |
||
| 86 | throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage'])); |
||
| 87 | } elseif (!$aResponse) { |
||
| 88 | throw new LocalizedException(__('Unkown error')); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Method handling the capture request and the response |
||
| 94 | * |
||
| 95 | * @param InfoInterface $payment |
||
| 96 | * @param float $amount |
||
| 97 | * @return void |
||
| 98 | * @throws LocalizedException |
||
| 99 | */ |
||
| 100 | protected function sendPayoneCapture(InfoInterface $payment, $amount) |
||
| 101 | { |
||
| 102 | if ($this->shopHelper->getConfigParam('currency') == 'display' && $payment->getOrder()->hasInvoices()) { |
||
| 103 | $oInvoice = $payment->getOrder()->getInvoiceCollection()->getLastItem(); |
||
| 104 | $amount = $oInvoice->getGrandTotal(); // send display amount instead of base amount |
||
| 105 | } |
||
| 106 | $aResponse = $this->captureRequest->sendRequest($this, $payment, $amount); |
||
| 107 | if ($aResponse['status'] == 'ERROR') {// request returned an error |
||
| 108 | throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage'])); |
||
| 109 | } elseif (!$aResponse) {// response not existing |
||
| 110 | throw new LocalizedException(__('Unkown error')); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Removes status flag used during checkout process from session |
||
| 116 | * |
||
| 117 | * @return void |
||
| 118 | */ |
||
| 119 | protected function unsetSessionStatusFlags() { |
||
| 120 | $this->checkoutSession->unsPayoneRedirectUrl(); |
||
| 121 | $this->checkoutSession->unsPayoneRedirectedPaymentMethod(); |
||
| 122 | $this->checkoutSession->unsPayoneCanceledPaymentMethod(); |
||
| 123 | $this->checkoutSession->unsPayoneIsError(); |
||
| 124 | $this->checkoutSession->unsShowAmazonPendingNotice(); |
||
| 125 | $this->checkoutSession->unsAmazonRetryAsync(); |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Method handling the authorization request and the response |
||
| 130 | * |
||
| 131 | * @param InfoInterface $payment |
||
| 132 | * @param float $amount |
||
| 133 | * @return void |
||
| 134 | * @throws LocalizedException |
||
| 135 | */ |
||
| 136 | protected function sendPayoneAuthorization(InfoInterface $payment, $amount) |
||
| 161 | } |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Perform certain actions with the response |
||
| 167 | * Extension hook for certain payment methods |
||
| 168 | * |
||
| 169 | * @param array $aResponse |
||
| 170 | * @param Order $oOrder |
||
| 171 | * @param float $amount |
||
| 172 | * @return array |
||
| 173 | */ |
||
| 174 | protected function handleResponse($aResponse, Order $oOrder, $amount) |
||
| 175 | { |
||
| 176 | $aAddData = $oOrder->getPayment()->getAdditionalInformation(); |
||
| 177 | if (!empty($aAddData['iban'])) { |
||
| 178 | $oOrder->getPayment()->setAdditionalInformation('iban', $this->toolkitHelper->maskIban($aAddData['iban'])); |
||
| 179 | } |
||
| 180 | return $aResponse; |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Convert DataObject to needed array format |
||
| 185 | * Hook for overriding in specific payment type class |
||
| 186 | * |
||
| 187 | * @param DataObject $data |
||
| 188 | * @return array |
||
| 189 | */ |
||
| 190 | protected function getPaymentStorageData(DataObject $data) |
||
| 191 | { |
||
| 192 | return []; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Check config and save payment data |
||
| 197 | * |
||
| 198 | * @param DataObject $data |
||
| 199 | * @return void |
||
| 200 | */ |
||
| 201 | protected function handlePaymentDataStorage(DataObject $data) |
||
| 202 | { |
||
| 203 | if ((bool)$this->getCustomConfigParam('save_data_enabled') === true) { |
||
| 204 | $aPaymentData = $this->getPaymentStorageData($data); |
||
| 205 | $iCustomerId = $this->checkoutSession->getQuote()->getCustomerId(); |
||
| 206 | if (!empty($aPaymentData) && $iCustomerId) { |
||
| 207 | $this->savedPaymentData->addSavedPaymentData($iCustomerId, $this->getCode(), $aPaymentData); |
||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Returns operationmode live or test for this payment method |
||
| 214 | * |
||
| 215 | * @return string |
||
| 216 | */ |
||
| 217 | public function getOperationMode() |
||
| 218 | { |
||
| 219 | return $this->getCustomConfigParam('mode'); |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Return parameters specific to this payment type |
||
| 224 | * |
||
| 225 | * @param Order $oOrder |
||
| 226 | * @return array |
||
| 227 | */ |
||
| 228 | public function getPaymentSpecificParameters(Order $oOrder) |
||
| 229 | { |
||
| 230 | return []; // filled in child classes |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Return success url for redirect payment types |
||
| 235 | * |
||
| 236 | * @param Order $oOrder |
||
| 237 | * @return string |
||
| 238 | */ |
||
| 239 | public function getSuccessUrl(Order $oOrder = null) |
||
| 240 | { |
||
| 241 | $sAddedParams = ''; |
||
| 242 | if ($oOrder !== null) { |
||
| 243 | $sAddedParams = '?incrementId='.$oOrder->getIncrementId(); |
||
| 244 | } |
||
| 245 | return $this->url->getUrl('payone/onepage/returned').$sAddedParams; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Return cancel url for redirect payment types |
||
| 250 | * |
||
| 251 | * @return string |
||
| 252 | */ |
||
| 253 | public function getCancelUrl() |
||
| 256 | } |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Return error url for redirect payment types |
||
| 260 | * |
||
| 261 | * @return string |
||
| 262 | */ |
||
| 263 | public function getErrorUrl() |
||
| 264 | { |
||
| 265 | return $this->url->getUrl('payone/onepage/cancel?error=1'); |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Return if redirect urls have to be added to the authroization request |
||
| 270 | * |
||
| 271 | * @return bool |
||
| 272 | */ |
||
| 273 | public function needsRedirectUrls() |
||
| 274 | { |
||
| 275 | return $this->blNeedsRedirectUrls; |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Return if invoice data has to be added to the authroization request |
||
| 280 | * |
||
| 281 | * @return bool |
||
| 282 | */ |
||
| 283 | public function needsProductInfo() |
||
| 286 | } |
||
| 287 | |||
| 288 | |||
| 289 | /** |
||
| 290 | * Return if bank data has to be added to the debit request |
||
| 291 | * |
||
| 292 | * @return bool |
||
| 293 | */ |
||
| 294 | public function needsSepaDataOnDebit() |
||
| 295 | { |
||
| 296 | return $this->blNeedsSepaDataOnDebit; |
||
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Get config parameter for this payment type |
||
| 301 | * |
||
| 302 | * @param string $sParam |
||
| 303 | * @param string $sStoreCode |
||
| 304 | * @return string |
||
| 305 | */ |
||
| 306 | public function getCustomConfigParam($sParam, $sStoreCode = null) |
||
| 307 | { |
||
| 308 | if ($sStoreCode === null) { |
||
| 309 | $sStoreCode = $this->getStoreCode(); |
||
| 310 | } |
||
| 311 | return $this->shopHelper->getConfigParam($sParam, $this->getCode(), 'payone_payment', $sStoreCode); |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Trys to retrieve the storecode from the order |
||
| 316 | * |
||
| 317 | * @return string|null |
||
| 318 | */ |
||
| 319 | protected function getStoreCode() |
||
| 320 | { |
||
| 321 | try { |
||
| 322 | $oInfoInstance = $this->getInfoInstance(); |
||
| 323 | if (empty($oInfoInstance)) { |
||
| 324 | return null; |
||
| 325 | } |
||
| 326 | } catch (\Exception $oExc) { |
||
| 327 | return null; |
||
| 328 | } |
||
| 329 | |||
| 330 | $oOrder = $oInfoInstance->getOrder(); |
||
| 331 | if (empty($oOrder)) { |
||
| 332 | $oOrder = $oInfoInstance->getQuote(); |
||
| 333 | if (empty($oOrder)) { |
||
| 334 | return null; |
||
| 335 | } |
||
| 336 | } |
||
| 337 | |||
| 338 | $oStore = $oOrder->getStore(); |
||
| 339 | if (empty($oStore)) { |
||
| 340 | return null; |
||
| 341 | } |
||
| 342 | return $oStore->getCode(); |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Returns if global PAYONE config is used for this payment type |
||
| 347 | * |
||
| 348 | * @return bool |
||
| 349 | */ |
||
| 350 | public function hasCustomConfig() |
||
| 351 | { |
||
| 352 | if ($this->getCustomConfigParam('use_global') == '0') {// has non-global config |
||
| 353 | return true; |
||
| 354 | } |
||
| 355 | return false; |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Return if this payment method is part of a group |
||
| 360 | * |
||
| 361 | * @return bool |
||
| 362 | */ |
||
| 363 | public function isGroupMethod() |
||
| 364 | { |
||
| 365 | if ($this->sGroupName === false) { |
||
| 366 | return false; |
||
| 367 | } |
||
| 368 | return true; |
||
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Returns group identifier |
||
| 373 | * |
||
| 374 | * @return string|bool |
||
| 375 | */ |
||
| 376 | public function getGroupName() |
||
| 377 | { |
||
| 378 | return $this->sGroupName; |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Returns group identifier |
||
| 383 | * |
||
| 384 | * @return string|bool |
||
| 385 | */ |
||
| 386 | public function getSubType() |
||
| 389 | } |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Return parameters specific to this payment sub type |
||
| 393 | * |
||
| 394 | * @param Order $oOrder |
||
| 395 | * @return array |
||
| 396 | */ |
||
| 397 | public function getSubTypeSpecificParameters(Order $oOrder) |
||
| 400 | } |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Formats the reference number if needed for this payment method |
||
| 404 | * Needed for Paydirekt |
||
| 405 | * |
||
| 406 | * @param string $sRefNr |
||
| 407 | * @return string |
||
| 408 | */ |
||
| 409 | public function formatReferenceNumber($sRefNr) |
||
| 412 | } |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Return max length of narrative text |
||
| 416 | * |
||
| 417 | * @return int |
||
| 418 | */ |
||
| 419 | public function getNarrativeTextMaxLength() |
||
| 422 | } |
||
| 423 | } |
||
| 424 |
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