diff --git a/src/DataProvider.php b/src/DataProvider.php index 06cbdd5..cdcfeda 100644 --- a/src/DataProvider.php +++ b/src/DataProvider.php @@ -46,10 +46,10 @@ public function onKernelRequest(RequestEvent $event): void $this->httpRequest = $event->getRequest(); $this->timestampStart = microtime(true); } - + return; } - + if (method_exists($event, 'isMainRequest')) { // Symfony < 5.3 if ($event->isMainRequest()) { $this->httpRequest = $event->getRequest(); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 3654ef9..181f7c6 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -16,21 +16,21 @@ public function getConfigTreeBuilder() // @phpstan-ignore-next-line $treeBuilder->getRootNode() ->children() - ->scalarNode('endpoint_url') - ->defaultValue('https://rocknrolla.treblle.com') - ->end() - ->scalarNode('project_id') - ->end() - ->scalarNode('api_key') - ->end() - ->booleanNode('debug') - ->end() - ->arrayNode('masked') - ->scalarPrototype()->end() - ->end() - ->arrayNode('ignore') - ->scalarPrototype()->end() - ->end() + ->scalarNode('endpoint_url') + ->defaultValue('https://rocknrolla.treblle.com') + ->end() + ->scalarNode('project_id') + ->end() + ->scalarNode('api_key') + ->end() + ->booleanNode('debug') + ->end() + ->arrayNode('masked') + ->scalarPrototype()->end() + ->end() + ->arrayNode('ignore') + ->scalarPrototype()->end() + ->end() ->end(); return $treeBuilder; diff --git a/src/DependencyInjection/TreblleConfiguration.php b/src/DependencyInjection/TreblleConfiguration.php index 12f6492..22d4343 100644 --- a/src/DependencyInjection/TreblleConfiguration.php +++ b/src/DependencyInjection/TreblleConfiguration.php @@ -6,30 +6,22 @@ class TreblleConfiguration { - /** @var string $apiKey */ private string $apiKey; - /** @var string $projectId */ private string $projectId; - /** @var string $endpointUrl */ private string $endpointUrl; - /** @var list $masked */ + /** @var list */ private array $masked; - /** @var list $ignore */ + /** @var list */ private array $ignore; - /** @var bool $debug */ private bool $debug; /** - * @param string $apiKey - * @param string $projectId - * @param string $endpointUrl * @param array $masked - * @param bool $debug * @param array $ignore */ public function __construct(string $apiKey, string $projectId, string $endpointUrl, array $masked, bool $debug, array $ignore = []) @@ -42,25 +34,16 @@ public function __construct(string $apiKey, string $projectId, string $endpointU $this->debug = $debug; } - /** - * @return string - */ public function getApiKey(): string { return $this->apiKey; } - /** - * @return string - */ public function getProjectId(): string { return $this->projectId; } - /** - * @return string - */ public function getEndpointUrl(): string { return $this->endpointUrl; @@ -74,9 +57,6 @@ public function getMasked(): array return $this->masked; } - /** - * @return bool - */ public function isDebug(): bool { return $this->debug; diff --git a/src/EventSubscriber/TreblleEventSubscriber.php b/src/EventSubscriber/TreblleEventSubscriber.php index 741c6f9..9d3fc97 100644 --- a/src/EventSubscriber/TreblleEventSubscriber.php +++ b/src/EventSubscriber/TreblleEventSubscriber.php @@ -28,14 +28,22 @@ public function __construct(Treblle $treblle, LoggerInterface $logger) public static function getSubscribedEvents(): array { return [ + KernelEvents::REQUEST => 'onKernelRequest', KernelEvents::TERMINATE => 'onKernelTerminate', KernelEvents::EXCEPTION => 'onException', ]; } + public function onKernelRequest(KernelEvent $event): void + { + $request = $event->getRequest(); + $requestId = $request->headers->get('X-TREBLLE-TRACE-ID', uniqid('req_', true)); + $request->attributes->set('requestId', $requestId); + } + public function onKernelTerminate(KernelEvent $event): void { - if (in_array($event->getRequest()->getRequestUri(), $this->treblle->ignoredUris(), true)) { + if (\in_array($event->getRequest()->getRequestUri(), $this->treblle->ignoredUris(), true)) { return; } diff --git a/src/TreblleBundle.php b/src/TreblleBundle.php index ee95ab8..abfc660 100644 --- a/src/TreblleBundle.php +++ b/src/TreblleBundle.php @@ -6,6 +6,4 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -final class TreblleBundle extends Bundle -{ -} +final class TreblleBundle extends Bundle {} diff --git a/tests/DataProviderTest.php b/tests/DataProviderTest.php index 7abeba3..c2d76d5 100644 --- a/tests/DataProviderTest.php +++ b/tests/DataProviderTest.php @@ -16,6 +16,7 @@ /** * @internal + * * @coversNothing * * @small diff --git a/tests/TreblleEventSubscriberTest.php b/tests/TreblleEventSubscriberTest.php index b0305fd..bcc7532 100644 --- a/tests/TreblleEventSubscriberTest.php +++ b/tests/TreblleEventSubscriberTest.php @@ -18,6 +18,7 @@ /** * @internal + * * @coversNothing * * @small @@ -26,7 +27,7 @@ final class TreblleEventSubscriberTest extends TestCase { private TreblleEventSubscriber $subjectUnderTest; - /** @var Treblle&MockObject */ + /** @var MockObject&Treblle */ private Treblle $treblle; protected function setUp(): void diff --git a/tests/TreblleIntegrationTest.php b/tests/TreblleIntegrationTest.php index a8e6d37..40b04d4 100644 --- a/tests/TreblleIntegrationTest.php +++ b/tests/TreblleIntegrationTest.php @@ -32,6 +32,7 @@ /** * @internal + * * @coversNothing * * @small @@ -46,7 +47,7 @@ final class TreblleIntegrationTest extends TestCase private array $container = []; - /** @var ServerDataProvider&MockObject */ + /** @var MockObject&ServerDataProvider */ private ServerDataProvider $serverDataProvider; /** @var LanguageDataProvider&MockObject */ @@ -93,7 +94,7 @@ protected function setUp(): void $this->eventSubscriber = new TreblleEventSubscriber($this->treblle, new NullLogger()); } - public function provideTestData(): iterable + public function provideIt_correctly_serializes_request_data_on_shutdownCases(): iterable { $server = new Server( '1.1.1.1', @@ -324,7 +325,7 @@ public function provideTestData(): iterable } /** - * @dataProvider provideTestData + * @dataProvider provideIt_correctly_serializes_request_data_on_shutdownCases */ public function test_it_correctly_serializes_request_data_on_shutdown( Server $server, diff --git a/tools/rector/config.php b/tools/rector/config.php index 574e982..136e9ea 100644 --- a/tools/rector/config.php +++ b/tools/rector/config.php @@ -15,7 +15,7 @@ $parameters->set(Option::PATHS, [ $basePath.'src', ]); -// $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80); + // $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80); $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_74); $parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__.'/tools/phpstan/config.neon'); $parameters->set(Option::SKIP, [ @@ -24,6 +24,6 @@ ]); $containerConfigurator->import(SetList::CODE_QUALITY); $containerConfigurator->import(SetList::PHP_74); -// $containerConfigurator->import(SetList::PHP_80); + // $containerConfigurator->import(SetList::PHP_80); $containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT); };