| Conditions | 13 |
| Paths | 15 |
| Total Lines | 47 |
| Code Lines | 23 |
| 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 | protected function afterRequest(HTTPRequest $request, HTTPResponse $response) |
||
| 55 | { |
||
| 56 | $debugbar = DebugBar::getDebugBar(); |
||
| 57 | if (!$debugbar) { |
||
| 58 | return; |
||
| 59 | } |
||
| 60 | DebugBar::setRequest($request); |
||
| 61 | |||
| 62 | // All queries have been displayed |
||
| 63 | if (DebugBar::getShowQueries()) { |
||
| 64 | exit(); |
||
| 65 | } |
||
| 66 | |||
| 67 | $script = DebugBar::renderDebugBar(); |
||
| 68 | |||
| 69 | // If the bar is not renderable, return early |
||
| 70 | if (!$script) { |
||
| 71 | return; |
||
| 72 | } |
||
| 73 | |||
| 74 | // Inject init script into the HTML response |
||
| 75 | $body = $response->getBody(); |
||
| 76 | if (strpos($body, '</body>') !== false) { |
||
| 77 | $body = str_replace('</body>', $script . '</body>', $body); |
||
| 78 | $response->setBody($body); |
||
| 79 | } |
||
| 80 | |||
| 81 | // Ajax support |
||
| 82 | if (Director::is_ajax() && !headers_sent()) { |
||
| 83 | if (DebugBar::isAdminUrl() && !DebugBar::config()->enabled_in_admin) { |
||
| 84 | return; |
||
| 85 | } |
||
| 86 | // Skip anything that is not a GET request |
||
| 87 | if (!$request->isGET()) { |
||
| 88 | return; |
||
| 89 | } |
||
| 90 | // Always enable in admin because everything is mostly loaded through ajax |
||
| 91 | if (DebugBar::config()->ajax || DebugBar::isAdminUrl()) { |
||
| 92 | $headers = $debugbar->getDataAsHeaders(); |
||
| 93 | |||
| 94 | // Prevent throwing js errors in case header size is too large |
||
| 95 | if (is_array($headers)) { |
||
| 96 | $debugbar->sendDataInHeaders(); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.