From 845a43ed09abc4b6168cd86e13b70a28dcd27e4b Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sun, 14 Nov 2021 17:20:02 +0100 Subject: [PATCH 01/11] Update PHPStan and PHP-CS-Fixer to their latest version --- .gitignore | 2 +- .php_cs.dist => .php-cs-fixer.dist.php | 8 ++-- composer.json | 9 ++-- phpstan-baseline.neon | 45 ++++++++++++------- phpstan.neon | 2 +- .../SentryExtensionTest.php | 5 +++ .../AbstractConsoleListenerTest.php | 2 + tests/EventListener/MessengerListenerTest.php | 1 + tests/EventListener/RequestListenerTest.php | 2 + .../AbstractTraceableCacheAdapterTest.php | 13 ++++++ .../TraceableTagAwareCacheAdapterTest.php | 1 + .../DBAL/TracingDriverConnectionTest.php | 6 +++ .../DBAL/TracingStatementForV2Test.php | 1 + .../DBAL/TracingStatementForV3Test.php | 1 + .../Tracing/Twig/TwigTracingExtensionTest.php | 4 ++ 15 files changed, 77 insertions(+), 25 deletions(-) rename .php_cs.dist => .php-cs-fixer.dist.php (91%) diff --git a/.gitignore b/.gitignore index 06b9bba8..07086ad8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ package.xml /vendor .idea -.php_cs.cache +.php-cs-fixer.cache .phpunit.result.cache docs/_build var diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 91% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 8da7956b..7136604b 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -1,6 +1,9 @@ setRiskyAllowed(true) ->setRules([ '@PSR2' => true, '@Symfony' => true, @@ -11,8 +14,6 @@ 'imports_order' => ['class', 'function', 'const'], ], 'declare_strict_types' => true, - 'psr0' => true, - 'psr4' => true, 'random_api_migration' => true, 'yoda_style' => true, 'self_accessor' => false, @@ -27,7 +28,6 @@ 'property' => 'multi', ], ]) - ->setRiskyAllowed(true) ->setFinder( PhpCsFixer\Finder::create() ->in(__DIR__) diff --git a/composer.json b/composer.json index 1cbc4a63..7034bb0f 100644 --- a/composer.json +++ b/composer.json @@ -40,14 +40,15 @@ "require-dev": { "doctrine/dbal": "^2.13||^3.0", "doctrine/doctrine-bundle": "^1.12||^2.5", - "friendsofphp/php-cs-fixer": "^2.18", - "jangregor/phpstan-prophecy": "^0.8", + "friendsofphp/php-cs-fixer": "^3.2", + "jangregor/phpstan-prophecy": "^1.0", "monolog/monolog": "^1.3||^2.0", "phpspec/prophecy": "!=1.11.0", "phpspec/prophecy-phpunit": "^1.1||^2.0", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^8.5.14||^9.3.9", "symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11||^6.0", "symfony/cache": "^3.4.44||^4.4.20||^5.0.11||^6.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8b1503d9..48630124 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,10 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:booleanNode\\(\\)\\.$#" - count: 1 - path: src/DependencyInjection/Configuration.php - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\TreeBuilder\\:\\:root\\(\\)\\.$#" count: 1 @@ -20,6 +15,11 @@ parameters: count: 1 path: src/EventListener/AbstractTracingRequestListener.php + - + message: "#^Class Sentry\\\\SentryBundle\\\\EventListener\\\\ConsoleCommandListener extends @final class Sentry\\\\SentryBundle\\\\EventListener\\\\ConsoleListener\\.$#" + count: 1 + path: src/EventListener/ConsoleCommandListener.php + - message: "#^Else branch is unreachable because previous condition is always true\\.$#" count: 1 @@ -41,17 +41,27 @@ parameters: path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:exec\\(\\) has parameter \\$sql with no typehint specified\\.$#" + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:exec\\(\\) has parameter \\$sql with no type specified\\.$#" count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:prepare\\(\\) has parameter \\$sql with no typehint specified\\.$#" + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:prepare\\(\\) has parameter \\$sql with no type specified\\.$#" count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:query\\(\\) has parameter \\$args with no typehint specified\\.$#" + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:query\\(\\) has parameter \\$args with no type specified\\.$#" + count: 1 + path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php + + - + message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Driver\\\\Connection\\:\\:query\\(\\) expects string, string\\|null given\\.$#" + count: 1 + path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php + + - + message: "#^Parameter \\#2 \\$spanDescription of method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:traceFunction\\(\\) expects string, string\\|null given\\.$#" count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php @@ -61,17 +71,22 @@ parameters: path: src/Tracing/Doctrine/DBAL/TracingServerInfoAwareDriverConnection.php - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingServerInfoAwareDriverConnection\\:\\:exec\\(\\) has parameter \\$sql with no typehint specified\\.$#" + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingServerInfoAwareDriverConnection\\:\\:exec\\(\\) has parameter \\$sql with no type specified\\.$#" + count: 1 + path: src/Tracing/Doctrine/DBAL/TracingServerInfoAwareDriverConnection.php + + - + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingServerInfoAwareDriverConnection\\:\\:prepare\\(\\) has parameter \\$sql with no type specified\\.$#" count: 1 path: src/Tracing/Doctrine/DBAL/TracingServerInfoAwareDriverConnection.php - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingServerInfoAwareDriverConnection\\:\\:prepare\\(\\) has parameter \\$sql with no typehint specified\\.$#" + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingServerInfoAwareDriverConnection\\:\\:query\\(\\) has parameter \\$args with no type specified\\.$#" count: 1 path: src/Tracing/Doctrine/DBAL/TracingServerInfoAwareDriverConnection.php - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingServerInfoAwareDriverConnection\\:\\:query\\(\\) has parameter \\$args with no typehint specified\\.$#" + message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Driver\\\\Connection\\:\\:query\\(\\) expects string, string\\|null given\\.$#" count: 1 path: src/Tracing/Doctrine/DBAL/TracingServerInfoAwareDriverConnection.php @@ -101,7 +116,7 @@ parameters: path: tests/EventListener/ErrorListenerTest.php - - message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\ErrorListenerTest\\:\\:testHandleExceptionEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent\\.$#" + message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\ErrorListenerTest\\:\\:testHandleExceptionEvent\\(\\) has invalid type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent\\.$#" count: 1 path: tests/EventListener/ErrorListenerTest.php @@ -146,12 +161,12 @@ parameters: path: tests/EventListener/RequestListenerTest.php - - message: "#^Parameter \\$controllerEvent of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelControllerEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent\\.$#" + message: "#^Parameter \\$controllerEvent of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelControllerEvent\\(\\) has invalid type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent\\.$#" count: 1 path: tests/EventListener/RequestListenerTest.php - - message: "#^Parameter \\$requestEvent of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelRequestEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\.$#" + message: "#^Parameter \\$requestEvent of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelRequestEvent\\(\\) has invalid type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\.$#" count: 1 path: tests/EventListener/RequestListenerTest.php @@ -176,7 +191,7 @@ parameters: path: tests/EventListener/SubRequestListenerTest.php - - message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\SubRequestListenerTest\\:\\:testHandleKernelRequestEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\.$#" + message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\SubRequestListenerTest\\:\\:testHandleKernelRequestEvent\\(\\) has invalid type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\.$#" count: 1 path: tests/EventListener/SubRequestListenerTest.php diff --git a/phpstan.neon b/phpstan.neon index 5eabf3b3..6b9b4e31 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,7 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: 7 + level: 8 paths: - src - tests diff --git a/tests/DependencyInjection/SentryExtensionTest.php b/tests/DependencyInjection/SentryExtensionTest.php index 42ce7b4c..adb04f95 100644 --- a/tests/DependencyInjection/SentryExtensionTest.php +++ b/tests/DependencyInjection/SentryExtensionTest.php @@ -233,11 +233,13 @@ public function testClientIsCreatedFromOptions(): void $clientDefinition = $container->findDefinition(ClientInterface::class); $factory = $clientDefinition->getFactory(); + $this->assertIsArray($factory); $this->assertInstanceOf(Definition::class, $factory[0]); $this->assertSame('getClient', $factory[1]); $methodCalls = $factory[0]->getMethodCalls(); + $this->assertCount(4, $methodCalls); $this->assertDefinitionMethodCallAt($methodCalls[0], 'setSdkIdentifier', [SentryBundle::SDK_IDENTIFIER]); $this->assertDefinitionMethodCallAt($methodCalls[1], 'setSdkVersion', [PrettyVersions::getVersion('sentry/sentry-symfony')->getPrettyVersion()]); $this->assertDefinitionMethodCallAt($methodCalls[2], 'setTransportFactory', [new Reference('App\\Sentry\\Transport\\TransportFactory')]); @@ -395,6 +397,9 @@ public function testLoggerOptionFallbackToNullLoggerIfNotSet(): void $container = $this->createContainerFromFixture('logger_service_not_set'); $clientDefinition = $container->findDefinition(ClientInterface::class); $factory = $clientDefinition->getFactory(); + + $this->assertIsArray($factory); + $methodCalls = $factory[0]->getMethodCalls(); $this->assertDefinitionMethodCallAt($methodCalls[5], 'setLogger', [new Reference(NullLogger::class, ContainerBuilder::IGNORE_ON_INVALID_REFERENCE)]); diff --git a/tests/EventListener/AbstractConsoleListenerTest.php b/tests/EventListener/AbstractConsoleListenerTest.php index 36eb14dd..9e124523 100644 --- a/tests/EventListener/AbstractConsoleListenerTest.php +++ b/tests/EventListener/AbstractConsoleListenerTest.php @@ -50,6 +50,7 @@ public function testHandleConsoleCommandEvent(ConsoleCommandEvent $consoleEvent, $event = $scope->applyToEvent(Event::createEvent()); + $this->assertNotNull($event); $this->assertSame($expectedTags, $event->getTags()); $this->assertSame($expectedExtra, $event->getExtra()); } @@ -119,6 +120,7 @@ public function testHandleConsoleErrorEvent(bool $captureErrors): void $event = $scope->applyToEvent(Event::createEvent()); + $this->assertNotNull($event); $this->assertSame(['console.command.exit_code' => '1'], $event->getTags()); } diff --git a/tests/EventListener/MessengerListenerTest.php b/tests/EventListener/MessengerListenerTest.php index d2dd4db5..04976652 100644 --- a/tests/EventListener/MessengerListenerTest.php +++ b/tests/EventListener/MessengerListenerTest.php @@ -72,6 +72,7 @@ public function testHandleWorkerMessageFailedEvent(array $exceptions, WorkerMess $sentryEvent = $scope->applyToEvent(Event::createEvent()); + $this->assertNotNull($sentryEvent); $this->assertSame($expectedTags, $sentryEvent->getTags()); } diff --git a/tests/EventListener/RequestListenerTest.php b/tests/EventListener/RequestListenerTest.php index df659d96..863dddbd 100644 --- a/tests/EventListener/RequestListenerTest.php +++ b/tests/EventListener/RequestListenerTest.php @@ -79,6 +79,7 @@ public function testHandleKernelRequestEvent($requestEvent, ?ClientInterface $cl $event = $scope->applyToEvent(Event::createEvent()); + $this->assertNotNull($event); $this->assertEquals($expectedUser, $event->getUser()); } @@ -344,6 +345,7 @@ public function testHandleKernelControllerEvent($controllerEvent, array $expecte $event = $scope->applyToEvent(Event::createEvent()); + $this->assertNotNull($event); $this->assertSame($expectedTags, $event->getTags()); } diff --git a/tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php b/tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php index 3f1b2c65..4b50bdf4 100644 --- a/tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php +++ b/tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php @@ -58,6 +58,7 @@ public function testGetItem(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertSame($cacheItem, $adapter->getItem('foo')); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -85,6 +86,7 @@ public function testGetItems(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertSame($cacheItems, $adapter->getItems(['foo'])); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -111,6 +113,7 @@ public function testClear(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->clear('foo')); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -139,6 +142,7 @@ public function testGet(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertSame('bar', $adapter->get('foo', $callback, 1.0, $metadata)); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -175,6 +179,7 @@ public function testDelete(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->delete('foo')); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -211,6 +216,7 @@ public function testHasItem(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->hasItem('foo')); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -237,6 +243,7 @@ public function testDeleteItem(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->deleteItem('foo')); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -263,6 +270,7 @@ public function testDeleteItems(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->deleteItems(['foo'])); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -290,6 +298,7 @@ public function testSave(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->save($cacheItem)); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -317,6 +326,7 @@ public function testSaveDeferred(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->saveDeferred($cacheItem)); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -342,6 +352,7 @@ public function testCommit(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->commit()); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -367,6 +378,7 @@ public function testPrune(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->prune()); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -387,6 +399,7 @@ public function testPruneReturnsFalseIfDecoratedAdapterIsNotPruneable(): void $adapter = $this->createCacheAdapter($this->createMock(static::getAdapterClassFqcn())); $this->assertFalse($adapter->prune()); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); diff --git a/tests/Tracing/Cache/TraceableTagAwareCacheAdapterTest.php b/tests/Tracing/Cache/TraceableTagAwareCacheAdapterTest.php index f5091973..d856601e 100644 --- a/tests/Tracing/Cache/TraceableTagAwareCacheAdapterTest.php +++ b/tests/Tracing/Cache/TraceableTagAwareCacheAdapterTest.php @@ -33,6 +33,7 @@ public function testInvalidateTags(): void $adapter = $this->createCacheAdapter($decoratedAdapter); $this->assertTrue($adapter->invalidateTags(['foo'])); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); diff --git a/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php b/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php index 4d135447..3fb29a59 100644 --- a/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php +++ b/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php @@ -73,6 +73,7 @@ public function testPrepare(array $params, array $expectedTags): void ->willReturn($statement); $this->assertEquals($resultStatement, $connection->prepare($sql)); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -126,6 +127,7 @@ public function testQuery(array $params, array $expectedTags): void ->willReturn($result); $this->assertSame($result, $connection->query($sql)); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -187,6 +189,7 @@ public function testExec(array $params, array $expectedTags): void ->willReturn(10); $this->assertSame(10, $connection->exec($sql)); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -228,6 +231,7 @@ public function testBeginTransaction(array $params, array $expectedTags): void ->willReturn(false); $this->assertFalse($connection->beginTransaction()); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -272,6 +276,7 @@ public function testCommit(array $params, array $expectedTags): void ->willReturn(false); $this->assertFalse($connection->commit()); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -316,6 +321,7 @@ public function testRollBack(array $params, array $expectedTags): void ->willReturn(false); $this->assertFalse($connection->rollBack()); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); diff --git a/tests/Tracing/Doctrine/DBAL/TracingStatementForV2Test.php b/tests/Tracing/Doctrine/DBAL/TracingStatementForV2Test.php index e923a490..75fa17b6 100644 --- a/tests/Tracing/Doctrine/DBAL/TracingStatementForV2Test.php +++ b/tests/Tracing/Doctrine/DBAL/TracingStatementForV2Test.php @@ -162,6 +162,7 @@ public function testExecute(): void ->willReturn(true); $this->assertTrue($this->statement->execute(['foo' => 'bar'])); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); diff --git a/tests/Tracing/Doctrine/DBAL/TracingStatementForV3Test.php b/tests/Tracing/Doctrine/DBAL/TracingStatementForV3Test.php index f6102acb..b04c7bdc 100644 --- a/tests/Tracing/Doctrine/DBAL/TracingStatementForV3Test.php +++ b/tests/Tracing/Doctrine/DBAL/TracingStatementForV3Test.php @@ -83,6 +83,7 @@ public function testExecute(): void ->willReturn($driverResult); $this->assertSame($driverResult, $this->statement->execute(['foo' => 'bar'])); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); diff --git a/tests/Tracing/Twig/TwigTracingExtensionTest.php b/tests/Tracing/Twig/TwigTracingExtensionTest.php index 1970a3ae..7a37a226 100644 --- a/tests/Tracing/Twig/TwigTracingExtensionTest.php +++ b/tests/Tracing/Twig/TwigTracingExtensionTest.php @@ -52,6 +52,8 @@ public function testEnter(Profile $profile, string $spanDescription): void $this->listener->enter($profile); + $this->assertNotNull($transaction->getSpanRecorder()); + $spans = $transaction->getSpanRecorder()->getSpans(); $this->assertCount(2, $spans); @@ -109,6 +111,8 @@ public function testLeave(): void $this->listener->enter($profile); $this->listener->leave($profile); + $this->assertNotNull($transaction->getSpanRecorder()); + $spans = $transaction->getSpanRecorder()->getSpans(); $this->assertCount(2, $spans); From 790815aee72d4717f6fb7f80d2033adeb02fe0d1 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sun, 28 Nov 2021 00:37:35 +0100 Subject: [PATCH 02/11] Raise the PHPStan level to 9 --- phpstan.neon | 2 +- psalm.xml | 1 + src/DependencyInjection/SentryExtension.php | 4 +++- src/EventListener/RequestListener.php | 8 ++++---- src/EventListener/TracingRequestListener.php | 2 ++ src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php | 9 ++++----- src/Tracing/Doctrine/DBAL/TracingDriverConnection.php | 6 ++++++ .../DBAL/TracingDriverConnectionFactoryInterface.php | 9 +++++++++ src/Tracing/Doctrine/DBAL/TracingStatementForV2.php | 4 +++- src/Tracing/Doctrine/DBAL/TracingStatementForV3.php | 4 +++- tests/DependencyInjection/SentryExtensionTest.php | 1 + .../Doctrine/DBAL/TracingDriverConnectionTest.php | 5 +++++ 12 files changed, 42 insertions(+), 13 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 6b9b4e31..df2e90c3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,7 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: 8 + level: 9 paths: - src - tests diff --git a/psalm.xml b/psalm.xml index 2810674c..39fe8712 100644 --- a/psalm.xml +++ b/psalm.xml @@ -10,6 +10,7 @@ + diff --git a/src/DependencyInjection/SentryExtension.php b/src/DependencyInjection/SentryExtension.php index 95837d32..1b2bc394 100644 --- a/src/DependencyInjection/SentryExtension.php +++ b/src/DependencyInjection/SentryExtension.php @@ -58,7 +58,9 @@ public function getNamespace(): string } /** - * @param mixed[] $mergedConfig + * {@inheritdoc} + * + * @param array $mergedConfig */ protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void { diff --git a/src/EventListener/RequestListener.php b/src/EventListener/RequestListener.php index a639f302..f8b79982 100644 --- a/src/EventListener/RequestListener.php +++ b/src/EventListener/RequestListener.php @@ -89,14 +89,14 @@ public function handleKernelControllerEvent(RequestListenerControllerEvent $even return; } - $request = $event->getRequest(); + $route = $event->getRequest()->attributes->get('_route'); - if (!$request->attributes->has('_route')) { + if (!is_string($route)) { return; } - $this->hub->configureScope(static function (Scope $scope) use ($request): void { - $scope->setTag('route', (string) $request->attributes->get('_route')); + $this->hub->configureScope(static function (Scope $scope) use ($route): void { + $scope->setTag('route', $route); }); } diff --git a/src/EventListener/TracingRequestListener.php b/src/EventListener/TracingRequestListener.php index 760a6bad..3166dabf 100644 --- a/src/EventListener/TracingRequestListener.php +++ b/src/EventListener/TracingRequestListener.php @@ -30,6 +30,8 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo /** @var Request $request */ $request = $event->getRequest(); + + /** @var float $requestStartTime */ $requestStartTime = $request->server->get('REQUEST_TIME_FLOAT', microtime(true)); $context = TransactionContext::fromSentryTrace($request->headers->get('sentry-trace', '')); diff --git a/src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php b/src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php index ba489196..cd740d9d 100644 --- a/src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php +++ b/src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php @@ -56,16 +56,15 @@ public function __construct(HubInterface $hub, Statement $decoratedStatement, st * Calls the given callback by passing to it the specified arguments and * wrapping its execution into a child {@see Span} of the current one. * - * @param callable $callback The function to call - * @param mixed ...$args The arguments to pass to the callback + * @param \Closure $callback The function to call * * @phpstan-template T * - * @phpstan-param callable(mixed...): T $callback + * @phpstan-param \Closure(mixed...): T $callback * * @phpstan-return T */ - protected function traceFunction(SpanContext $spanContext, callable $callback, ...$args) + protected function traceFunction(SpanContext $spanContext, \Closure $callback) { $span = $this->hub->getSpan(); @@ -74,7 +73,7 @@ protected function traceFunction(SpanContext $spanContext, callable $callback, . } try { - return $callback(...$args); + return $callback(); } finally { if (null !== $span) { $span->finish(); diff --git a/src/Tracing/Doctrine/DBAL/TracingDriverConnection.php b/src/Tracing/Doctrine/DBAL/TracingDriverConnection.php index d4f7790d..5bc2e90b 100644 --- a/src/Tracing/Doctrine/DBAL/TracingDriverConnection.php +++ b/src/Tracing/Doctrine/DBAL/TracingDriverConnection.php @@ -15,6 +15,8 @@ * This implementation wraps a driver connection and adds distributed tracing * capabilities to Doctrine DBAL. This implementation IS and MUST be compatible * with all versions of Doctrine DBAL >= 2.10. + * + * @phpstan-import-type Params from \Doctrine\DBAL\DriverManager as ConnectionParams */ final class TracingDriverConnection implements TracingDriverConnectionInterface { @@ -70,6 +72,8 @@ final class TracingDriverConnection implements TracingDriverConnectionInterface * @param DriverConnectionInterface $decoratedConnection The connection to decorate * @param string $databasePlatform The name of the database platform * @param array $params The connection params + * + * @phpstan-param ConnectionParams $params */ public function __construct( HubInterface $hub, @@ -230,6 +234,8 @@ private function traceFunction(string $spanOperation, string $spanDescription, \ * * @return array * + * @phpstan-param ConnectionParams $params + * * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md */ private function getSpanTags(string $databasePlatform, array $params): array diff --git a/src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactoryInterface.php b/src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactoryInterface.php index bb01ceed..0fef68d4 100644 --- a/src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactoryInterface.php +++ b/src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactoryInterface.php @@ -7,6 +7,13 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Platforms\AbstractPlatform; +/** + * This interface defines a contract that must be implemented by all factories + * supporting the creation of a Doctrine DBAL driver connection which is instrumented + * to report performance information to Sentry. + * + * @phpstan-import-type Params from \Doctrine\DBAL\DriverManager as ConnectionParams + */ interface TracingDriverConnectionFactoryInterface { /** @@ -16,6 +23,8 @@ interface TracingDriverConnectionFactoryInterface * @param Connection $connection The connection to wrap * @param AbstractPlatform $databasePlatform The database platform * @param array $params The params of the connection + * + * @phpstan-param ConnectionParams $params */ public function create(Connection $connection, AbstractPlatform $databasePlatform, array $params): TracingDriverConnectionInterface; } diff --git a/src/Tracing/Doctrine/DBAL/TracingStatementForV2.php b/src/Tracing/Doctrine/DBAL/TracingStatementForV2.php index 7803d415..d643a5ae 100644 --- a/src/Tracing/Doctrine/DBAL/TracingStatementForV2.php +++ b/src/Tracing/Doctrine/DBAL/TracingStatementForV2.php @@ -121,6 +121,8 @@ public function execute($params = null): bool $spanContext->setDescription($this->sqlQuery); $spanContext->setTags($this->spanTags); - return $this->traceFunction($spanContext, [$this->decoratedStatement, 'execute'], $params); + return $this->traceFunction($spanContext, function () use ($params): bool { + return $this->decoratedStatement->execute($params); + }); } } diff --git a/src/Tracing/Doctrine/DBAL/TracingStatementForV3.php b/src/Tracing/Doctrine/DBAL/TracingStatementForV3.php index 2ef5b3b1..e2ced036 100644 --- a/src/Tracing/Doctrine/DBAL/TracingStatementForV3.php +++ b/src/Tracing/Doctrine/DBAL/TracingStatementForV3.php @@ -40,6 +40,8 @@ public function execute($params = null): Result $spanContext->setDescription($this->sqlQuery); $spanContext->setTags($this->spanTags); - return $this->traceFunction($spanContext, [$this->decoratedStatement, 'execute'], $params); + return $this->traceFunction($spanContext, function () use ($params): Result { + return $this->decoratedStatement->execute($params); + }); } } diff --git a/tests/DependencyInjection/SentryExtensionTest.php b/tests/DependencyInjection/SentryExtensionTest.php index adb04f95..4a468519 100644 --- a/tests/DependencyInjection/SentryExtensionTest.php +++ b/tests/DependencyInjection/SentryExtensionTest.php @@ -263,6 +263,7 @@ public function testLoggerIsPassedToTransportFactory(): void $transportFactoryDefinition = $container->findDefinition(TransportFactoryInterface::class); $logger = $transportFactoryDefinition->getArgument('$logger'); + $this->assertInstanceOf(Reference::class, $logger); $this->assertSame('app.logger', $logger->__toString()); } diff --git a/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php b/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php index 3fb29a59..aa9228d4 100644 --- a/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php +++ b/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php @@ -16,6 +16,9 @@ use Sentry\Tracing\Transaction; use Sentry\Tracing\TransactionContext; +/** + * @phpstan-import-type Params from \Doctrine\DBAL\DriverManager as ConnectionParams + */ final class TracingDriverConnectionTest extends DoctrineTestCase { /** @@ -107,6 +110,8 @@ public function testPrepareDoesNothingIfNoSpanIsSetOnHub(): void * * @param array $params * @param array $expectedTags + * + * @phpstan-param ConnectionParams $params */ public function testQuery(array $params, array $expectedTags): void { From 8a1aa22da3df03902c0ad3eb2f1568a98302bdd9 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Thu, 2 Dec 2021 20:12:21 +0100 Subject: [PATCH 03/11] Fix failing test due to wrong assertion --- tests/DependencyInjection/SentryExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/DependencyInjection/SentryExtensionTest.php b/tests/DependencyInjection/SentryExtensionTest.php index 4a468519..ddd58681 100644 --- a/tests/DependencyInjection/SentryExtensionTest.php +++ b/tests/DependencyInjection/SentryExtensionTest.php @@ -239,7 +239,7 @@ public function testClientIsCreatedFromOptions(): void $methodCalls = $factory[0]->getMethodCalls(); - $this->assertCount(4, $methodCalls); + $this->assertCount(6, $methodCalls); $this->assertDefinitionMethodCallAt($methodCalls[0], 'setSdkIdentifier', [SentryBundle::SDK_IDENTIFIER]); $this->assertDefinitionMethodCallAt($methodCalls[1], 'setSdkVersion', [PrettyVersions::getVersion('sentry/sentry-symfony')->getPrettyVersion()]); $this->assertDefinitionMethodCallAt($methodCalls[2], 'setTransportFactory', [new Reference('App\\Sentry\\Transport\\TransportFactory')]); From 7465a3908c38a98cdd4b51f7de9a86f508845e91 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Thu, 2 Dec 2021 20:14:49 +0100 Subject: [PATCH 04/11] Fix code style --- src/EventListener/RequestListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventListener/RequestListener.php b/src/EventListener/RequestListener.php index f8b79982..7c094ca7 100644 --- a/src/EventListener/RequestListener.php +++ b/src/EventListener/RequestListener.php @@ -91,7 +91,7 @@ public function handleKernelControllerEvent(RequestListenerControllerEvent $even $route = $event->getRequest()->attributes->get('_route'); - if (!is_string($route)) { + if (!\is_string($route)) { return; } From f6acf3fc5b0d1b4fda694417ef42b04e2615bc38 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Mon, 13 Dec 2021 20:04:19 +0100 Subject: [PATCH 05/11] Bump minimum required version of `friendsofphp/php-cs-fixer` --- .github/workflows/static-analysis.yaml | 4 ---- .github/workflows/tests.yaml | 3 --- composer.json | 2 +- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 103f88c4..8ec19924 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -18,8 +18,6 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - name: Install dependencies run: composer update --no-progress --no-interaction --prefer-dist @@ -52,8 +50,6 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - name: Install dependencies run: composer update --no-progress --no-interaction --prefer-dist diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 8ff173ad..57d7f962 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -71,9 +71,6 @@ jobs: - name: Setup Problem Matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Remove PHP-CS-Fixer - run: composer remove --dev friendsofphp/php-cs-fixer --no-update - - name: Remove Symfony Messenger run: composer remove --dev symfony/messenger --no-update if: matrix.symfony-version == '3.4.*' diff --git a/composer.json b/composer.json index 7034bb0f..4e32235c 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "require-dev": { "doctrine/dbal": "^2.13||^3.0", "doctrine/doctrine-bundle": "^1.12||^2.5", - "friendsofphp/php-cs-fixer": "^3.2", + "friendsofphp/php-cs-fixer": "^3.4", "jangregor/phpstan-prophecy": "^1.0", "monolog/monolog": "^1.3||^2.0", "phpspec/prophecy": "!=1.11.0", From 836b7f857c0a80031de5178b920289e252ccf171 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Mon, 13 Dec 2021 20:11:10 +0100 Subject: [PATCH 06/11] Update PHPStan and Psalm baselines --- phpstan-baseline.neon | 230 ++++++++++++++++++++++++++++++++++++++++++ psalm-baseline.xml | 26 +---- 2 files changed, 231 insertions(+), 25 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 48630124..1ca0b82b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,145 @@ parameters: ignoreErrors: + - + message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/DbalTracingPass.php + - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\TreeBuilder\\:\\:root\\(\\)\\.$#" count: 1 path: src/DependencyInjection/Configuration.php + - + message: "#^Cannot access offset 'before_breadcrumb' on mixed\\.$#" + count: 3 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Cannot access offset 'before_send' on mixed\\.$#" + count: 3 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Cannot access offset 'class_serializers' on mixed\\.$#" + count: 3 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Cannot access offset 'connections' on mixed\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Cannot access offset 'default_integrations' on mixed\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Cannot access offset 'dsn' on mixed\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Cannot access offset 'excluded_commands' on mixed\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Cannot access offset 'in_app_exclude' on mixed\\.$#" + count: 2 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Cannot access offset 'integrations' on mixed\\.$#" + count: 3 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Cannot access offset 'traces_sampler' on mixed\\.$#" + count: 3 + path: src/DependencyInjection/SentryExtension.php + - message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#" count: 1 path: src/DependencyInjection/SentryExtension.php + - + message: "#^Parameter \\#1 \\$array of function array_filter expects array, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: Symfony\\\\Component\\\\DependencyInjection\\\\Reference given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#" + count: 5 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#1 \\$integrations of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:configureIntegrationsOption\\(\\) expects array\\, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$array of function array_map expects array, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$callback of function array_filter expects callable\\(mixed\\)\\: mixed, Closure\\(string\\)\\: bool given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$config of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:registerCacheTracingConfiguration\\(\\) expects array\\, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$config of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:registerDbalTracingConfiguration\\(\\) expects array\\, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$config of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:registerMessengerListenerConfiguration\\(\\) expects array\\, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$config of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:registerTracingConfiguration\\(\\) expects array\\, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$config of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:registerTwigTracingConfiguration\\(\\) expects array\\, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$config of method Symfony\\\\Component\\\\DependencyInjection\\\\Extension\\\\Extension\\:\\:isConfigEnabled\\(\\) expects array, mixed given\\.$#" + count: 3 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$registerErrorListener of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:configureErrorListenerIntegration\\(\\) expects bool, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$useDefaultIntegrations of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:configureRequestIntegration\\(\\) expects bool, mixed given\\.$#" + count: 1 + path: src/DependencyInjection/SentryExtension.php + + - + message: "#^Parameter \\#2 \\$value of method Symfony\\\\Component\\\\DependencyInjection\\\\Container\\:\\:setParameter\\(\\) expects array\\|bool\\|float\\|int\\|string\\|null, mixed given\\.$#" + count: 2 + path: src/DependencyInjection/SentryExtension.php + - message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#" count: 1 @@ -30,11 +160,31 @@ parameters: count: 1 path: src/EventListener/RequestListener.php + - + message: "#^Cannot call method getUser\\(\\) on Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\TokenInterface\\|null\\.$#" + count: 1 + path: src/EventListener/RequestListener.php + + - + message: "#^Parameter \\#1 \\$user of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:getUsername\\(\\) expects object\\|string, Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\|null given\\.$#" + count: 1 + path: src/EventListener/RequestListener.php + - message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#" count: 1 path: src/EventListener/SubRequestListener.php + - + message: "#^Parameter \\#1 \\$driver of method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverMiddleware\\:\\:wrap\\(\\) expects Doctrine\\\\DBAL\\\\Driver, mixed given\\.$#" + count: 1 + path: src/Tracing/Doctrine/DBAL/ConnectionConfigurator.php + + - + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:__construct\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" + count: 5 + path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php + - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:errorInfo\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -45,6 +195,11 @@ parameters: count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php + - + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:getSpanTags\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" + count: 5 + path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php + - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:prepare\\(\\) has parameter \\$sql with no type specified\\.$#" count: 1 @@ -55,6 +210,16 @@ parameters: count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php + - + message: "#^Offset 'unix_socket' on array\\{charset\\?\\: string, dbname\\?\\: string, default_dbname\\?\\: string, driver\\?\\: mixed, driverClass\\?\\: class\\-string\\, driverOptions\\?\\: array, host\\?\\: string, keepSlave\\?\\: bool, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#" + count: 1 + path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php + + - + message: "#^PHPDoc tag @param for parameter \\$params contains unresolvable type\\.$#" + count: 2 + path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php + - message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Driver\\\\Connection\\:\\:query\\(\\) expects string, string\\|null given\\.$#" count: 1 @@ -65,6 +230,26 @@ parameters: count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php + - + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnectionFactory\\:\\:create\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" + count: 5 + path: src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactory.php + + - + message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnectionFactoryInterface\\:\\:create\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" + count: 5 + path: src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactoryInterface.php + + - + message: "#^PHPDoc tag @param for parameter \\$params contains unresolvable type\\.$#" + count: 1 + path: src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactoryInterface.php + + - + message: "#^Parameter \\#3 \\$params of method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnectionFactoryInterface\\:\\:create\\(\\) expects array\\{charset\\?\\: string, dbname\\?\\: string, default_dbname\\?\\: string, driver\\?\\: mixed, driverClass\\?\\: class\\-string\\, driverOptions\\?\\: array, host\\?\\: string, keepSlave\\?\\: bool, \\.\\.\\.\\}, array given\\.$#" + count: 1 + path: src/Tracing/Doctrine/DBAL/TracingDriverForV3.php + - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingServerInfoAwareDriverConnection\\:\\:errorInfo\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -90,6 +275,36 @@ parameters: count: 1 path: src/Tracing/Doctrine/DBAL/TracingServerInfoAwareDriverConnection.php + - + message: "#^Cannot access offset 'sample_rate' on mixed\\.$#" + count: 1 + path: tests/DependencyInjection/ConfigurationTest.php + + - + message: "#^Cannot access offset 'traces_sample_rate' on mixed\\.$#" + count: 1 + path: tests/DependencyInjection/ConfigurationTest.php + + - + message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" + count: 1 + path: tests/DependencyInjection/SentryExtensionTest.php + + - + message: "#^Cannot access offset 'dsn' on mixed\\.$#" + count: 1 + path: tests/DependencyInjection/SentryExtensionTest.php + + - + message: "#^Cannot access offset 'error_types' on mixed\\.$#" + count: 1 + path: tests/DependencyInjection/SentryExtensionTest.php + + - + message: "#^Cannot access offset 'integrations' on mixed\\.$#" + count: 1 + path: tests/DependencyInjection/SentryExtensionTest.php + - message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#" count: 1 @@ -230,6 +445,21 @@ parameters: count: 1 path: tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php + - + message: "#^Method Sentry\\\\SentryBundle\\\\Tests\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnectionTest\\:\\:testQuery\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" + count: 5 + path: tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php + + - + message: "#^PHPDoc tag @param for parameter \\$params contains unresolvable type\\.$#" + count: 1 + path: tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php + + - + message: "#^Parameter \\#4 \\$params of class Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection constructor expects array\\{charset\\?\\: string, dbname\\?\\: string, default_dbname\\?\\: string, driver\\?\\: mixed, driverClass\\?\\: class\\-string\\, driverOptions\\?\\: array, host\\?\\: string, keepSlave\\?\\: bool, \\.\\.\\.\\}, array\\ given\\.$#" + count: 5 + path: tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php + - message: "#^Trying to mock an undefined method errorCode\\(\\) on class Doctrine\\\\DBAL\\\\Driver\\\\Connection\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 8b53fba0..4d309035 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + FatalErrorException @@ -44,30 +44,6 @@ AbstractSchemaManager<T> - - - $this->decoratedStatement - $this->traceFunction($spanContext, [$this->decoratedStatement, 'execute'], $params) - - - \Traversable - bool - - - TracingStatementForV2 - - - closeCursor - columnCount - errorCode - errorInfo - fetch - fetchAll - fetchColumn - rowCount - setFetchMode - - TracingDriverForV2 From d2e38ec67719164459bc32886666a8f706f38ccd Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Wed, 29 Dec 2021 18:31:03 +0100 Subject: [PATCH 07/11] Raise the minimum required version of PHPStan --- composer.json | 2 +- phpstan-baseline.neon | 52 +------------------ .../Doctrine/DBAL/TracingDriverForV3.php | 4 ++ .../DBAL/TracingDriverConnectionTest.php | 10 ++++ 4 files changed, 16 insertions(+), 52 deletions(-) diff --git a/composer.json b/composer.json index 4e32235c..0c3b6c90 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "phpspec/prophecy": "!=1.11.0", "phpspec/prophecy-phpunit": "^1.1||^2.0", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.0", + "phpstan/phpstan": "^1.3", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^8.5.14||^9.3.9", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1ca0b82b..23341234 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -180,11 +180,6 @@ parameters: count: 1 path: src/Tracing/Doctrine/DBAL/ConnectionConfigurator.php - - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:__construct\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" - count: 5 - path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:errorInfo\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -195,11 +190,6 @@ parameters: count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:getSpanTags\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" - count: 5 - path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:prepare\\(\\) has parameter \\$sql with no type specified\\.$#" count: 1 @@ -211,15 +201,10 @@ parameters: path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - message: "#^Offset 'unix_socket' on array\\{charset\\?\\: string, dbname\\?\\: string, default_dbname\\?\\: string, driver\\?\\: mixed, driverClass\\?\\: class\\-string\\, driverOptions\\?\\: array, host\\?\\: string, keepSlave\\?\\: bool, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#" + message: "#^Offset 'unix_socket' on array\\{charset\\?\\: string, dbname\\?\\: string, default_dbname\\?\\: string, driver\\?\\: 'ibm_db2'\\|'mysqli'\\|'oci8'\\|'pdo_mysql'\\|'pdo_oci'\\|'pdo_pgsql'\\|'pdo_sqlite'\\|'pdo_sqlsrv'\\|'sqlsrv', driverClass\\?\\: class\\-string\\, driverOptions\\?\\: array, host\\?\\: string, keepSlave\\?\\: bool, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#" count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - - message: "#^PHPDoc tag @param for parameter \\$params contains unresolvable type\\.$#" - count: 2 - path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Driver\\\\Connection\\:\\:query\\(\\) expects string, string\\|null given\\.$#" count: 1 @@ -230,26 +215,6 @@ parameters: count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnectionFactory\\:\\:create\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" - count: 5 - path: src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactory.php - - - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnectionFactoryInterface\\:\\:create\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" - count: 5 - path: src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactoryInterface.php - - - - message: "#^PHPDoc tag @param for parameter \\$params contains unresolvable type\\.$#" - count: 1 - path: src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactoryInterface.php - - - - message: "#^Parameter \\#3 \\$params of method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnectionFactoryInterface\\:\\:create\\(\\) expects array\\{charset\\?\\: string, dbname\\?\\: string, default_dbname\\?\\: string, driver\\?\\: mixed, driverClass\\?\\: class\\-string\\, driverOptions\\?\\: array, host\\?\\: string, keepSlave\\?\\: bool, \\.\\.\\.\\}, array given\\.$#" - count: 1 - path: src/Tracing/Doctrine/DBAL/TracingDriverForV3.php - - message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingServerInfoAwareDriverConnection\\:\\:errorInfo\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -445,21 +410,6 @@ parameters: count: 1 path: tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php - - - message: "#^Method Sentry\\\\SentryBundle\\\\Tests\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnectionTest\\:\\:testQuery\\(\\) has parameter \\$params with no value type specified in iterable type array\\\\.$#" - count: 5 - path: tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php - - - - message: "#^PHPDoc tag @param for parameter \\$params contains unresolvable type\\.$#" - count: 1 - path: tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php - - - - message: "#^Parameter \\#4 \\$params of class Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection constructor expects array\\{charset\\?\\: string, dbname\\?\\: string, default_dbname\\?\\: string, driver\\?\\: mixed, driverClass\\?\\: class\\-string\\, driverOptions\\?\\: array, host\\?\\: string, keepSlave\\?\\: bool, \\.\\.\\.\\}, array\\ given\\.$#" - count: 5 - path: tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php - - message: "#^Trying to mock an undefined method errorCode\\(\\) on class Doctrine\\\\DBAL\\\\Driver\\\\Connection\\.$#" count: 1 diff --git a/src/Tracing/Doctrine/DBAL/TracingDriverForV3.php b/src/Tracing/Doctrine/DBAL/TracingDriverForV3.php index e4fbd21f..6b46bf47 100644 --- a/src/Tracing/Doctrine/DBAL/TracingDriverForV3.php +++ b/src/Tracing/Doctrine/DBAL/TracingDriverForV3.php @@ -17,6 +17,8 @@ * is compatible with all versions of Doctrine DBAL >= 3.0. * * @internal + * + * @phpstan-import-type Params from \Doctrine\DBAL\DriverManager as ConnectionParams */ final class TracingDriverForV3 implements Driver, VersionAwarePlatformDriver { @@ -44,6 +46,8 @@ public function __construct(TracingDriverConnectionFactoryInterface $connectionF /** * {@inheritdoc} + * + * @phpstan-param ConnectionParams $params */ public function connect(array $params): TracingDriverConnectionInterface { diff --git a/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php b/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php index aa9228d4..3975a30f 100644 --- a/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php +++ b/tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php @@ -55,6 +55,8 @@ protected function setUp(): void * * @param array $params * @param array $expectedTags + * + * @phpstan-param ConnectionParams $params */ public function testPrepare(array $params, array $expectedTags): void { @@ -175,6 +177,8 @@ public function testQuote(): void * * @param array $params * @param array $expectedTags + * + * @phpstan-param ConnectionParams $params */ public function testExec(array $params, array $expectedTags): void { @@ -220,6 +224,8 @@ public function testLastInsertId(): void * * @param array $params * @param array $expectedTags + * + * @phpstan-param ConnectionParams $params */ public function testBeginTransaction(array $params, array $expectedTags): void { @@ -265,6 +271,8 @@ public function testBeginTransactionDoesNothingIfNoSpanIsSetOnHub(): void * * @param array $params * @param array $expectedTags + * + * @phpstan-param ConnectionParams $params */ public function testCommit(array $params, array $expectedTags): void { @@ -310,6 +318,8 @@ public function testCommitDoesNothingIfNoSpanIsSetOnHub(): void * * @param array $params * @param array $expectedTags + * + * @phpstan-param ConnectionParams $params */ public function testRollBack(array $params, array $expectedTags): void { From dc8382229795ef057e1049fc9f95f0dc7604cfab Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Thu, 10 Feb 2022 19:31:36 +0100 Subject: [PATCH 08/11] Bump minimum required version of `PHP-CS-Fixer` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0c3b6c90..359032be 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "require-dev": { "doctrine/dbal": "^2.13||^3.0", "doctrine/doctrine-bundle": "^1.12||^2.5", - "friendsofphp/php-cs-fixer": "^3.4", + "friendsofphp/php-cs-fixer": "^3.6", "jangregor/phpstan-prophecy": "^1.0", "monolog/monolog": "^1.3||^2.0", "phpspec/prophecy": "!=1.11.0", From 44481af96261cd967434b3567abdc8799d477934 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Thu, 10 Feb 2022 19:32:09 +0100 Subject: [PATCH 09/11] Update PHPStan and Psalm baselines --- phpstan-baseline.neon | 5 ----- psalm-baseline.xml | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 23341234..98e45e4b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -200,11 +200,6 @@ parameters: count: 1 path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - - message: "#^Offset 'unix_socket' on array\\{charset\\?\\: string, dbname\\?\\: string, default_dbname\\?\\: string, driver\\?\\: 'ibm_db2'\\|'mysqli'\\|'oci8'\\|'pdo_mysql'\\|'pdo_oci'\\|'pdo_pgsql'\\|'pdo_sqlite'\\|'pdo_sqlsrv'\\|'sqlsrv', driverClass\\?\\: class\\-string\\, driverOptions\\?\\: array, host\\?\\: string, keepSlave\\?\\: bool, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#" - count: 1 - path: src/Tracing/Doctrine/DBAL/TracingDriverConnection.php - - message: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Driver\\\\Connection\\:\\:query\\(\\) expects string, string\\|null given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 4d309035..cb50c90a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + FatalErrorException @@ -43,6 +43,9 @@ AbstractSchemaManager<T> + + $params + From 56c317f2f9e0bdec7cbe61f42c92c158f7a5fa4b Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Thu, 10 Feb 2022 19:37:56 +0100 Subject: [PATCH 10/11] Widen the version constraint range for PHP-CS-Fixer --- .github/workflows/static-analysis.yaml | 6 ++++++ composer.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 8ec19924..69e391a2 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -18,6 +18,8 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' - name: Install dependencies run: composer update --no-progress --no-interaction --prefer-dist @@ -34,6 +36,8 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' - name: Install dependencies run: composer update --no-progress --no-interaction --prefer-dist @@ -50,6 +54,8 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' - name: Install dependencies run: composer update --no-progress --no-interaction --prefer-dist diff --git a/composer.json b/composer.json index 359032be..f0c18fd4 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "require-dev": { "doctrine/dbal": "^2.13||^3.0", "doctrine/doctrine-bundle": "^1.12||^2.5", - "friendsofphp/php-cs-fixer": "^3.6", + "friendsofphp/php-cs-fixer": "^2.19||^3.6", "jangregor/phpstan-prophecy": "^1.0", "monolog/monolog": "^1.3||^2.0", "phpspec/prophecy": "!=1.11.0", From ea4619c2e2be64bf79d7cd0c56f1f5597d31cb2c Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Thu, 10 Feb 2022 19:57:40 +0100 Subject: [PATCH 11/11] Revert breaking change --- phpstan-baseline.neon | 5 +++++ src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php | 9 +++++---- src/Tracing/Doctrine/DBAL/TracingStatementForV2.php | 4 +--- src/Tracing/Doctrine/DBAL/TracingStatementForV3.php | 4 +--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 98e45e4b..fec799ff 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -235,6 +235,11 @@ parameters: count: 1 path: src/Tracing/Doctrine/DBAL/TracingServerInfoAwareDriverConnection.php + - + message: "#^Parameter \\#2 \\$callback of method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\AbstractTracingStatement\\:\\:traceFunction\\(\\) expects callable\\(\\.\\.\\.mixed\\)\\: Doctrine\\\\DBAL\\\\Driver\\\\Result, array\\{Doctrine\\\\DBAL\\\\Driver\\\\Statement, 'execute'\\} given\\.$#" + count: 1 + path: src/Tracing/Doctrine/DBAL/TracingStatementForV3.php + - message: "#^Cannot access offset 'sample_rate' on mixed\\.$#" count: 1 diff --git a/src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php b/src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php index cd740d9d..ba489196 100644 --- a/src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php +++ b/src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php @@ -56,15 +56,16 @@ public function __construct(HubInterface $hub, Statement $decoratedStatement, st * Calls the given callback by passing to it the specified arguments and * wrapping its execution into a child {@see Span} of the current one. * - * @param \Closure $callback The function to call + * @param callable $callback The function to call + * @param mixed ...$args The arguments to pass to the callback * * @phpstan-template T * - * @phpstan-param \Closure(mixed...): T $callback + * @phpstan-param callable(mixed...): T $callback * * @phpstan-return T */ - protected function traceFunction(SpanContext $spanContext, \Closure $callback) + protected function traceFunction(SpanContext $spanContext, callable $callback, ...$args) { $span = $this->hub->getSpan(); @@ -73,7 +74,7 @@ protected function traceFunction(SpanContext $spanContext, \Closure $callback) } try { - return $callback(); + return $callback(...$args); } finally { if (null !== $span) { $span->finish(); diff --git a/src/Tracing/Doctrine/DBAL/TracingStatementForV2.php b/src/Tracing/Doctrine/DBAL/TracingStatementForV2.php index d643a5ae..7803d415 100644 --- a/src/Tracing/Doctrine/DBAL/TracingStatementForV2.php +++ b/src/Tracing/Doctrine/DBAL/TracingStatementForV2.php @@ -121,8 +121,6 @@ public function execute($params = null): bool $spanContext->setDescription($this->sqlQuery); $spanContext->setTags($this->spanTags); - return $this->traceFunction($spanContext, function () use ($params): bool { - return $this->decoratedStatement->execute($params); - }); + return $this->traceFunction($spanContext, [$this->decoratedStatement, 'execute'], $params); } } diff --git a/src/Tracing/Doctrine/DBAL/TracingStatementForV3.php b/src/Tracing/Doctrine/DBAL/TracingStatementForV3.php index e2ced036..2ef5b3b1 100644 --- a/src/Tracing/Doctrine/DBAL/TracingStatementForV3.php +++ b/src/Tracing/Doctrine/DBAL/TracingStatementForV3.php @@ -40,8 +40,6 @@ public function execute($params = null): Result $spanContext->setDescription($this->sqlQuery); $spanContext->setTags($this->spanTags); - return $this->traceFunction($spanContext, function () use ($params): Result { - return $this->decoratedStatement->execute($params); - }); + return $this->traceFunction($spanContext, [$this->decoratedStatement, 'execute'], $params); } }