Conditions | 11 |
Paths | 11 |
Total Lines | 27 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | 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: |
||
83 | throw new HttpBadRequestException($request, $this->getBody($response)); |
||
84 | case 401: |
||
85 | throw new HttpUnauthorizedException($request, $this->getBody($response)); |
||
86 | case 403: |
||
87 | throw new HttpForbiddenException($request, $this->getBody($response)); |
||
88 | case 404: |
||
89 | throw new HttpNotFoundException($request, $this->getBody($response)); |
||
90 | case 405: |
||
91 | throw new HttpMethodNotAllowedException($request, $this->getBody($response)); |
||
92 | case 410: |
||
93 | throw class_exists(HttpGoneException::class) |
||
94 | ? new HttpGoneException($request, $this->getBody($response)) |
||
95 | : new HttpException($request, $this->getBody($response), $status); |
||
96 | case 500: |
||
97 | throw new HttpInternalServerErrorException($request, $this->getBody($response)); |
||
98 | case 501: |
||
99 | throw new HttpNotImplementedException($request, $this->getBody($response)); |
||
100 | } |
||
101 | |||
102 | if ($status >= 400) { |
||
103 | throw new HttpException($request, $this->getBody($response), $status); |
||
104 | } |
||
113 |