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