| Conditions | 9 |
| Paths | 13 |
| Total Lines | 55 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 86 | private function getMolliePaymentOptions(OrderInterface $order, string $countryCode): array |
||
| 87 | { |
||
| 88 | $allowedMethods = []; |
||
| 89 | |||
| 90 | $methods = $this->getDefaultOptions(); |
||
| 91 | |||
| 92 | /** @var GatewayConfigInterface $gateway */ |
||
| 93 | $paymentMethod = $this->paymentMethodRepository->findOneByChannelAndGatewayFactoryName( |
||
| 94 | $order->getChannel(), |
||
| 95 | MollieGatewayFactory::FACTORY_NAME |
||
| 96 | ); |
||
| 97 | |||
| 98 | if (null === $paymentMethod) { |
||
| 99 | return $this->getDefaultOptions(); |
||
| 100 | } |
||
| 101 | |||
| 102 | $gateway = $paymentMethod->getGatewayConfig(); |
||
| 103 | |||
| 104 | if (null === $gateway) { |
||
| 105 | return $this->getDefaultOptions(); |
||
| 106 | } |
||
| 107 | |||
| 108 | $paymentConfigs = $this->mollieGatewayRepository->findAllEnabledByGateway($gateway); |
||
| 109 | |||
| 110 | if (empty($paymentConfigs)) { |
||
| 111 | return $this->getDefaultOptions(); |
||
| 112 | } |
||
| 113 | |||
| 114 | try { |
||
| 115 | $allowedMethodsIds = $this->allowedMethodsResolver->resolve($order); |
||
| 116 | } catch (ApiException $e) { |
||
| 117 | $this->loggerAction->addNegativeLog($e->getMessage()); |
||
| 118 | |||
| 119 | return $this->getDefaultOptions(); |
||
| 120 | } |
||
| 121 | |||
| 122 | /** @var MollieGatewayConfig $paymentMethod */ |
||
| 123 | foreach ($paymentConfigs as $paymentMethod) { |
||
| 124 | if (in_array($paymentMethod->getMethodId(), $allowedMethodsIds, true)) { |
||
| 125 | $allowedMethods[] = $paymentMethod; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | if (empty($allowedMethods)) { |
||
| 130 | return $this->getDefaultOptions(); |
||
| 131 | } |
||
| 132 | |||
| 133 | /** @var MollieGatewayConfigInterface $paymentMethod */ |
||
| 134 | foreach ($allowedMethods as $paymentMethod) { |
||
| 135 | $methods = $this->countriesRestrictionResolver->resolve($paymentMethod, $methods, $countryCode); |
||
| 136 | } |
||
| 137 | |||
| 138 | $methods = $this->productVoucherTypeChecker->checkTheProductTypeOnCart($order, $methods); |
||
| 139 | |||
| 140 | return $methods; |
||
| 141 | } |
||
| 153 |