| Conditions | 9 |
| Paths | 9 |
| Total Lines | 60 |
| 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 |
||
| 39 | public function returnResponse() : ResponseInterface |
||
| 40 | { |
||
| 41 | switch ($this->controllerResponse->getReturnType()) { |
||
| 42 | case Router::HTML: |
||
| 43 | return new HtmlResponse( |
||
| 44 | $this->renderResponse(), |
||
| 45 | $this->controllerResponse->getStatusCode(), |
||
| 46 | $this->controllerResponse->getHeaders() |
||
| 47 | ); |
||
| 48 | break; |
||
|
|
|||
| 49 | case Router::JSON: |
||
| 50 | return new JsonResponse( |
||
| 51 | $this->controllerResponse->getData(), |
||
| 52 | $this->controllerResponse->getStatusCode(), |
||
| 53 | $this->controllerResponse->getHeaders() |
||
| 54 | ); |
||
| 55 | break; |
||
| 56 | case Router::TEXT: |
||
| 57 | return new TextResponse( |
||
| 58 | $this->renderResponse(), |
||
| 59 | $this->controllerResponse->getStatusCode(), |
||
| 60 | $this->controllerResponse->getHeaders() |
||
| 61 | ); |
||
| 62 | break; |
||
| 63 | case Router::XML: |
||
| 64 | return new XmlResponse( |
||
| 65 | $this->renderResponse(), |
||
| 66 | $this->controllerResponse->getStatusCode(), |
||
| 67 | $this->controllerResponse->getHeaders() |
||
| 68 | ); |
||
| 69 | break; |
||
| 70 | case Router::DOWNLOAD: |
||
| 71 | $stream = $this->controllerResponse->getMetaData()['stream']->read(); |
||
| 72 | return (new EmptyResponse( |
||
| 73 | $this->controllerResponse->getStatusCode(), |
||
| 74 | $this->controllerResponse->getHeaders() |
||
| 75 | ))->withBody($stream); |
||
| 76 | break; |
||
| 77 | case Router::REDIRECT: |
||
| 78 | return new RedirectResponse( |
||
| 79 | $this->controllerResponse->getMetaData()['uri'], |
||
| 80 | $this->controllerResponse->getStatusCode(), |
||
| 81 | $this->controllerResponse->getHeaders() |
||
| 82 | ); |
||
| 83 | break; |
||
| 84 | case Router::CUSTOM: |
||
| 85 | return new HtmlResponse( |
||
| 86 | $this->renderResponse(), |
||
| 87 | $this->controllerResponse->getStatusCode(), |
||
| 88 | $this->controllerResponse->getHeaders() |
||
| 89 | ); |
||
| 90 | break; |
||
| 91 | case Router::EMPTY: |
||
| 92 | return new EmptyResponse( |
||
| 93 | $this->controllerResponse->getStatusCode(), |
||
| 94 | $this->controllerResponse->getHeaders() |
||
| 95 | ); |
||
| 96 | break; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 140 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.