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 |
||
125 | public function verify(): ReceiptInterface |
||
126 | { |
||
127 | $token = Request::get('token'); |
||
128 | $paymentStatus = Request::get('payment_status'); |
||
129 | $data = [ |
||
130 | 'api_key' => $this->settings->merchantId, |
||
131 | 'token' => $token |
||
132 | ]; |
||
133 | |||
134 | if ($paymentStatus == self::PAYMENT_STATUS_FAILED) { |
||
135 | $this->notVerified('پرداخت با شکست مواجه شد.'); |
||
136 | } |
||
137 | |||
138 | $response = $this->client |
||
139 | ->request( |
||
140 | 'POST', |
||
141 | $this->settings->apiVerificationUrl, |
||
142 | [ |
||
143 | 'json' => $data, |
||
144 | 'headers' => [ |
||
145 | "Accept" => "application/json", |
||
146 | ], |
||
147 | 'http_errors' => false, |
||
148 | ] |
||
149 | ); |
||
150 | |||
151 | $responseBody = json_decode($response->getBody()->getContents(), true); |
||
152 | $statusCode = (int) $responseBody['status']; |
||
153 | |||
154 | if ($statusCode !== 1) { |
||
155 | if (isset($responseBody['error'])) { |
||
156 | $message = is_array($responseBody['error']) ? array_pop($responseBody['error']) : $responseBody['error']; |
||
157 | } |
||
158 | |||
159 | if (isset($responseBody['errors']) and is_array($responseBody['errors'])) { |
||
160 | $message = array_pop($responseBody['errors']); |
||
161 | } |
||
162 | |||
163 | $this->notVerified($message ?? '', $statusCode); |
||
164 | } |
||
165 | |||
166 | $receipt = $this->createReceipt($token); |
||
167 | |||
168 | $receipt->detail([ |
||
169 | "amount" => $responseBody['amount'], |
||
170 | "realAmount" => $responseBody['realAmount'], |
||
171 | "wage" => $responseBody['wage'], |
||
172 | "cardNumber" => $responseBody['cardNumber'], |
||
173 | ]); |
||
174 | |||
175 | return $receipt; |
||
176 | } |
||
205 |