| Conditions | 10 |
| Paths | 22 |
| Total Lines | 48 |
| 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 |
||
| 15 | public function output(Collection $detectedQueries, Response $response) |
||
| 16 | { |
||
| 17 | |||
| 18 | $contentType = $response->headers->get('Content-Type'); |
||
| 19 | |||
| 20 | $validateContentTypeHTML = true; |
||
| 21 | |||
| 22 | if (env('QUERY_DETECTOR_AJAX', false)) { |
||
| 23 | if (request()->ajax()) { |
||
| 24 | if (stripos($contentType, 'application/json') === false || $response->isRedirection()) { |
||
| 25 | return; |
||
| 26 | } |
||
| 27 | |||
| 28 | $validateContentTypeHTML = false; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | if ($validateContentTypeHTML) { |
||
| 33 | if (stripos($contentType, 'text/html') !== 0 || $response->isRedirection()) { |
||
| 34 | return; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | $content = $response->getContent(); |
||
| 39 | |||
| 40 | $outputContent = $this->getOutputContent($detectedQueries); |
||
| 41 | |||
| 42 | $pos = strripos($content, '</body>'); |
||
| 43 | |||
| 44 | if (false !== $pos) { |
||
| 45 | $content = substr($content, 0, $pos) . $outputContent . substr($content, $pos); |
||
| 46 | } else { |
||
| 47 | if (!request()->ajax()) { |
||
| 48 | $content = $content . $outputContent; |
||
| 49 | } else { |
||
| 50 | $jsonResponseContent = json_decode($content); |
||
| 51 | |||
| 52 | $jsonResponseContent->laravelQueryDetector = $outputContent; |
||
| 53 | |||
| 54 | $content = json_encode($jsonResponseContent); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | // Update the new content and reset the content length |
||
| 59 | $response->setContent($content); |
||
| 60 | |||
| 61 | $response->headers->remove('Content-Length'); |
||
| 62 | } |
||
| 63 | |||
| 89 | } |