Conditions | 10 |
Paths | 10 |
Total Lines | 24 |
Code Lines | 22 |
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 |
||
30 | static function create(RequestException $e) { |
||
|
|||
31 | switch ($e->getResponse()->getStatusCode()) { |
||
32 | case 400: |
||
33 | return new ValidationException($e); |
||
34 | case 401: |
||
35 | return new AuthenticationException($e); |
||
36 | case 403: |
||
37 | return new AccessDeniedException($e); |
||
38 | case 404: |
||
39 | return new NotFoundException($e); |
||
40 | case 405: |
||
41 | return new MethodNotAllowedException($e); |
||
42 | case 406: |
||
43 | return new UnsupportedAcceptHeaderException($e); |
||
44 | case 409: |
||
45 | return new ConflictingStateException($e); |
||
46 | case 415: |
||
47 | return new UnsupportedContentTypeException($e); |
||
48 | case 429: |
||
49 | return new RateLimitExceededException($e); |
||
50 | default: |
||
51 | return new ApiException($e); |
||
52 | } |
||
53 | } |
||
54 | |||
87 |
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.