From 14b3a51f51fc9f30753988ce939ac3bbad0d85aa Mon Sep 17 00:00:00 2001 From: Naumov Date: Sun, 23 Jul 2023 12:00:57 +0300 Subject: [PATCH] remove supported symfony below 5 --- Command/NotifyDeploymentCommand.php | 8 ++-- Listener/CommandListener.php | 10 +++-- Listener/DeprecationListener.php | 4 +- Listener/ExceptionListener.php | 17 ++------- Listener/RequestListener.php | 37 +++++++++---------- Listener/ResponseListener.php | 25 ++++--------- Logging/AdaptiveHandler.php | 4 ++ NewRelic/AdaptiveInteractor.php | 2 +- NewRelic/Config.php | 18 ++++----- NewRelic/LoggingInteractorDecorator.php | 4 +- NewRelic/NewRelicInteractor.php | 6 +-- .../DependencyInjection/ConfigurationTest.php | 8 ++-- Tests/Listener/DeprecationListenerTest.php | 2 +- Tests/Listener/ExceptionListenerTest.php | 5 +-- Tests/Listener/RequestListenerTest.php | 23 ++++++------ Tests/Listener/ResponseListenerTest.php | 25 ++++++------- Twig/NewRelicExtension.php | 10 ++--- composer.json | 16 ++++---- 18 files changed, 104 insertions(+), 120 deletions(-) diff --git a/Command/NotifyDeploymentCommand.php b/Command/NotifyDeploymentCommand.php index d6e5ab7..f5dee99 100644 --- a/Command/NotifyDeploymentCommand.php +++ b/Command/NotifyDeploymentCommand.php @@ -14,11 +14,14 @@ namespace Ekino\NewRelicBundle\Command; use Ekino\NewRelicBundle\NewRelic\Config; +use RuntimeException; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand(name: 'newrelic:notify-deployment', description: 'Notifies New Relic that a new deployment has been made')] class NotifyDeploymentCommand extends Command { public const EXIT_NO_APP_NAMES = 1; @@ -27,7 +30,7 @@ class NotifyDeploymentCommand extends Command protected static $defaultName = 'newrelic:notify-deployment'; - private $newrelic; + private Config $newrelic; public function __construct(Config $newrelic) { @@ -57,7 +60,6 @@ protected function configure(): void 'Text annotation for the deployment — notes for you', null ), ]) - ->setDescription('Notifies New Relic that a new deployment has been made') ; } @@ -120,7 +122,7 @@ public function performRequest(string $api_key, string $payload, ?string $api_ho error_reporting($level); if (false === $content) { $error = error_get_last(); - throw new \RuntimeException($error['message']); + throw new RuntimeException($error['message']); } $response = [ diff --git a/Listener/CommandListener.php b/Listener/CommandListener.php index 46463cb..189996c 100644 --- a/Listener/CommandListener.php +++ b/Listener/CommandListener.php @@ -22,10 +22,14 @@ class CommandListener implements EventSubscriberInterface { - private $interactor; - private $config; - private $ignoredCommands; + private NewRelicInteractorInterface $interactor; + private Config $config; + /** @var string[] */ + private array $ignoredCommands; + /** + * @param string[] $ignoredCommands + */ public function __construct(Config $config, NewRelicInteractorInterface $interactor, array $ignoredCommands) { $this->config = $config; diff --git a/Listener/DeprecationListener.php b/Listener/DeprecationListener.php index 08a9a69..ac3e307 100644 --- a/Listener/DeprecationListener.php +++ b/Listener/DeprecationListener.php @@ -18,8 +18,8 @@ class DeprecationListener { - private $isRegistered = false; - private $interactor; + private bool $isRegistered = false; + private NewRelicInteractorInterface $interactor; public function __construct(NewRelicInteractorInterface $interactor) { diff --git a/Listener/ExceptionListener.php b/Listener/ExceptionListener.php index c083859..9d77266 100644 --- a/Listener/ExceptionListener.php +++ b/Listener/ExceptionListener.php @@ -16,7 +16,6 @@ use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\ExceptionEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -25,7 +24,7 @@ */ class ExceptionListener implements EventSubscriberInterface { - private $interactor; + private NewRelicInteractorInterface $interactor; public function __construct(NewRelicInteractorInterface $interactor) { @@ -40,21 +39,13 @@ public static function getSubscribedEvents(): array } /** - * @param GetResponseForExceptionEvent|ExceptionEvent $event + * @param ExceptionEvent $event */ - public function onKernelException(KernelExceptionEvent $event): void + public function onKernelException(ExceptionEvent $event): void { - $exception = method_exists($event, 'getThrowable') ? $event->getThrowable() : $event->getException(); + $exception = $event->getThrowable(); if (!$exception instanceof HttpExceptionInterface) { $this->interactor->noticeThrowable($exception); } } } - -if (!class_exists(KernelExceptionEvent::class)) { - if (class_exists(ExceptionEvent::class)) { - class_alias(ExceptionEvent::class, KernelExceptionEvent::class); - } else { - class_alias(GetResponseForExceptionEvent::class, KernelExceptionEvent::class); - } -} diff --git a/Listener/RequestListener.php b/Listener/RequestListener.php index f8fa6a8..b614b7a 100644 --- a/Listener/RequestListener.php +++ b/Listener/RequestListener.php @@ -17,20 +17,25 @@ use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; use Ekino\NewRelicBundle\TransactionNamingStrategy\TransactionNamingStrategyInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; class RequestListener implements EventSubscriberInterface { - private $ignoredRoutes; - private $ignoredPaths; - private $config; - private $interactor; - private $transactionNamingStrategy; - private $symfonyCache; + /** @var string[] */ + private array $ignoredRoutes; + /** @var string[] */ + private array $ignoredPaths; + private Config $config; + private NewRelicInteractorInterface $interactor; + private TransactionNamingStrategyInterface $transactionNamingStrategy; + private bool $symfonyCache; + /** + * @param string[] $ignoreRoutes + * @param string[] $ignoredPaths + */ public function __construct( Config $config, NewRelicInteractorInterface $interactor, @@ -58,7 +63,7 @@ public static function getSubscribedEvents(): array ]; } - public function setApplicationName(KernelRequestEvent $event): void + public function setApplicationName(RequestEvent $event): void { if (!$this->isEventValid($event)) { return; @@ -80,7 +85,7 @@ public function setApplicationName(KernelRequestEvent $event): void } } - public function setTransactionName(KernelRequestEvent $event): void + public function setTransactionName(RequestEvent $event): void { if (!$this->isEventValid($event)) { return; @@ -91,7 +96,7 @@ public function setTransactionName(KernelRequestEvent $event): void $this->interactor->setTransactionName($transactionName); } - public function setIgnoreTransaction(KernelRequestEvent $event): void + public function setIgnoreTransaction(RequestEvent $event): void { if (!$this->isEventValid($event)) { return; @@ -110,16 +115,8 @@ public function setIgnoreTransaction(KernelRequestEvent $event): void /** * Make sure we should consider this event. Example: make sure it is a master request. */ - private function isEventValid(KernelRequestEvent $event): bool + private function isEventValid(RequestEvent $event): bool { - return HttpKernelInterface::MASTER_REQUEST === $event->getRequestType(); - } -} - -if (!class_exists(KernelRequestEvent::class)) { - if (class_exists(RequestEvent::class)) { - class_alias(RequestEvent::class, KernelRequestEvent::class); - } else { - class_alias(GetResponseEvent::class, KernelRequestEvent::class); + return HttpKernelInterface::MAIN_REQUEST === $event->getRequestType(); } } diff --git a/Listener/ResponseListener.php b/Listener/ResponseListener.php index a299abc..ab4e958 100644 --- a/Listener/ResponseListener.php +++ b/Listener/ResponseListener.php @@ -18,17 +18,16 @@ use Ekino\NewRelicBundle\Twig\NewRelicExtension; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\StreamedResponse; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; class ResponseListener implements EventSubscriberInterface { - private $newRelic; - private $interactor; - private $instrument; - private $symfonyCache; - private $newRelicTwigExtension; + private Config $newRelic; + private NewRelicInteractorInterface $interactor; + private bool $instrument; + private bool $symfonyCache; + private ?NewRelicExtension $newRelicTwigExtension; public function __construct( Config $newRelic, @@ -53,9 +52,9 @@ public static function getSubscribedEvents(): array ]; } - public function onKernelResponse(KernelResponseEvent $event): void + public function onKernelResponse(ResponseEvent $event): void { - $isMainRequest = method_exists($event, 'isMainRequest') ? $event->isMainRequest() : $event->isMasterRequest(); + $isMainRequest = $event->isMainRequest(); if (!$isMainRequest) { return; @@ -88,7 +87,7 @@ public function onKernelResponse(KernelResponseEvent $event): void // We can only instrument HTML responses if (!$response instanceof StreamedResponse - && 'text/html' === substr($response->headers->get('Content-Type', ''), 0, 9) + && str_starts_with($response->headers->get('Content-Type', ''), 'text/html') ) { $responseContent = $response->getContent(); $response->setContent(''); // free the memory @@ -111,11 +110,3 @@ public function onKernelResponse(KernelResponseEvent $event): void } } } - -if (!class_exists(KernelResponseEvent::class)) { - if (class_exists(ResponseEvent::class)) { - class_alias(ResponseEvent::class, KernelResponseEvent::class); - } else { - class_alias(FilterResponseEvent::class, KernelResponseEvent::class); - } -} diff --git a/Logging/AdaptiveHandler.php b/Logging/AdaptiveHandler.php index 396fa67..f600ae6 100644 --- a/Logging/AdaptiveHandler.php +++ b/Logging/AdaptiveHandler.php @@ -13,6 +13,7 @@ namespace Ekino\NewRelicBundle\Logging; +use Monolog\Handler\MissingExtensionException; use Monolog\Handler\NewRelicHandler; use Psr\Log\LogLevel; @@ -28,6 +29,9 @@ public function __construct( parent::__construct($level, $bubble, $appName, $explodeArrays, $transactionName); } + /** + * @throws MissingExtensionException + */ protected function write(array $record): void { if (!$this->isNewRelicEnabled()) { diff --git a/NewRelic/AdaptiveInteractor.php b/NewRelic/AdaptiveInteractor.php index ef4d9b9..31333c9 100644 --- a/NewRelic/AdaptiveInteractor.php +++ b/NewRelic/AdaptiveInteractor.php @@ -23,7 +23,7 @@ */ class AdaptiveInteractor implements NewRelicInteractorInterface { - private $interactor; + private NewRelicInteractorInterface $interactor; public function __construct(NewRelicInteractorInterface $real, NewRelicInteractorInterface $fake) { diff --git a/NewRelic/Config.php b/NewRelic/Config.php index 875d55a..b5022f2 100644 --- a/NewRelic/Config.php +++ b/NewRelic/Config.php @@ -18,15 +18,15 @@ */ class Config { - private $name; - private $apiKey; - private $apiHost = null; - private $licenseKey; - private $xmit; - private $customEvents; - private $customMetrics; - private $customParameters; - private $deploymentNames; + private string|false $name; + private ?string $apiKey; + private ?string $apiHost; + private string|false $licenseKey; + private bool $xmit; + private array $customEvents; + private array $customMetrics; + private array $customParameters; + private array $deploymentNames; public function __construct(?string $name, string $apiKey = null, string $licenseKey = null, bool $xmit = false, array $deploymentNames = [], ?string $apiHost = null) { diff --git a/NewRelic/LoggingInteractorDecorator.php b/NewRelic/LoggingInteractorDecorator.php index 996be29..17dceca 100644 --- a/NewRelic/LoggingInteractorDecorator.php +++ b/NewRelic/LoggingInteractorDecorator.php @@ -18,8 +18,8 @@ class LoggingInteractorDecorator implements NewRelicInteractorInterface { - private $interactor; - private $logger; + private NewRelicInteractorInterface $interactor; + private LoggerInterface|NullLogger $logger; public function __construct(NewRelicInteractorInterface $interactor, LoggerInterface $logger = null) { diff --git a/NewRelic/NewRelicInteractor.php b/NewRelic/NewRelicInteractor.php index dd5ce6b..4c87b4f 100644 --- a/NewRelic/NewRelicInteractor.php +++ b/NewRelic/NewRelicInteractor.php @@ -32,7 +32,7 @@ public function ignoreTransaction(): void public function addCustomEvent(string $name, array $attributes): void { - newrelic_record_custom_event((string) $name, $attributes); + newrelic_record_custom_event($name, $attributes); } public function addCustomMetric(string $name, float $value): bool @@ -42,7 +42,7 @@ public function addCustomMetric(string $name, float $value): bool public function addCustomParameter(string $name, $value): bool { - return newrelic_add_custom_parameter((string) $name, $value); + return newrelic_add_custom_parameter($name, $value); } public function getBrowserTimingHeader(bool $includeTags = true): string @@ -72,7 +72,7 @@ public function noticeThrowable(\Throwable $e, string $message = null): void public function enableBackgroundJob(): void { - newrelic_background_job(true); + newrelic_background_job(); } public function disableBackgroundJob(): void diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 1c7330e..560a49d 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -93,7 +93,7 @@ public function testDefaults() $this->assertIsArray($config['deployment_names']); } - public static function ignoredRoutesProvider() + public static function ignoredRoutesProvider(): array { return [ ['single_ignored_route', ['single_ignored_route']], @@ -102,7 +102,7 @@ public static function ignoredRoutesProvider() ]; } - public static function ignoredPathsProvider() + public static function ignoredPathsProvider(): array { return [ ['/single/ignored/path', ['/single/ignored/path']], @@ -111,7 +111,7 @@ public static function ignoredPathsProvider() ]; } - public static function ignoredCommandsProvider() + public static function ignoredCommandsProvider(): array { return [ ['single:ignored:command', ['single:ignored:command']], @@ -120,7 +120,7 @@ public static function ignoredCommandsProvider() ]; } - public static function deploymentNamesProvider() + public static function deploymentNamesProvider(): array { return [ ['App1', ['App1']], diff --git a/Tests/Listener/DeprecationListenerTest.php b/Tests/Listener/DeprecationListenerTest.php index 5354bcf..f0dd996 100644 --- a/Tests/Listener/DeprecationListenerTest.php +++ b/Tests/Listener/DeprecationListenerTest.php @@ -68,7 +68,7 @@ public function testOtherErrorAreIgnored() set_error_handler(function () { return false; }); try { $listener->register(); - @trigger_error('This is a notice', \E_USER_NOTICE); + @trigger_error('This is a notice'); } finally { $listener->unregister(); restore_error_handler(); diff --git a/Tests/Listener/ExceptionListenerTest.php b/Tests/Listener/ExceptionListenerTest.php index a1b59f1..1377427 100644 --- a/Tests/Listener/ExceptionListenerTest.php +++ b/Tests/Listener/ExceptionListenerTest.php @@ -18,7 +18,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\ExceptionEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -34,7 +33,7 @@ public function testOnKernelException() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request(); - $eventClass = class_exists(ExceptionEvent::class) ? ExceptionEvent::class : GetResponseForExceptionEvent::class; + $eventClass = ExceptionEvent::class; $event = new $eventClass($kernel, $request, HttpKernelInterface::SUB_REQUEST, $exception); $listener = new ExceptionListener($interactor); @@ -51,7 +50,7 @@ public function testOnKernelExceptionWithHttp() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request(); - $eventClass = class_exists(ExceptionEvent::class) ? ExceptionEvent::class : GetResponseForExceptionEvent::class; + $eventClass = ExceptionEvent::class; $event = new $eventClass($kernel, $request, HttpKernelInterface::SUB_REQUEST, $exception); $listener = new ExceptionListener($interactor); diff --git a/Tests/Listener/RequestListenerTest.php b/Tests/Listener/RequestListenerTest.php index 72a4bd4..d36e93c 100644 --- a/Tests/Listener/RequestListenerTest.php +++ b/Tests/Listener/RequestListenerTest.php @@ -20,7 +20,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -35,7 +34,7 @@ public function testSubRequest() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; + $eventClass = RequestEvent::class; $event = new $eventClass($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy); @@ -54,8 +53,8 @@ public function testMasterRequest() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy); $listener->setTransactionName($event); @@ -71,8 +70,8 @@ public function testPathIsIgnored() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request([], [], [], [], [], ['REQUEST_URI' => '/ignored_path']); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, $request, HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], ['/ignored_path'], $namingStrategy); $listener->setIgnoreTransaction($event); @@ -88,8 +87,8 @@ public function testRouteIsIgnored() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request([], [], ['_route' => 'ignored_route']); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, $request, HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, ['ignored_route'], [], $namingStrategy); $listener->setIgnoreTransaction($event); @@ -104,8 +103,8 @@ public function testSymfonyCacheEnabled() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy, true); $listener->setApplicationName($event); @@ -120,8 +119,8 @@ public function testSymfonyCacheDisabled() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; - $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); + $eventClass = RequestEvent::class; + $event = new $eventClass($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, new Response()); $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy, false); $listener->setApplicationName($event); diff --git a/Tests/Listener/ResponseListenerTest.php b/Tests/Listener/ResponseListenerTest.php index b8107d7..a46e2cb 100644 --- a/Tests/Listener/ResponseListenerTest.php +++ b/Tests/Listener/ResponseListenerTest.php @@ -20,7 +20,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -157,7 +156,7 @@ public function testOnKernelResponseOnlyInstrumentHTMLResponses($content, $expec $object->onKernelResponse($event); } - public function providerOnKernelResponseOnlyInstrumentHTMLResponses() + public function providerOnKernelResponseOnlyInstrumentHTMLResponses(): array { return [ // unsupported content types @@ -193,8 +192,8 @@ public function testInteractionWithTwigExtensionHeader() $this->extension->expects($this->once())->method('isHeaderCalled')->willReturn(true); $this->extension->expects($this->once())->method('isFooterCalled')->willReturn(false); - $request = $this->createRequestMock(true); - $response = $this->createResponseMock('content', 'content', 'text/html'); + $request = $this->createRequestMock(); + $response = $this->createResponseMock('content', 'content'); $event = $this->createFilterResponseEventDummy($request, $response); $object = new ResponseListener($this->newRelic, $this->interactor, true, false, $this->extension); @@ -215,8 +214,8 @@ public function testInteractionWithTwigExtensionFooter() $this->extension->expects($this->once())->method('isHeaderCalled')->willReturn(false); $this->extension->expects($this->once())->method('isFooterCalled')->willReturn(true); - $request = $this->createRequestMock(true); - $response = $this->createResponseMock('content', 'content', 'text/html'); + $request = $this->createRequestMock(); + $response = $this->createResponseMock('content', 'content'); $event = $this->createFilterResponseEventDummy($request, $response); $object = new ResponseListener($this->newRelic, $this->interactor, true, false, $this->extension); @@ -237,15 +236,15 @@ public function testInteractionWithTwigExtensionHeaderFooter() $this->extension->expects($this->once())->method('isHeaderCalled')->willReturn(true); $this->extension->expects($this->once())->method('isFooterCalled')->willReturn(true); - $request = $this->createRequestMock(true); - $response = $this->createResponseMock('content', 'content', 'text/html'); + $request = $this->createRequestMock(); + $response = $this->createResponseMock('content', 'content'); $event = $this->createFilterResponseEventDummy($request, $response); $object = new ResponseListener($this->newRelic, $this->interactor, true, false, $this->extension); $object->onKernelResponse($event); } - private function setUpNoCustomMetricsOrParameters() + private function setUpNoCustomMetricsOrParameters(): void { $this->newRelic->expects($this->once())->method('getCustomEvents')->willReturn([]); $this->newRelic->expects($this->once())->method('getCustomMetrics')->willReturn([]); @@ -287,13 +286,11 @@ private function createResponseMock($content = null, $expectsSetContent = null, return $mock; } - private function createFilterResponseEventDummy(Request $request = null, Response $response = null, int $requestType = HttpKernelInterface::MASTER_REQUEST) + private function createFilterResponseEventDummy(Request $request = null, Response $response = null, int $requestType = HttpKernelInterface::MAIN_REQUEST) { $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $eventClass = class_exists(ResponseEvent::class) ? ResponseEvent::class : FilterResponseEvent::class; - $event = new $eventClass($kernel, $request ?? new Request(), $requestType, $response ?? new Response()); - - return $event; + $eventClass = ResponseEvent::class; + return new $eventClass($kernel, $request ?? new Request(), $requestType, $response ?? new Response()); } } diff --git a/Twig/NewRelicExtension.php b/Twig/NewRelicExtension.php index e446d48..7e2ce87 100644 --- a/Twig/NewRelicExtension.php +++ b/Twig/NewRelicExtension.php @@ -23,11 +23,11 @@ */ class NewRelicExtension extends AbstractExtension { - private $newRelic; - private $interactor; - private $instrument; - private $headerCalled = false; - private $footerCalled = false; + private Config $newRelic; + private NewRelicInteractorInterface $interactor; + private bool $instrument; + private bool $headerCalled = false; + private bool $footerCalled = false; public function __construct( Config $newRelic, diff --git a/composer.json b/composer.json index 357653c..aab3b9d 100644 --- a/composer.json +++ b/composer.json @@ -9,20 +9,20 @@ { "name": "Thomas Rabaix", "email": "thomas.rabaix@ekino.com", - "homepage": "http://ekino.com" + "homepage": "https://www.ekino.com/" } ], "require": { - "php": "^7.1 | ^8.0", - "symfony/config": "^3.4|^4.0|^5.0|^6.0", - "symfony/console": "^3.4|^4.0|^5.0|^6.0", - "symfony/dependency-injection": "^3.4|^4.0|^5.0|^6.0", - "symfony/event-dispatcher": "^3.4|^4.0|^5.0|^6.0", - "symfony/http-kernel": "^3.4|^4.0|^5.0|^6.0" + "php": "^8.0", + "symfony/config": "^5.0|^6.0", + "symfony/console": "^5.0|^6.0", + "symfony/dependency-injection": "^5.0|^6.0", + "symfony/event-dispatcher": "^5.0|^6.0", + "symfony/http-kernel": "^5.0|^6.0" }, "require-dev": { "matthiasnoback/symfony-dependency-injection-test": "^3.1|^4.0", - "symfony/framework-bundle": "^3.4|^4.0|^5.0|^6.0", + "symfony/framework-bundle": "^5.0|^6.0", "symfony/phpunit-bridge": "^5.3", "symfony/debug": ">3.4.21", "twig/twig": "^1.32|^2.4",