Conditions | 5 |
Paths | 6 |
Total Lines | 65 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
151 | protected function handleCallback(Request $request) |
||
152 | { |
||
153 | $payment = $this->getPaymentFromRequest($request); |
||
154 | $callbackHandler = $this->get('loevgaard_dandomain_altapay.altapay_callback_handler'); |
||
155 | |||
156 | // convert symfony request to PSR7 request |
||
157 | $psr7Factory = new DiactorosFactory(); |
||
158 | $psrRequest = $psr7Factory->createRequest($request); |
||
159 | $callback = $callbackHandler->handleCallback($psrRequest); |
||
160 | |||
161 | if ($callback instanceof XmlCallback) { |
||
162 | $transactions = $callback->getTransactions(); |
||
163 | if (isset($transactions[0])) { |
||
164 | /** @var Transaction $transaction */ |
||
165 | $transaction = $transactions[0]; |
||
166 | |||
167 | $paymentManager = $this->getPaymentManager(); |
||
168 | |||
169 | $payment |
||
170 | ->setAltapayId($transaction->getPaymentId()) |
||
171 | ->setCardStatus($transaction->getCardStatus()) |
||
172 | ->setCreditCardToken($transaction->getCreditCardToken()) |
||
173 | ->setCreditCardMaskedPan($transaction->getCreditCardMaskedPan()) |
||
174 | ->setThreeDSecureResult($transaction->getThreeDSecureResult()) |
||
175 | ->setLiableForChargeback($transaction->getLiableForChargeback()) |
||
176 | ->setBlacklistToken($transaction->getBlacklistToken()) |
||
177 | ->setShop($transaction->getShop()) |
||
178 | ->setTerminal($transaction->getTerminal()) |
||
179 | ->setTransactionStatus($transaction->getTransactionStatus()) |
||
180 | ->setReasonCode($transaction->getReasonCode()) |
||
181 | ->setMerchantCurrency($transaction->getMerchantCurrency()) |
||
182 | ->setMerchantCurrencyAlpha($transaction->getMerchantCurrencyAlpha()) |
||
183 | ->setCardHolderCurrency($transaction->getCardHolderCurrency()) |
||
184 | ->setCardHolderCurrencyAlpha($transaction->getCardHolderCurrencyAlpha()) |
||
185 | ->setReservedAmount($transaction->getReservedAmount()) |
||
186 | ->setCapturedAmount($transaction->getCapturedAmount()) |
||
187 | ->setRefundedAmount($transaction->getRefundedAmount()) |
||
188 | ->setRecurringDefaultAmount($transaction->getRecurringDefaultAmount()) |
||
189 | ->setCreatedDate($transaction->getCreatedDate()) |
||
190 | ->setUpdatedDate($transaction->getUpdatedDate()) |
||
191 | ->setPaymentNature($transaction->getPaymentNature()) |
||
192 | ->setSupportsRefunds($transaction->getPaymentNatureService()->isSupportsRefunds()) |
||
193 | ->setSupportsRelease($transaction->getPaymentNatureService()->isSupportsRelease()) |
||
194 | ->setSupportsMultipleCaptures($transaction->getPaymentNatureService()->isSupportsMultipleCaptures()) |
||
195 | ->setSupportsMultipleRefunds($transaction->getPaymentNatureService()->isSupportsMultipleRefunds()) |
||
196 | ->setFraudRiskScore($transaction->getFraudRiskScore()) |
||
197 | ->setFraudExplanation($transaction->getFraudExplanation()) |
||
198 | ; |
||
199 | $paymentManager->update($payment); |
||
200 | } |
||
201 | } |
||
202 | |||
203 | $callbackManager = $this->container->get('loevgaard_dandomain_altapay.callback_manager'); |
||
204 | $callback = $callbackManager->createCallbackFromRequest($request); |
||
205 | $callback->setPayment($payment); |
||
206 | |||
207 | $callbackManager->update($callback); |
||
208 | |||
209 | $allowedIps = $this->container->getParameter('loevgaard_dandomain_altapay.altapay_ips'); |
||
210 | if ('prod' === $this->container->get('kernel')->getEnvironment() && !in_array($request->getClientIp(), $allowedIps)) { |
||
211 | throw NotAllowedIpException::create('IP `'.$request->getClientIp().'` is not an allowed IP.', $request, $payment); |
||
212 | } |
||
213 | |||
214 | return $payment; |
||
215 | } |
||
216 | |||
263 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.