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 |
||
85 | private function getMolliePaymentOptions(OrderInterface $order, string $countryCode): array |
||
86 | { |
||
87 | $allowedMethods = []; |
||
88 | |||
89 | $methods = $this->getDefaultOptions(); |
||
90 | |||
91 | /** @var GatewayConfigInterface $gateway */ |
||
92 | $paymentMethod = $this->paymentMethodRepository->findOneByChannelAndGatewayFactoryName( |
||
93 | $order->getChannel(), |
||
94 | MollieGatewayFactory::FACTORY_NAME |
||
95 | ); |
||
96 | |||
97 | if (null === $paymentMethod) { |
||
98 | return $this->getDefaultOptions(); |
||
99 | } |
||
100 | |||
101 | $gateway = $paymentMethod->getGatewayConfig(); |
||
102 | |||
103 | if (null === $gateway) { |
||
104 | return $this->getDefaultOptions(); |
||
105 | } |
||
106 | |||
107 | $paymentConfigs = $this->mollieGatewayRepository->findAllEnabledByGateway($gateway); |
||
108 | |||
109 | if (empty($paymentConfigs)) { |
||
110 | return $this->getDefaultOptions(); |
||
111 | } |
||
112 | |||
113 | try { |
||
114 | $allowedMethodsIds = $this->allowedMethodsResolver->resolve($order); |
||
115 | } catch (ApiException $e) { |
||
116 | $this->loggerAction->addNegativeLog($e->getMessage()); |
||
117 | |||
118 | return $this->getDefaultOptions(); |
||
119 | } |
||
120 | |||
121 | /** @var MollieGatewayConfig $paymentMethod */ |
||
122 | foreach ($paymentConfigs as $paymentMethod) { |
||
123 | if (in_array($paymentMethod->getMethodId(), $allowedMethodsIds, true)) { |
||
124 | $allowedMethods[] = $paymentMethod; |
||
125 | } |
||
126 | } |
||
127 | |||
128 | if (empty($allowedMethods)) { |
||
129 | return $this->getDefaultOptions(); |
||
130 | } |
||
131 | |||
132 | /** @var MollieGatewayConfigInterface $paymentMethod */ |
||
133 | foreach ($allowedMethods as $paymentMethod) { |
||
134 | $methods = $this->countriesRestrictionResolver->resolve($paymentMethod, $methods, $countryCode); |
||
135 | } |
||
136 | |||
137 | $methods = $this->productVoucherTypeChecker->checkTheProductTypeOnCart($order, $methods); |
||
138 | |||
139 | return $methods; |
||
140 | } |
||
152 |