| Conditions | 9 |
| Paths | 7 |
| Total Lines | 51 |
| Code Lines | 33 |
| 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 |
||
| 58 | public static function sendResponse(int $status = 200, $body = '', string $content_type = |
||
| 59 | 'text/html') |
||
| 60 | { |
||
| 61 | $status_header = self::$httpVersion . $status . ' ' |
||
| 62 | . RestUtilities::getStatusCodeMessage($status); |
||
| 63 | |||
| 64 | |||
| 65 | $ob = ini_get('output_buffering'); |
||
| 66 | |||
| 67 | // Abort the method if headers have already been sent, except when output buffering has been enabled |
||
| 68 | if (headers_sent() && false === (bool)$ob || 'off' == strtolower($ob)) { |
||
| 69 | return new self(); |
||
| 70 | } |
||
| 71 | |||
| 72 | header($status_header); |
||
| 73 | header('Access-Control-allow-Origin:*'); |
||
| 74 | header('Access-Control-allow-Methods:POST, GET, DELETE, PUT'); |
||
| 75 | header('Content-type: ' . $content_type); |
||
| 76 | header('Content-length: ' . strlen($body)); |
||
| 77 | if ($body != '') { |
||
| 78 | return $body; |
||
| 79 | exit; |
||
| 80 | } |
||
| 81 | $msg = ''; |
||
| 82 | switch ($status_header) { |
||
| 83 | case 401: |
||
| 84 | $msg = 'You must be authorized to view this page.'; |
||
| 85 | break; |
||
| 86 | case 404: |
||
| 87 | $msg = 'The requested URL was not found.'; |
||
| 88 | break; |
||
| 89 | case 500: |
||
| 90 | $msg = 'The server encountered an error processing your request.'; |
||
| 91 | break; |
||
| 92 | case 501: |
||
| 93 | $msg = 'The requested method is not implemented.'; |
||
| 94 | |||
| 95 | break; |
||
| 96 | } |
||
| 97 | $body = "<!DOCTYPE html> |
||
| 98 | <html lang='en'> |
||
| 99 | <head> |
||
| 100 | <meta charset='utf-8'> |
||
| 101 | <title>" . $status . ' ' . |
||
| 102 | self::getStatusCodeMessage($status) . "</title> |
||
| 103 | </head> |
||
| 104 | <body> |
||
| 105 | <h1>" . self::getStatusCodeMessage($status) . "</h1> |
||
| 106 | <p>" . $msg . "</p> |
||
| 107 | </body></html>"; |
||
| 108 | return $body; |
||
| 109 | |||
| 141 | } |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.