| Conditions | 10 |
| Paths | 10 |
| Total Lines | 22 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 2 | Features | 1 |
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 |
||
| 7 | public function setProperHeader(\Exception $exception) |
||
| 8 | { |
||
| 9 | if ($exception instanceof \ByJG\RestServer\Exception\Error401Exception) { |
||
| 10 | header('HTTP/1.0 401 Unathorized', true, 401); |
||
| 11 | } elseif ($exception instanceof \ByJG\RestServer\Exception\Error402Exception) { |
||
| 12 | header('HTTP/1.0 402 Payment Required', true, 402); |
||
| 13 | } elseif ($exception instanceof \ByJG\RestServer\Exception\Error403Exception) { |
||
| 14 | header('HTTP/1.0 403 Forbidden', true, 403); |
||
| 15 | } elseif ($exception instanceof \ByJG\RestServer\Exception\Error404Exception) { |
||
| 16 | header('HTTP/1.0 404 Not Found', true, 404); |
||
| 17 | } elseif ($exception instanceof \ByJG\RestServer\Exception\ClassNotFoundException) { |
||
| 18 | header('HTTP/1.0 404 Not Found', true, 404); |
||
| 19 | } elseif ($exception instanceof \ByJG\RestServer\Exception\Error405Exception) { |
||
| 20 | header('HTTP/1.0 405 Method not allowed', true, 405); |
||
| 21 | } elseif ($exception instanceof \ByJG\RestServer\Exception\Error501Exception) { |
||
| 22 | header('HTTP/1.0 501 Not Implemented', true, 501); |
||
| 23 | } elseif ($exception instanceof \BadMethodCallException) { |
||
| 24 | header('HTTP/1.0 501 Not Implemented', true, 501); |
||
| 25 | } elseif ($exception instanceof \ByJG\RestServer\Exception\Error520Exception) { |
||
| 26 | header('HTTP/1.0 520 Unknow Error', true, 501); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | } |
||
| 30 |