| Conditions | 11 |
| Paths | 11 |
| Total Lines | 31 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 27 | public function getAction(RequestMethod $requestMethod, RestResource $resource): Action |
||
| 28 | { |
||
| 29 | switch ($requestMethod) { |
||
| 30 | case new DeleteRequestMethod(): |
||
| 31 | if (!$resource instanceof SupportsDeleteRequests) { |
||
| 32 | throw new UnsupportedRequestMethodException(); |
||
| 33 | } |
||
| 34 | return $resource->getDeleteCommand(); |
||
| 35 | case new GetRequestMethod(): |
||
| 36 | if (!$resource instanceof SupportsGetRequests) { |
||
| 37 | throw new UnsupportedRequestMethodException(); |
||
| 38 | } |
||
| 39 | return $resource->getQuery(); |
||
| 40 | case new PatchRequestMethod(): |
||
| 41 | if (!$resource instanceof SupportsPatchRequests) { |
||
| 42 | throw new UnsupportedRequestMethodException(); |
||
| 43 | } |
||
| 44 | return $resource->getPatchCommand(); |
||
| 45 | case new PostRequestMethod(): |
||
| 46 | if (!$resource instanceof SupportsPostRequests) { |
||
| 47 | throw new UnsupportedRequestMethodException(); |
||
| 48 | } |
||
| 49 | return $resource->getPostCommand(); |
||
| 50 | case new PutRequestMethod(): |
||
| 51 | if (!$resource instanceof SupportsPutRequests) { |
||
| 52 | throw new UnsupportedRequestMethodException(); |
||
| 53 | } |
||
| 54 | return $resource->getPutCommand(); |
||
| 55 | } |
||
| 56 | throw new UnsupportedRequestMethodException(); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |