| Conditions | 9 |
| Paths | 9 |
| Total Lines | 66 |
| 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 |
||
| 54 | public function returnResponse() : ResponseInterface |
||
| 55 | { |
||
| 56 | switch ($this->controllerResponse->getReturnType()) { |
||
| 57 | case Router::HTML: |
||
| 58 | return new HtmlResponse( |
||
| 59 | $this->renderResponse(), |
||
| 60 | $this->controllerResponse->getStatusCode(), |
||
| 61 | $this->getResponseHeaders() |
||
| 62 | ); |
||
| 63 | break; |
||
|
|
|||
| 64 | case Router::JSON: |
||
| 65 | return new JsonResponse( |
||
| 66 | $this->controllerResponse->getData(), |
||
| 67 | $this->controllerResponse->getStatusCode(), |
||
| 68 | $this->getResponseHeaders(), |
||
| 69 | JsonResponse::DEFAULT_JSON_FLAGS | JSON_PARTIAL_OUTPUT_ON_ERROR |
||
| 70 | ); |
||
| 71 | break; |
||
| 72 | case Router::TEXT: |
||
| 73 | return new TextResponse( |
||
| 74 | $this->renderResponse(), |
||
| 75 | $this->controllerResponse->getStatusCode(), |
||
| 76 | $this->getResponseHeaders() |
||
| 77 | ); |
||
| 78 | break; |
||
| 79 | case Router::XML: |
||
| 80 | return new XmlResponse( |
||
| 81 | $this->renderResponse(), |
||
| 82 | $this->controllerResponse->getStatusCode(), |
||
| 83 | $this->getResponseHeaders() |
||
| 84 | ); |
||
| 85 | break; |
||
| 86 | case Router::DOWNLOAD: |
||
| 87 | $metaData = $this->controllerResponse->getMetaData(); |
||
| 88 | /** |
||
| 89 | * @var $stream Stream |
||
| 90 | */ |
||
| 91 | $stream = $metaData['stream']; |
||
| 92 | return new Response( |
||
| 93 | $stream, |
||
| 94 | $this->controllerResponse->getStatusCode(), |
||
| 95 | $this->getResponseHeaders() |
||
| 96 | ); |
||
| 97 | break; |
||
| 98 | case Router::REDIRECT: |
||
| 99 | return new RedirectResponse( |
||
| 100 | $this->controllerResponse->getMetaData()['uri'], |
||
| 101 | $this->controllerResponse->getStatusCode(), |
||
| 102 | $this->getResponseHeaders() |
||
| 103 | ); |
||
| 104 | break; |
||
| 105 | case Router::CUSTOM: |
||
| 106 | return new HtmlResponse( |
||
| 107 | $this->renderResponse(), |
||
| 108 | $this->controllerResponse->getStatusCode(), |
||
| 109 | $this->getResponseHeaders() |
||
| 110 | ); |
||
| 111 | break; |
||
| 112 | case Router::EMPTY: |
||
| 113 | return new EmptyResponse( |
||
| 114 | $this->controllerResponse->getStatusCode(), |
||
| 115 | $this->getResponseHeaders() |
||
| 116 | ); |
||
| 117 | break; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 161 |
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.