| Total Complexity | 42 |
| Total Lines | 289 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like MethodList 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 MethodList, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 40 | class MethodList |
||
| 41 | { |
||
| 42 | /** |
||
| 43 | * PAYONE consumerscore request model |
||
| 44 | * |
||
| 45 | * @var \Payone\Core\Model\Api\Request\Consumerscore |
||
| 46 | */ |
||
| 47 | protected $consumerscore; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Consumerscore helper |
||
| 51 | * |
||
| 52 | * @var \Payone\Core\Helper\Consumerscore |
||
| 53 | */ |
||
| 54 | protected $consumerscoreHelper; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Checkout session |
||
| 58 | * |
||
| 59 | * @var \Magento\Checkout\Model\Session |
||
| 60 | */ |
||
| 61 | protected $checkoutSession; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Payment ban entity |
||
| 65 | * |
||
| 66 | * @var \Payone\Core\Model\ResourceModel\PaymentBan |
||
| 67 | */ |
||
| 68 | protected $paymentBan; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Addresscheck management object |
||
| 72 | * |
||
| 73 | * @var \Payone\Core\Model\Risk\Addresscheck |
||
| 74 | */ |
||
| 75 | protected $addresscheck; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Payone customer helper |
||
| 79 | * |
||
| 80 | * @var \Payone\Core\Helper\Customer |
||
| 81 | */ |
||
| 82 | protected $customerHelper; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Constructor |
||
| 86 | * |
||
| 87 | * @param \Payone\Core\Model\Api\Request\Consumerscore $consumerscore |
||
| 88 | * @param \Payone\Core\Helper\Consumerscore $consumerscoreHelper |
||
| 89 | * @param \Magento\Checkout\Model\Session $checkoutSession |
||
| 90 | * @param \Payone\Core\Model\ResourceModel\PaymentBan $paymentBan |
||
| 91 | * @param \Payone\Core\Model\Risk\Addresscheck $addresscheck |
||
| 92 | * @param \Payone\Core\Helper\Customer $customerHelper |
||
| 93 | */ |
||
| 94 | public function __construct( |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Filter methods by the worst score |
||
| 112 | * |
||
| 113 | * @param MethodInterface[] $aPaymentMethods |
||
| 114 | * @param string $sWorstScore |
||
| 115 | * @return MethodInterface[] |
||
| 116 | */ |
||
| 117 | protected function filterMethodsByScore($aPaymentMethods, $sWorstScore) |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Execute a consumerscore request to PAYONE or load an old score if its lifetime is still active |
||
| 137 | * |
||
| 138 | * @param AddressInterface $oShipping |
||
| 139 | * @return string |
||
| 140 | */ |
||
| 141 | protected function getScoreByCreditrating(AddressInterface $oShipping) |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Get parameter from config |
||
| 164 | * |
||
| 165 | * @param string $sParam |
||
| 166 | * @param bool $blIsAddresscheck |
||
| 167 | * @return string |
||
| 168 | */ |
||
| 169 | protected function getConfigParam($sParam, $blIsAddresscheck = false) |
||
| 170 | { |
||
| 171 | $sGroup = 'creditrating'; |
||
| 172 | if ($blIsAddresscheck === true) { |
||
| 173 | $sGroup = 'address_check'; |
||
| 174 | } |
||
| 175 | return $this->consumerscoreHelper->getConfigParam($sParam, $sGroup, 'payone_protect'); |
||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Get quote object from session |
||
| 180 | * |
||
| 181 | * @return Quote |
||
| 182 | */ |
||
| 183 | protected function getQuote() |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Return banned payment methods for the current user |
||
| 190 | * |
||
| 191 | * @param Quote $oQuote |
||
| 192 | * @return array |
||
| 193 | */ |
||
| 194 | protected function getBannedPaymentMethods(Quote $oQuote) |
||
| 195 | { |
||
| 196 | $aBans = []; |
||
| 197 | if (!empty($oQuote->getCustomerId())) { |
||
| 198 | $aBans = $this->paymentBan->getPaymentBans($oQuote->getCustomerId()); |
||
| 199 | } |
||
| 200 | |||
| 201 | $aSessionBans = $this->checkoutSession->getPayonePaymentBans(); |
||
| 202 | if (!empty($aSessionBans)) { |
||
| 203 | $aBans = array_merge($aBans, $aSessionBans); |
||
| 204 | } |
||
| 205 | return $aBans; |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Remove banned paymenttypes |
||
| 210 | * |
||
| 211 | * @param array $aPaymentMethods |
||
| 212 | * @param Quote $oQuote |
||
| 213 | * @return array |
||
| 214 | */ |
||
| 215 | protected function removeBannedPaymentMethods($aPaymentMethods, Quote $oQuote) |
||
| 216 | { |
||
| 217 | $aBannedMethods = $this->getBannedPaymentMethods($oQuote); |
||
| 218 | foreach ($aPaymentMethods as $key => $aPaymentMethod) { |
||
| 219 | $sCode = $aPaymentMethod->getCode(); |
||
| 220 | if (array_key_exists($sCode, $aBannedMethods) !== false) { |
||
| 221 | $iBannedUntil = strtotime($aBannedMethods[$sCode]); |
||
| 222 | if ($iBannedUntil > time()) { |
||
| 223 | unset($aPaymentMethods[$key]); |
||
| 224 | } |
||
| 225 | } |
||
| 226 | } |
||
| 227 | return $aPaymentMethods; |
||
| 228 | } |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Remove paymenttypes not on the session whitelist |
||
| 232 | * |
||
| 233 | * @param array $aPaymentMethods |
||
| 234 | * @return array |
||
| 235 | */ |
||
| 236 | protected function removeNotWhitelistedPaymentMethods($aPaymentMethods) |
||
| 237 | { |
||
| 238 | $aWhitelist = $this->checkoutSession->getPayonePaymentWhitelist(); |
||
| 239 | if (!empty($aWhitelist)) { |
||
| 240 | foreach ($aPaymentMethods as $key => $aPaymentMethod) { |
||
| 241 | if (!in_array($aPaymentMethod->getCode(), $aWhitelist)) { |
||
| 242 | unset($aPaymentMethods[$key]); |
||
| 243 | } |
||
| 244 | } |
||
| 245 | } |
||
| 246 | return $aPaymentMethods; |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Remove Amazon Pay from payment method array |
||
| 251 | * |
||
| 252 | * @param array $aPaymentMethods |
||
| 253 | * @return array |
||
| 254 | */ |
||
| 255 | public function removeAmazonPay($aPaymentMethods) |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Removes Klarna base methode if there are no Klarna sub-types available |
||
| 268 | * |
||
| 269 | * @param array $aPaymentMethods |
||
| 270 | * @return array |
||
| 271 | */ |
||
| 272 | public function checkKlarnaMethods($aPaymentMethods) |
||
| 273 | { |
||
| 274 | $iKeyKlarna = false; |
||
| 275 | $blHasKlarnaSubtypes = false; |
||
| 276 | $aKlarnaSubtypes = [ |
||
| 277 | PayoneConfig::METHOD_KLARNA_INVOICE, |
||
| 278 | PayoneConfig::METHOD_KLARNA_DEBIT, |
||
| 279 | PayoneConfig::METHOD_KLARNA_INSTALLMENT |
||
| 280 | ]; |
||
| 281 | foreach ($aPaymentMethods as $key => $aPaymentMethod) { |
||
| 282 | if ($aPaymentMethod->getCode() == PayoneConfig::METHOD_KLARNA_BASE) { |
||
| 283 | $iKeyKlarna = $key; |
||
| 284 | } |
||
| 285 | if (in_array($aPaymentMethod->getCode(), $aKlarnaSubtypes) === true) { |
||
| 286 | $blHasKlarnaSubtypes = true; |
||
| 287 | break; |
||
| 288 | } |
||
| 289 | } |
||
| 290 | if ($iKeyKlarna !== false && $blHasKlarnaSubtypes === false) { |
||
| 291 | unset($aPaymentMethods[$iKeyKlarna]); |
||
| 292 | } |
||
| 293 | return $aPaymentMethods; |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * |
||
| 298 | * @param OrigMethodList $subject |
||
| 299 | * @param MethodInterface[] $aPaymentMethods |
||
| 300 | * @param \Magento\Quote\Api\Data\CartInterface $quote |
||
| 301 | * @return MethodInterface[] |
||
| 302 | */ |
||
| 303 | public function afterGetAvailableMethods(OrigMethodList $subject, $aPaymentMethods, \Magento\Quote\Api\Data\CartInterface $quote) |
||
| 329 | } |
||
| 330 | } |
||
| 331 |
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