Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 34 |
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 |
||
174 | function it_refunds( |
||
175 | ClientInterface $client, |
||
176 | ResponseInterface $tokenResponse, |
||
177 | ResponseInterface $orderResponse, |
||
178 | ResponseInterface $refundResponse |
||
179 | ): void { |
||
180 | $tokenResponse->getBody()->willReturn('{ |
||
181 | "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciO", |
||
182 | "expires_in": 86400, |
||
183 | "scope": "read:me merchant", |
||
184 | "token_type": "Bearer" |
||
185 | }'); |
||
186 | |||
187 | $client->request( |
||
188 | 'POST', |
||
189 | 'https://api-ci.quadpay.com/oauth/token', |
||
190 | [ |
||
191 | 'json' => [ |
||
192 | 'client_id' => 'test', |
||
193 | 'client_secret' => 'test', |
||
194 | 'audience' => 'https://api-ci.quadpay.com/', |
||
195 | 'grant_type' => 'client_credentials', |
||
196 | ], |
||
197 | 'headers' => [ |
||
198 | 'Content-Type' => 'application/json', |
||
199 | ], |
||
200 | ] |
||
201 | )->willReturn($tokenResponse); |
||
202 | |||
203 | $orderResponse->getBody()->willReturn('{"orderId": "h4897t4htye8iype"}'); |
||
204 | |||
205 | $client->request( |
||
206 | 'GET', |
||
207 | 'https://api-ci.quadpay.com/order?token=gf74yr4iuyti4hjtikht', |
||
208 | [ |
||
209 | 'json' => [], |
||
210 | 'headers' => [ |
||
211 | 'Content-Type' => 'application/json', |
||
212 | 'Authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciO', |
||
213 | ], |
||
214 | ] |
||
215 | )->willReturn($orderResponse); |
||
216 | |||
217 | $refundResponse->getBody()->willReturn('{"refundId": "test"}'); |
||
218 | |||
219 | $client->request( |
||
220 | 'POST', |
||
221 | 'https://api-ci.quadpay.com/order/h4897t4htye8iype/refund', |
||
222 | [ |
||
223 | 'json' => [ |
||
224 | 'amount' => 20.77, |
||
225 | 'merchantRefundReference' => 'hfeirjtlegjktejio', |
||
226 | ], |
||
227 | 'headers' => [ |
||
228 | 'Content-Type' => 'application/json', |
||
229 | 'Authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciO', |
||
230 | ], |
||
231 | ] |
||
232 | )->willReturn($refundResponse); |
||
233 | |||
234 | $this->refund(20.77, 'hfeirjtlegjktejio', 'gf74yr4iuyti4hjtikht')->shouldReturn([ |
||
235 | 'refundId' => 'test', |
||
236 | ]); |
||
239 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.