| Conditions | 4 |
| Paths | 3 |
| Total Lines | 55 |
| Code Lines | 33 |
| 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 |
||
| 166 | public function handle(array $handlingSubject, array $response) |
||
| 167 | { |
||
| 168 | if (!isset($handlingSubject['payment']) |
||
| 169 | || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface |
||
| 170 | ) { |
||
| 171 | throw new InvalidArgumentException('Payment data object should be provided'); |
||
| 172 | } |
||
| 173 | |||
| 174 | $paymentDO = $handlingSubject['payment']; |
||
| 175 | |||
| 176 | $payment = $paymentDO->getPayment(); |
||
| 177 | |||
| 178 | $payCredit = $response[self::CREDIT]; |
||
| 179 | |||
| 180 | $payment->setAdditionalInformation( |
||
| 181 | self::PAYMENT_INFO_TERMINAL_NSU, |
||
| 182 | $payCredit[self::RESPONSE_TERMINAL_NSU] |
||
| 183 | ); |
||
| 184 | |||
| 185 | $payment->setAdditionalInformation( |
||
| 186 | self::PAYMENT_INFO_AUTHORIZATION_CODE, |
||
| 187 | $payCredit[self::RESPONSE_AUTHORIZATION_CODE] |
||
| 188 | ); |
||
| 189 | |||
| 190 | $payment->setAdditionalInformation( |
||
| 191 | self::PAYMENT_INFO_ACQUIRER_TRANSACTION_ID, |
||
| 192 | $payCredit[self::RESPONSE_ACQUIRER_TRANSACTION_ID] |
||
| 193 | ); |
||
| 194 | |||
| 195 | $payment->setAdditionalInformation( |
||
| 196 | self::PAYMENT_INFO_TRANSACTION_ID, |
||
| 197 | $payCredit[self::RESPONSE_TRANSACTION_ID] |
||
| 198 | ); |
||
| 199 | |||
| 200 | $ccType = $payment->getAdditionalInformation(self::PAYMENT_INFO_CC_TYPE); |
||
| 201 | if ($ccType) { |
||
| 202 | $ccType = $this->getCreditCardType($ccType); |
||
| 203 | $payment->setCcType($ccType); |
||
| 204 | } |
||
| 205 | |||
| 206 | $ccLast4 = $payment->getAdditionalInformation(self::PAYMENT_INFO_CC_NUMBER); |
||
| 207 | $ccLast4 = preg_replace('/[^0-9]/', '', $ccLast4); |
||
| 208 | $payment->setCcLast4($ccLast4); |
||
| 209 | |||
| 210 | $ccOwner = $payment->getAdditionalInformation(self::PAYMENT_INFO_CC_OWNER); |
||
| 211 | $payment->setCcOwner($ccOwner); |
||
| 212 | |||
| 213 | $ccExpMonth = $payment->getAdditionalInformation(self::PAYMENT_INFO_CC_EXP_MONTH); |
||
| 214 | $payment->setCcExpMonth($ccExpMonth); |
||
| 215 | |||
| 216 | $ccExpYear = $payment->getAdditionalInformation(self::PAYMENT_INFO_CC_EXP_YEAR); |
||
| 217 | $payment->setCcExpYear($ccExpYear); |
||
| 218 | |||
| 219 | $ccNumberEnc = $payment->getAdditionalInformation(self::PAYMENT_INFO_CC_NUMBER_ENC); |
||
| 220 | $payment->setCcNumberEnc($ccNumberEnc); |
||
| 221 | } |
||
| 237 |