| Conditions | 19 |
| Paths | 157 |
| Total Lines | 53 |
| Code Lines | 26 |
| 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 |
||
| 55 | public function onKernelResponse(FilterResponseEvent $event): void |
||
| 56 | { |
||
| 57 | if (!$event->isMasterRequest()) { |
||
| 58 | return; |
||
| 59 | } |
||
| 60 | |||
| 61 | if (null === $this->newRelicTwigExtension || false === $this->newRelicTwigExtension->isUsed()) { |
||
| 62 | foreach ($this->newRelic->getCustomMetrics() as $name => $value) { |
||
| 63 | $this->interactor->addCustomMetric((string) $name, (float) $value); |
||
| 64 | } |
||
| 65 | |||
| 66 | foreach ($this->newRelic->getCustomParameters() as $name => $value) { |
||
| 67 | $this->interactor->addCustomParameter((string) $name, $value); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | foreach ($this->newRelic->getCustomEvents() as $name => $events) { |
||
| 72 | foreach ($events as $attributes) { |
||
| 73 | $this->interactor->addCustomEvent((string) $name, $attributes); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($this->instrument) { |
||
| 78 | if (null === $this->newRelicTwigExtension || false === $this->newRelicTwigExtension->isUsed()) { |
||
| 79 | $this->interactor->disableAutoRUM(); |
||
| 80 | } |
||
| 81 | |||
| 82 | // Some requests might not want to get instrumented |
||
| 83 | if ($event->getRequest()->attributes->get('_instrument', true)) { |
||
| 84 | $response = $event->getResponse(); |
||
| 85 | |||
| 86 | // We can only instrument HTML responses |
||
| 87 | if (!$response instanceof StreamedResponse |
||
| 88 | && 'text/html' === \substr($response->headers->get('Content-Type', ''), 0, 9) |
||
| 89 | ) { |
||
| 90 | $responseContent = $response->getContent(); |
||
| 91 | $response->setContent(''); // free the memory |
||
| 92 | |||
| 93 | if (null === $this->newRelicTwigExtension || false === $this->newRelicTwigExtension->isHeaderCalled()) { |
||
| 94 | $responseContent = \preg_replace('|<head>|i', '$0'.$this->interactor->getBrowserTimingHeader(), $responseContent); |
||
| 95 | } |
||
| 96 | |||
| 97 | if (null === $this->newRelicTwigExtension || false === $this->newRelicTwigExtension->isFooterCalled()) { |
||
| 98 | $responseContent = \preg_replace('|</body>|i', $this->interactor->getBrowserTimingFooter().'$0', $responseContent); |
||
| 99 | } |
||
| 100 | |||
| 101 | $response->setContent($responseContent); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($this->symfonyCache) { |
||
| 107 | $this->interactor->endTransaction(); |
||
| 108 | } |
||
| 111 |