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