Conditions | 11 |
Paths | 8 |
Total Lines | 33 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
28 | public function transformResponseToException( |
||
29 | RequestInterface $request, |
||
30 | ResponseInterface $response |
||
31 | ): ResponseInterface { |
||
32 | if ($response->getStatusCode() >= 300 && $response->getStatusCode() < 400) { |
||
33 | throw new RedirectionHttpException($response->getReasonPhrase(), $request, $response); |
||
34 | } |
||
35 | |||
36 | if ($response->getStatusCode() === 400) { |
||
37 | throw new BadRequestHttpException($response->getReasonPhrase(), $request, $response); |
||
38 | } |
||
39 | |||
40 | if ($response->getStatusCode() === 401) { |
||
41 | throw new UnauthorizedHttpException($response->getReasonPhrase(), $request, $response); |
||
42 | } |
||
43 | |||
44 | if ($response->getStatusCode() === 404) { |
||
45 | throw new NotFoundHttpException($response->getReasonPhrase(), $request, $response); |
||
46 | } |
||
47 | |||
48 | if ($response->getStatusCode() === 422) { |
||
49 | throw new UnprocessableEntityHttpException($response->getReasonPhrase(), $request, $response); |
||
50 | } |
||
51 | |||
52 | if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500) { |
||
53 | throw new ClientErrorHttpException($response->getReasonPhrase(), $request, $response); |
||
54 | } |
||
55 | |||
56 | if ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) { |
||
57 | throw new ServerErrorHttpException($response->getReasonPhrase(), $request, $response); |
||
58 | } |
||
59 | |||
60 | return $response; |
||
61 | } |
||
63 |