| Conditions | 11 |
| Paths | 11 |
| Total Lines | 20 |
| Code Lines | 15 |
| 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 |
||
| 77 | protected function throwOnError(ServerRequestInterface $request, ResponseInterface $response): void |
||
| 78 | { |
||
| 79 | $status = $response->getStatusCode(); |
||
| 80 | |||
| 81 | switch ($status) { |
||
| 82 | case 400: throw new HttpBadRequestException($request, $this->getBody($response)); |
||
| 83 | case 401: throw new HttpUnauthorizedException($request, $this->getBody($response)); |
||
| 84 | case 403: throw new HttpForbiddenException($request, $this->getBody($response)); |
||
| 85 | case 404: throw new HttpNotFoundException($request, $this->getBody($response)); |
||
| 86 | case 405: throw new HttpMethodNotAllowedException($request, $this->getBody($response)); |
||
| 87 | case 410: |
||
| 88 | throw class_exists(HttpGoneException::class) |
||
| 89 | ? new HttpGoneException($request, $this->getBody($response)) |
||
| 90 | : new HttpException($request, $this->getBody($response), $status); |
||
| 91 | case 500: throw new HttpInternalServerErrorException($request, $this->getBody($response)); |
||
| 92 | case 501: throw new HttpNotImplementedException($request, $this->getBody($response)); |
||
| 93 | } |
||
| 94 | |||
| 95 | if ($status >= 400) { |
||
| 96 | throw new HttpException($request, $this->getBody($response), $status); |
||
| 97 | } |
||
| 105 | } |