| Conditions | 7 |
| Paths | 14 |
| Total Lines | 51 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 127 | public function verify(): ReceiptInterface |
||
| 128 | { |
||
| 129 | $token = Request::get('token'); |
||
|
|
|||
| 130 | $paymentStatus = Request::get('payment_status'); |
||
| 131 | $data = [ |
||
| 132 | 'api_key' => $this->settings->merchantId, |
||
| 133 | 'token' => $token |
||
| 134 | ]; |
||
| 135 | |||
| 136 | if ($paymentStatus == self::PAYMENT_STATUS_FAILED) { |
||
| 137 | $this->notVerified('پرداخت با شکست مواجه شد.'); |
||
| 138 | } |
||
| 139 | |||
| 140 | $response = $this->client |
||
| 141 | ->request( |
||
| 142 | 'POST', |
||
| 143 | $this->settings->apiVerificationUrl, |
||
| 144 | [ |
||
| 145 | 'json' => $data, |
||
| 146 | 'headers' => [ |
||
| 147 | "Accept" => "application/json", |
||
| 148 | ], |
||
| 149 | 'http_errors' => false, |
||
| 150 | ] |
||
| 151 | ); |
||
| 152 | |||
| 153 | $responseBody = json_decode($response->getBody()->getContents(), true); |
||
| 154 | $statusCode = (int) $responseBody['status']; |
||
| 155 | |||
| 156 | if ($statusCode !== 1) { |
||
| 157 | if (isset($responseBody['error'])) { |
||
| 158 | $message = is_array($responseBody['error']) ? array_pop($responseBody['error']) : $responseBody['error']; |
||
| 159 | } |
||
| 160 | |||
| 161 | if (isset($responseBody['errors']) and is_array($responseBody['errors'])) { |
||
| 162 | $message = array_pop($responseBody['errors']); |
||
| 163 | } |
||
| 164 | |||
| 165 | $this->notVerified($message ?? ''); |
||
| 166 | } |
||
| 167 | |||
| 168 | $receipt = $this->createReceipt($token); |
||
| 169 | |||
| 170 | $receipt->detail([ |
||
| 171 | "amount" => $responseBody['amount'], |
||
| 172 | "realAmount" => $responseBody['realAmount'], |
||
| 173 | "wage" => $responseBody['wage'], |
||
| 174 | "cardNumber" => $responseBody['cardNumber'], |
||
| 175 | ]); |
||
| 176 | |||
| 177 | return $receipt; |
||
| 178 | } |
||
| 207 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.