| Conditions | 10 |
| Paths | 50 |
| Total Lines | 50 |
| Code Lines | 34 |
| Lines | 12 |
| Ratio | 24 % |
| 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 |
||
| 82 | public function run(Request $request) |
||
| 83 | { |
||
| 84 | try { |
||
| 85 | switch ($request->getRequestMethod()) { |
||
| 86 | case 'GET': |
||
| 87 | return $this->handleGet($request); |
||
| 88 | case 'POST': |
||
| 89 | return $this->handlePost($request); |
||
| 90 | View Code Duplication | case 'PUT': |
|
| 91 | $tokenInfo = $this->auth['bearer']->requireAuth($request); |
||
| 92 | |||
| 93 | return $this->apiModule->put($request, $tokenInfo); |
||
| 94 | View Code Duplication | case 'DELETE': |
|
| 95 | $tokenInfo = $this->auth['bearer']->requireAuth($request); |
||
| 96 | |||
| 97 | return $this->apiModule->delete($request, $tokenInfo); |
||
| 98 | case 'OPTIONS': |
||
| 99 | return $this->apiModule->options($request); |
||
| 100 | View Code Duplication | case 'HEAD': |
|
| 101 | $tokenInfo = $this->auth['bearer']->optionalAuth($request); |
||
| 102 | |||
| 103 | return $this->apiModule->head($request, $tokenInfo); |
||
| 104 | default: |
||
| 105 | throw new HttpException('method not allowed', 405); |
||
| 106 | } |
||
| 107 | } catch (HttpException $e) { |
||
| 108 | if ($request->isBrowser()) { |
||
| 109 | $response = new Response($e->getCode(), 'text/html'); |
||
| 110 | $response->setBody( |
||
| 111 | $this->templateManager->render( |
||
| 112 | 'error', |
||
| 113 | [ |
||
| 114 | 'code' => $e->getCode(), |
||
| 115 | 'message' => $e->getMessage(), |
||
| 116 | ] |
||
| 117 | ) |
||
| 118 | ); |
||
| 119 | } else { |
||
| 120 | // not a browser |
||
| 121 | $response = new Response($e->getCode(), 'application/json'); |
||
| 122 | $response->setBody(json_encode(['error' => $e->getMessage()])); |
||
| 123 | } |
||
| 124 | |||
| 125 | foreach ($e->getResponseHeaders() as $key => $value) { |
||
| 126 | $response->addHeader($key, $value); |
||
| 127 | } |
||
| 128 | |||
| 129 | return $response; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 182 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.