| Conditions | 22 |
| Paths | 552 |
| Total Lines | 95 |
| Code Lines | 65 |
| 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 |
||
| 148 | protected function handleCallback(Request $request) |
||
| 149 | { |
||
| 150 | $payment = $this->getPaymentFromRequest($request); |
||
| 151 | |||
| 152 | // @todo this should be placed somewhere in the altapay php sdk |
||
| 153 | $transaction = null; |
||
| 154 | |||
| 155 | if($request->request->has('xml')) { |
||
| 156 | $xml = new \SimpleXMLElement($request->request->get('xml')); |
||
| 157 | if(isset($xml->Body->Transactions->Transaction) && !empty($xml->Body->Transactions->Transaction)) { |
||
| 158 | foreach ($xml->Body->Transactions->Transaction as $transactionXml) { |
||
| 159 | $transaction = $transactionXml; |
||
| 160 | break; |
||
| 161 | } |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | if($transaction) { |
||
| 166 | $paymentManager = $this->getPaymentManager(); |
||
| 167 | |||
| 168 | $createdDate = \DateTime::createFromFormat('Y-m-d H:i:s', $transaction->CreatedDate); |
||
| 169 | if($createdDate === false) { |
||
| 170 | $createdDate = null; |
||
| 171 | } |
||
| 172 | |||
| 173 | $updatedDate = \DateTime::createFromFormat('Y-m-d H:i:s', $transaction->UpdatedDate); |
||
| 174 | if($updatedDate === false) { |
||
| 175 | $updatedDate = null; |
||
| 176 | } |
||
| 177 | |||
| 178 | $supportsRefunds = $supportsRelease = $supportsMultipleCaptures = $supportsMultipleRefunds = null; |
||
| 179 | if(isset($transaction->PaymentNatureService)) { |
||
| 180 | if(isset($transaction->PaymentNatureService->SupportsRefunds)) { |
||
| 181 | $supportsRefunds = (string)$transaction->PaymentNatureService->SupportsRefunds === 'true'; |
||
| 182 | } |
||
| 183 | |||
| 184 | if(isset($transaction->PaymentNatureService->SupportsRelease)) { |
||
| 185 | $supportsRelease = (string)$transaction->PaymentNatureService->SupportsRelease === 'true'; |
||
| 186 | } |
||
| 187 | |||
| 188 | if(isset($transaction->PaymentNatureService->SupportsMultipleCaptures)) { |
||
| 189 | $supportsMultipleCaptures = (string)$transaction->PaymentNatureService->SupportsMultipleCaptures === 'true'; |
||
| 190 | } |
||
| 191 | |||
| 192 | if(isset($transaction->PaymentNatureService->SupportsMultipleRefunds)) { |
||
| 193 | $supportsMultipleRefunds = (string)$transaction->PaymentNatureService->SupportsMultipleRefunds === 'true'; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | $payment |
||
| 198 | ->setAltapayId($transaction->PaymentId ?? null) |
||
| 199 | ->setCardStatus($transaction->CardStatus ?? null) |
||
| 200 | ->setCreditCardToken($transaction->CreditCardToken ?? null) |
||
| 201 | ->setCreditCardMaskedPan($transaction->CreditCardMaskedPan ?? null) |
||
| 202 | ->setThreeDSecureResult($transaction->ThreeDSecureResult ?? null) |
||
| 203 | ->setLiableForChargeback($transaction->LiableForChargeback ?? null) |
||
| 204 | ->setBlacklistToken($transaction->BlacklistToken ?? null) |
||
| 205 | ->setShop($transaction->Shop ?? null) |
||
| 206 | ->setTerminal($transaction->Terminal ?? null) |
||
| 207 | ->setTransactionStatus($transaction->TransactionStatus ?? null) |
||
| 208 | ->setReasonCode($transaction->ReasonCode ?? null) |
||
| 209 | ->setMerchantCurrency(isset($transaction->MerchantCurrency) ? (int)$transaction->MerchantCurrency : null) |
||
| 210 | ->setMerchantCurrencyAlpha($transaction->MerchantCurrencyAlpha ?? null) |
||
| 211 | ->setCardHolderCurrency(isset($transaction->CardHolderCurrency) ? (int)$transaction->CardHolderCurrency : null) |
||
| 212 | ->setCardHolderCurrencyAlpha($transaction->CardHolderCurrencyAlpha ?? null) |
||
| 213 | ->setReservedAmount(isset($transaction->ReservedAmount) ? (float)$transaction->ReservedAmount : null) |
||
| 214 | ->setCapturedAmount(isset($transaction->CapturedAmount) ? (float)$transaction->CapturedAmount : null) |
||
| 215 | ->setRefundedAmount(isset($transaction->RefundedAmount) ? (float)$transaction->RefundedAmount : null) |
||
| 216 | ->setRecurringDefaultAmount(isset($transaction->RecurringDefaultAmount) ? (float)$transaction->RecurringDefaultAmount : null) |
||
| 217 | ->setCreatedDate($createdDate) |
||
| 218 | ->setUpdatedDate($updatedDate) |
||
| 219 | ->setPaymentNature($transaction->PaymentNature ?? null) |
||
| 220 | ->setSupportsRefunds($supportsRefunds) |
||
| 221 | ->setSupportsRelease($supportsRelease) |
||
| 222 | ->setSupportsMultipleCaptures($supportsMultipleCaptures) |
||
| 223 | ->setSupportsMultipleRefunds($supportsMultipleRefunds) |
||
| 224 | ->setFraudRiskScore(isset($transaction->FraudRiskScore) ? (float)$transaction->FraudRiskScore : null) |
||
| 225 | ->setFraudExplanation($transaction->FraudExplanation ?? null) |
||
| 226 | ; |
||
| 227 | $paymentManager->update($payment); |
||
| 228 | } |
||
| 229 | |||
| 230 | $callbackManager = $this->container->get('loevgaard_dandomain_altapay.callback_manager'); |
||
| 231 | $callback = $callbackManager->createCallbackFromRequest($request); |
||
| 232 | $callback->setPayment($payment); |
||
| 233 | |||
| 234 | $callbackManager->update($callback); |
||
| 235 | |||
| 236 | $allowedIps = $this->container->getParameter('loevgaard_dandomain_altapay.altapay_ips'); |
||
| 237 | if ('prod' === $this->container->get('kernel')->getEnvironment() && !in_array($request->getClientIp(), $allowedIps)) { |
||
| 238 | throw NotAllowedIpException::create('IP `'.$request->getClientIp().'` is not an allowed IP.', $request, $payment); |
||
| 239 | } |
||
| 240 | |||
| 241 | return $payment; |
||
| 242 | } |
||
| 243 | |||
| 290 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.