| Conditions | 10 |
| Paths | 1 |
| Total Lines | 27 |
| Code Lines | 19 |
| 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 |
||
| 21 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise |
||
| 22 | { |
||
| 23 | return $next($request)->then(function (ResponseInterface $response) { |
||
| 24 | $statusCode = $response->getStatusCode(); |
||
| 25 | $content = ResponseMediator::getContent($response); |
||
| 26 | |||
| 27 | if (ResponseMediator::isSuccess($response)) { |
||
| 28 | if (is_array($content) && isset($content['result']) && 'success' !== $content['result']) { |
||
| 29 | throw new TransmissionException($content['result'], $statusCode); |
||
| 30 | } |
||
| 31 | } elseif (!ResponseMediator::isConflictError($response) && ResponseMediator::isError($response)) { |
||
| 32 | switch ($statusCode) { |
||
| 33 | case 401: |
||
| 34 | $message = 'Invalid Username/Password'; |
||
| 35 | break; |
||
| 36 | case 403: |
||
| 37 | $message = 'Your IP Address is Not Whitelisted'; |
||
| 38 | break; |
||
| 39 | default: |
||
| 40 | $message = is_array($content) ? $content['result'] : $content; |
||
| 41 | break; |
||
| 42 | } |
||
| 43 | |||
| 44 | throw NetworkException::createByCode($statusCode, $message); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $response; |
||
| 48 | }); |
||
| 51 |