| Conditions | 10 |
| Paths | 7 |
| Total Lines | 30 |
| Code Lines | 16 |
| 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 |
||
| 98 | public function verify() : ReceiptInterface |
||
| 99 | { |
||
| 100 | $status = request()->get('status'); |
||
| 101 | $token = request()->get('Token'); |
||
| 102 | $rrn = request()->get('RRN'); |
||
|
|
|||
| 103 | |||
| 104 | if ($status != 0 || empty($token)) { |
||
| 105 | throw new InvalidPaymentException('تراکنش توسط کاربر کنسل شده است.'); |
||
| 106 | } |
||
| 107 | |||
| 108 | $data = $this->prepareVerificationData(); |
||
| 109 | $soap = new \SoapClient($this->settings->apiVerificationUrl); |
||
| 110 | |||
| 111 | $response = $soap->ConfirmPayment(['requestData' => $data]); |
||
| 112 | |||
| 113 | if (empty($response['ConfirmPaymentResult'])) { |
||
| 114 | throw new InvalidPaymentException('از سمت بانک پاسخی دریافت نشد.'); |
||
| 115 | } |
||
| 116 | |||
| 117 | $result = $response['ConfirmPaymentResult']; |
||
| 118 | |||
| 119 | if (!isset($result['Status']) || $result['Status'] != 0 || !isset($result['RRN']) || $result['RRN'] <= 0) { |
||
| 120 | $message = 'خطا از سمت بانک با کد ' . $result['Status'] . ' رخ داده است.'; |
||
| 121 | throw new InvalidPaymentException($message); |
||
| 122 | } |
||
| 123 | |||
| 124 | $bankReference = (isset($result['RRN']) && $result['RRN'] > 0) ? $result['RRN'] : ""; |
||
| 125 | // $cardNumberMasked = !empty($result['CardNumberMasked']) ? $result['CardNumberMasked'] : ""; |
||
| 126 | |||
| 127 | return $this->createReceipt($bankReference); |
||
| 128 | } |
||
| 181 |