diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 103f88c4..69e391a2 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -19,7 +19,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.1' - name: Install dependencies run: composer update --no-progress --no-interaction --prefer-dist @@ -36,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 @@ -53,7 +55,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.1' - 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/.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..f0c18fd4 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": "^2.19||^3.6", + "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.3", + "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..fec799ff 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,25 +1,155 @@ parameters: ignoreErrors: - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:booleanNode\\(\\)\\.$#" + message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#" count: 1 - path: src/DependencyInjection/Configuration.php + 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 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 @@ -30,28 +160,53 @@ 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\\:\\:errorInfo\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 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,20 +216,60 @@ 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 typehint specified\\.$#" + 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\\:\\:query\\(\\) has parameter \\$args 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: "#^Parameter \\#1 \\$sql of method Doctrine\\\\DBAL\\\\Driver\\\\Connection\\:\\:query\\(\\) expects string, string\\|null given\\.$#" + 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 + 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 @@ -101,7 +296,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 +341,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 +371,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..df2e90c3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,7 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: 7 + level: 9 paths: - src - tests diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 8b53fba0..cb50c90a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + FatalErrorException @@ -43,30 +43,9 @@ AbstractSchemaManager<T> - - - - $this->decoratedStatement - $this->traceFunction($spanContext, [$this->decoratedStatement, 'execute'], $params) - - - \Traversable - bool - - - TracingStatementForV2 - - - closeCursor - columnCount - errorCode - errorInfo - fetch - fetchAll - fetchColumn - rowCount - setFetchMode - + + $params + 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..7c094ca7 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/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/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/DependencyInjection/SentryExtensionTest.php b/tests/DependencyInjection/SentryExtensionTest.php index 42ce7b4c..ddd58681 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(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')]); @@ -261,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()); } @@ -395,6 +398,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..3975a30f 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 { /** @@ -52,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 { @@ -73,6 +78,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(); @@ -106,6 +112,8 @@ public function testPrepareDoesNothingIfNoSpanIsSetOnHub(): void * * @param array $params * @param array $expectedTags + * + * @phpstan-param ConnectionParams $params */ public function testQuery(array $params, array $expectedTags): void { @@ -126,6 +134,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(); @@ -168,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 { @@ -187,6 +198,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(); @@ -212,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 { @@ -228,6 +242,7 @@ public function testBeginTransaction(array $params, array $expectedTags): void ->willReturn(false); $this->assertFalse($connection->beginTransaction()); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -256,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 { @@ -272,6 +289,7 @@ public function testCommit(array $params, array $expectedTags): void ->willReturn(false); $this->assertFalse($connection->commit()); + $this->assertNotNull($transaction->getSpanRecorder()); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -300,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 { @@ -316,6 +336,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);