diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e1a9c4061..b2fb4ea6a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,7 +45,10 @@ Some changes do not cause an error, so nothing will point you to them. Check eac - The send_default_pii option is gone, and the defaults of the data_collection option collect more data than before, whichever value send_default_pii had. What gets collected is a privacy decision that is mine to make: apply the restrictive configuration from the guide, which is the closest to - the old behavior, and list what I could enable on top of it. + the old behavior, and list what I could enable on top of it. This only applies if the project + does not set the data_collection option yet. If it already does, send_default_pii was already + ignored and the existing data_collection configuration keeps applying, so only remove + send_default_pii. - The client is never null anymore. Remove the null checks, and tell me where one of them was used to detect that the SDK is not initialized. - Sentry\Metrics\Metrics and \Sentry\metrics() still exist, but they are a different API now. Code @@ -130,6 +133,32 @@ a span_id instead of the sentry.trace.parent_span_id attribute. - Fix the argument names of closures in stack frames. [(#2370)](https://github.com/getsentry/sentry-php/pull/2370) - Omit the `unit` of a metric and of a crontab monitor schedule when it is not set. [(#2373)](https://github.com/getsentry/sentry-php/pull/2373), [(#2374)](https://github.com/getsentry/sentry-php/pull/2374) +## 4.38.0 + +The Sentry SDK team is happy to announce the immediate availability of Sentry PHP SDK v4.38.0. + +### Features + +- Add `Scope::setUserResolver()` to resolve the user lazily each time it is read, instead of setting it upfront. User data set with `Scope::setUser()` takes precedence over the data the resolver returns. [(#2396)](https://github.com/getsentry/sentry-php/pull/2396) + + ```php + \Sentry\configureScope(static function (\Sentry\State\Scope $scope): void { + $scope->setUserResolver(static function (): ?\Sentry\UserDataBag { + // Return null as long as the user is not known yet + return \Sentry\UserDataBag::createFromUserIdentifier('1234'); + }); + }); + ``` + +## 4.37.1 + +The Sentry SDK team is happy to announce the immediate availability of Sentry PHP SDK v4.37.1. + +### Bug Fixes + +- Write the HTTP status code into the `http.response.status_code` data of a span in `Span::setHttpStatus()`, so that the `trace_ignore_status_codes` option also applies to transactions whose status is set this way. [(#2384)](https://github.com/getsentry/sentry-php/pull/2384) +- Fix a `TypeError` when the response of the HTTP client contains a header with a numeric name. [(#2366)](https://github.com/getsentry/sentry-php/pull/2366) + ## 4.37.0 The Sentry SDK team is happy to announce the immediate availability of Sentry PHP SDK v4.37.0. diff --git a/analysis-baseline.toml b/analysis-baseline.toml index 23d4514f90..ac9290558b 100644 --- a/analysis-baseline.toml +++ b/analysis-baseline.toml @@ -1,11 +1,5 @@ variant = "loose" -[[issues]] -file = "src/Agent/Transport/AgentClient.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - [[issues]] file = "src/Attachment/FileAttachment.php" code = "avoid-catching-error" @@ -18,6 +12,12 @@ code = "implicit-to-string-cast" message = 'Implicit conversion to `string` for left operand via `Sentry\Severity::__toString()`.' count = 1 +[[issues]] +file = "src/Client.php" +code = "mixed-assignment" +message = "Assigning `mixed` type to a variable may lead to unexpected behavior." +count = 2 + [[issues]] file = "src/Client.php" code = "possibly-invalid-argument" @@ -36,30 +36,6 @@ code = "unused-template-parameter" message = 'Template parameter `T` is never used in method `Sentry\Client::getIntegration`.' count = 1 -[[issues]] -file = "src/Client.php" -code = "mixed-assignment" -message = "Assigning `mixed` type to a variable may lead to unexpected behavior." -count = 2 - -[[issues]] -file = "src/ClientReport/ClientReportAggregator.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - -[[issues]] -file = "src/ClientReport/ClientReportAggregator.php" -code = "less-specific-argument" -message = 'Argument type mismatch for argument #1 of `Sentry\ClientReport\DiscardedEvent::__construct`: expected `string`, but provided type `array-key` is less specific.' -count = 1 - -[[issues]] -file = "src/ClientReport/ClientReportAggregator.php" -code = "redundant-comparison" -message = "Redundant `!==` comparison: left-hand side is always not identical to right-hand side." -count = 3 - [[issues]] file = "src/ClientReport/ClientReportAggregator.php" code = "redundant-comparison" @@ -67,21 +43,21 @@ message = "Redundant `===` comparison: left-hand side is never identical to righ count = 1 [[issues]] -file = "src/ClientReport/ClientReportAggregator.php" -code = "redundant-condition" -message = "This condition (type `true`) will always evaluate to true." +file = "src/DataCollection/DataCollectionOptions.php" +code = "less-specific-nested-argument-type" +message = "Argument type mismatch for argument #1 of `array_diff`: expected `array`, but provided type `array` is less specific." count = 1 [[issues]] -file = "src/ClientReport/ClientReportAggregator.php" -code = "redundant-logical-operation" -message = "Redundant `&&` operation: left operand is always truthy and right operand is evaluated." +file = "src/DataCollection/DataCollectionOptions.php" +code = "template-constraint-violation" +message = "Argument type mismatch for template `V`." count = 1 [[issues]] file = "src/Dsn.php" code = "possibly-false-operand" -message = "Left operand in `==` comparison might be `false` (type `false|int`)." +message = "Left operand in `==` comparison might be `false` (type `false|int(0)|int(1)`)." count = 1 [[issues]] @@ -129,25 +105,25 @@ count = 1 [[issues]] file = "src/Dsn.php" code = "possibly-undefined-string-array-index" -message = "Possibly undefined array key 'host' accessed on `array{'fragment'?: non-empty-string, 'host'?: non-empty-string, 'pass'?: non-empty-string, 'path'?: non-empty-string, 'port'?: int<0, 65535>, 'query'?: non-empty-string, 'scheme'?: non-empty-string, 'user'?: non-empty-string}`." +message = "Possibly undefined array key 'host' accessed on `array{'fragment'?: string, 'host'?: non-empty-string, 'pass'?: string, 'path'?: non-empty-string, 'port'?: int<0, 65535>, 'query'?: string, 'scheme'?: string('http')|string('https'), 'user'?: string}`." count = 2 [[issues]] file = "src/Dsn.php" code = "possibly-undefined-string-array-index" -message = "Possibly undefined array key 'path' accessed on `array{'fragment'?: non-empty-string, 'host'?: non-empty-string, 'pass'?: non-empty-string, 'path'?: non-empty-string, 'port'?: int<0, 65535>, 'query'?: non-empty-string, 'scheme'?: non-empty-string, 'user'?: non-empty-string}`." +message = "Possibly undefined array key 'path' accessed on `array{'fragment'?: string, 'host'?: non-empty-string, 'pass'?: string, 'path'?: non-empty-string, 'port'?: int<0, 65535>, 'query'?: string, 'scheme'?: string('http')|string('https'), 'user'?: string}`." count = 4 [[issues]] file = "src/Dsn.php" code = "possibly-undefined-string-array-index" -message = "Possibly undefined array key 'scheme' accessed on `array{'fragment'?: non-empty-string, 'host'?: non-empty-string, 'pass'?: non-empty-string, 'path'?: non-empty-string, 'port'?: int<0, 65535>, 'query'?: non-empty-string, 'scheme'?: non-empty-string, 'user'?: non-empty-string}`." +message = "Possibly undefined array key 'scheme' accessed on `array{'fragment'?: string, 'host'?: non-empty-string, 'pass'?: string, 'path'?: non-empty-string, 'port'?: int<0, 65535>, 'query'?: string, 'scheme'?: non-empty-string, 'user'?: string}`." count = 1 [[issues]] file = "src/Dsn.php" code = "possibly-undefined-string-array-index" -message = "Possibly undefined array key 'user' accessed on `array{'fragment'?: non-empty-string, 'host'?: non-empty-string, 'pass'?: non-empty-string, 'path'?: non-empty-string, 'port'?: int<0, 65535>, 'query'?: non-empty-string, 'scheme'?: non-empty-string, 'user'?: non-empty-string}`." +message = "Possibly undefined array key 'user' accessed on `array{'fragment'?: string, 'host'?: non-empty-string, 'pass'?: string, 'path'?: non-empty-string, 'port'?: int<0, 65535>, 'query'?: string, 'scheme'?: string('http')|string('https'), 'user'?: string}`." count = 1 [[issues]] @@ -198,6 +174,12 @@ code = "possibly-invalid-argument" message = '''Possible argument type mismatch for argument #1 of `Sentry\ErrorHandler::cleanBacktraceFromErrorHandlerFrames`: expected `list, 'class'?: class-string, 'file'?: string, 'function'?: string, 'line'?: int, 'type'?: string}>`, but possibly received `array`.''' count = 1 +[[issues]] +file = "src/ErrorHandler.php" +code = "possibly-invalid-argument" +message = "Possible argument type mismatch for argument #2 of `str_repeat`: expected `non-negative-int`, but possibly received `int`." +count = 1 + [[issues]] file = "src/ErrorHandler.php" code = "redundant-comparison" @@ -216,42 +198,12 @@ code = "reference-to-undefined-variable" message = "Reference created from a previously undefined variable `$matches`." count = 1 -[[issues]] -file = "src/Event.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - [[issues]] file = "src/Event.php" code = "mixed-assignment" message = "Assigning `mixed` type to a variable may lead to unexpected behavior." count = 1 -[[issues]] -file = "src/Event.php" -code = "no-value" -message = 'Argument #1 passed to method `Sentry\Util\DebugType::getDebugType` has type `never`, meaning it cannot produce a value.' -count = 1 - -[[issues]] -file = "src/EventHint.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 4 - -[[issues]] -file = "src/EventHint.php" -code = "no-value" -message = 'Argument #1 passed to method `Sentry\Util\DebugType::getDebugType` has type `never`, meaning it cannot produce a value.' -count = 4 - -[[issues]] -file = "src/EventHint.php" -code = "redundant-logical-operation" -message = "Redundant `&&` operation: left operand is evaluated and right operand is always falsy." -count = 3 - [[issues]] file = "src/EventHint.php" code = "redundant-type-comparison" @@ -282,12 +234,6 @@ code = "deprecated-function" message = "Call to deprecated function: `curl_close`." count = 2 -[[issues]] -file = "src/HttpClient/HttpClient.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 2 - [[issues]] file = "src/HttpClient/HttpClient.php" code = "mixed-argument" @@ -339,7 +285,7 @@ count = 1 [[issues]] file = "src/HttpClient/Response.php" code = "property-type-coercion" -message = "A value of a less specific type `array{'': array-key, ...}` is being assigned to property `$$headerNames` (array)." +message = "A value of a less specific type `non-empty-array` is being assigned to property `$headerNames` (array)." count = 1 [[issues]] @@ -356,87 +302,39 @@ count = 1 [[issues]] file = "src/Integration/IntegrationRegistry.php" -code = "invalid-property-assignment-value" -message = 'Invalid type for property `$integrations`: expected `array, bool>`, but got `array|string, bool>`.' -count = 1 - -[[issues]] -file = "src/Integration/IntegrationRegistry.php" -code = "invalid-return-statement" -message = 'Invalid return type for function `Sentry\Integration\IntegrationRegistry::getIntegrationsToSetup`: expected `array`, but found `list<(callable(array): Sentry\Integration\IntegrationInterface)|Sentry\Integration\IntegrationInterface>`.' -count = 1 - -[[issues]] -file = "src/Integration/IntegrationRegistry.php" -code = "invalid-return-statement" -message = 'Invalid return type for function `Sentry\Integration\IntegrationRegistry::setupIntegrations`: expected `array, Sentry\Integration\IntegrationInterface>`, but found `array`.' +code = "less-specific-return-statement" +message = 'Returned type `array|list` is less specific than the declared return type `array` for function `Sentry\Integration\IntegrationRegistry::getIntegrationsToSetup`.' count = 1 [[issues]] file = "src/Integration/IntegrationRegistry.php" code = "possibly-invalid-argument" -message = '''Possible argument type mismatch for argument #1 of `array_map`: expected `(callable((callable(array): Sentry\Integration\IntegrationInterface)|object): string)|(callable((callable(array): Sentry\Integration\IntegrationInterface)|object, ('S.array_map() extends mixed)): string)|null`, but possibly received `string('get_class')`.''' +message = "Possible argument type mismatch for argument #1 of `array_map`: expected `(callable(class-string|non-empty-string|object): class-string<'T.get_class() extends object>)|(callable(class-string|non-empty-string|object, ('S.array_map() extends mixed)): class-string<'T.get_class() extends object>)|null`, but possibly received `string('get_class')`." count = 1 [[issues]] file = "src/Integration/IntegrationRegistry.php" code = "possibly-invalid-argument" -message = 'Possible argument type mismatch for argument #1 of `get_class`: expected `object`, but possibly received `(callable(array): Sentry\Integration\IntegrationInterface)|Sentry\Integration\IntegrationInterface`.' -count = 1 - -[[issues]] -file = "src/Integration/IntegrationRegistry.php" -code = "redundant-condition" -message = "This condition (type `true`) will always evaluate to true." +message = "Possible argument type mismatch for argument #1 of `get_class`: expected `('T.get_class() extends object)`, but possibly received `class-string|non-empty-string|object`." count = 1 [[issues]] file = "src/Integration/IntegrationRegistry.php" code = "redundant-type-comparison" -message = 'Redundant type assertion: `$userIntegrations` is already `array): Sentry\Integration\IntegrationInterface)|Sentry\Integration\IntegrationInterface>`.' +message = 'Redundant type assertion: `$integrations` is already `array`.' count = 1 [[issues]] file = "src/Integration/IntegrationRegistry.php" -code = "unreachable-else-clause" -message = "Unreachable else clause" -count = 1 - -[[issues]] -file = "src/Integration/RequestIntegration.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - -[[issues]] -file = "src/Integration/RequestIntegration.php" -code = "less-specific-argument" -message = 'Argument type mismatch for argument #1 of `Sentry\Integration\RequestIntegration::parseUploadedFiles`: expected `array`, but provided type `array` is less specific.' -count = 2 - -[[issues]] -file = "src/Integration/RequestIntegration.php" -code = "less-specific-return-statement" -message = 'Returned type `array>` is less specific than the declared return type `array>` for function `Sentry\Integration\RequestIntegration::sanitizeHeaders`.' -count = 1 - -[[issues]] -file = "src/Integration/RequestIntegration.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #1 of `Sentry\UserDataBag::createFromUserIpAddress`: expected `string`, but found `truthy-mixed`.' -count = 1 - -[[issues]] -file = "src/Integration/RequestIntegration.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #1 of `Sentry\UserDataBag::setIpAddress`: expected `null|string`, but found `truthy-mixed`.' +code = "template-constraint-violation" +message = "Argument type mismatch for template `T`." count = 1 [[issues]] file = "src/Integration/RequestIntegration.php" code = "mixed-assignment" message = "Assigning `mixed` type to a variable may lead to unexpected behavior." -count = 2 +count = 1 [[issues]] file = "src/Integration/TransactionIntegration.php" @@ -450,18 +348,6 @@ code = "redundant-type-comparison" message = "Redundant condition: variable `$_SERVER['REQUEST_URI']` (type `non-empty-string`) is already known to be `string`." count = 1 -[[issues]] -file = "src/Logger/DebugLogger.php" -code = "incompatible-parameter-type" -message = 'Parameter `$message` of `Sentry\Logger\DebugFileLogger::log()` expects type `string` but parent `Psr\Log\LoggerInterface::log()` expects type `Stringable|string`' -count = 1 - -[[issues]] -file = "src/Logger/DebugLogger.php" -code = "incompatible-parameter-type" -message = 'Parameter `$message` of `Sentry\Logger\DebugFileLogger::log()` expects type `string` but parent `Psr\Log\LoggerTrait::log()` expects type `Stringable|string`' -count = 1 - [[issues]] file = "src/Logger/DebugLogger.php" code = "incompatible-parameter-type" @@ -474,18 +360,6 @@ code = "incompatible-parameter-type" message = 'Parameter `$message` of `Sentry\Logger\DebugLogger::log()` expects type `string` but parent `Psr\Log\LoggerTrait::log()` expects type `Stringable|string`' count = 1 -[[issues]] -file = "src/Logger/DebugLogger.php" -code = "incompatible-parameter-type" -message = 'Parameter `$message` of `Sentry\Logger\DebugStdOutLogger::log()` expects type `string` but parent `Psr\Log\LoggerInterface::log()` expects type `Stringable|string`' -count = 1 - -[[issues]] -file = "src/Logger/DebugLogger.php" -code = "incompatible-parameter-type" -message = 'Parameter `$message` of `Sentry\Logger\DebugStdOutLogger::log()` expects type `string` but parent `Psr\Log\LoggerTrait::log()` expects type `Stringable|string`' -count = 1 - [[issues]] file = "src/Logger/DebugLogger.php" code = "mixed-argument" @@ -498,12 +372,6 @@ code = "redundant-cast" message = "Redundant cast to `(string)`: the expression already has this type." count = 1 -[[issues]] -file = "src/Logs/LogsAggregator.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - [[issues]] file = "src/Logs/LogsAggregator.php" code = "mixed-assignment" @@ -528,12 +396,6 @@ code = "ambiguous-instantiation-target" message = "Ambiguous instantiation: the expression used with `new` can resolve to multiple different classes." count = 1 -[[issues]] -file = "src/Metrics/MetricsAggregator.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - [[issues]] file = "src/Metrics/MetricsAggregator.php" code = "mixed-argument" @@ -548,44 +410,38 @@ count = 1 [[issues]] file = "src/Metrics/MetricsAggregator.php" -code = "possibly-invalid-argument" -message = '''Possible argument type mismatch for argument #5 of `Sentry\Metrics\Types\CounterMetric::__construct`: expected `array`, but possibly received `array{'sentry.environment': scalar, 'sentry.release'?: scalar, 'sentry.sdk.name'?: scalar, 'sentry.sdk.version'?: scalar, 'server.address': scalar, 'user.email'?: null|scalar, 'user.id'?: null|scalar, 'user.name'?: null|scalar, ...}`.''' -count = 1 - -[[issues]] -file = "src/Metrics/MetricsAggregator.php" -code = "possibly-invalid-argument" -message = '''Possible argument type mismatch for argument #5 of `Sentry\Metrics\Types\DistributionMetric::__construct`: expected `array`, but possibly received `array{'sentry.environment': scalar, 'sentry.release'?: scalar, 'sentry.sdk.name'?: scalar, 'sentry.sdk.version'?: scalar, 'server.address': scalar, 'user.email'?: null|scalar, 'user.id'?: null|scalar, 'user.name'?: null|scalar, ...}`.''' +code = "redundant-type-comparison" +message = "Redundant type assertion: `$value` is already `float`." count = 1 [[issues]] -file = "src/Metrics/MetricsAggregator.php" -code = "possibly-invalid-argument" -message = '''Possible argument type mismatch for argument #5 of `Sentry\Metrics\Types\GaugeMetric::__construct`: expected `array`, but possibly received `array{'sentry.environment': scalar, 'sentry.release'?: scalar, 'sentry.sdk.name'?: scalar, 'sentry.sdk.version'?: scalar, 'server.address': scalar, 'user.email'?: null|scalar, 'user.id'?: null|scalar, 'user.name'?: null|scalar, ...}`.''' -count = 1 +file = "src/Monolog/BreadcrumbHandler.php" +code = "deprecated-class-constant" +message = 'Use of deprecated class constant `Monolog\Logger::DEBUG`.' +count = 2 [[issues]] -file = "src/Metrics/MetricsAggregator.php" -code = "redundant-comparison" -message = "Redundant `!==` comparison: left-hand side is always not identical to right-hand side." -count = 3 +file = "src/Monolog/BreadcrumbHandler.php" +code = "deprecated-class-constant" +message = 'Use of deprecated class constant `Monolog\Logger::ERROR`.' +count = 2 [[issues]] -file = "src/Metrics/MetricsAggregator.php" -code = "redundant-condition" -message = "This condition (type `true`) will always evaluate to true." -count = 3 +file = "src/Monolog/BreadcrumbHandler.php" +code = "deprecated-class-constant" +message = 'Use of deprecated class constant `Monolog\Logger::INFO`.' +count = 1 [[issues]] -file = "src/Metrics/MetricsAggregator.php" -code = "redundant-logical-operation" -message = "Redundant `&&` operation: left operand is evaluated and right operand is always falsy." +file = "src/Monolog/BreadcrumbHandler.php" +code = "deprecated-class-constant" +message = 'Use of deprecated class constant `Monolog\Logger::NOTICE`.' count = 1 [[issues]] -file = "src/Metrics/MetricsAggregator.php" -code = "redundant-type-comparison" -message = "Redundant type assertion: `$value` is already `float`." +file = "src/Monolog/BreadcrumbHandler.php" +code = "deprecated-class-constant" +message = 'Use of deprecated class constant `Monolog\Logger::WARNING`.' count = 1 [[issues]] @@ -642,12 +498,6 @@ code = "possibly-invalid-operand" message = "Possibly invalid type for right operand." count = 1 -[[issues]] -file = "src/Monolog/CompatibilityLogLevelTrait.php" -code = "duplicate-definition" -message = 'Trait `Sentry\Monolog\CompatibilityLogLevelTrait` is already defined elsewhere.' -count = 1 - [[issues]] file = "src/Monolog/CompatibilityLogLevelTrait.php" code = "redundant-comparison" @@ -661,9 +511,9 @@ message = "This condition (type `true`) will always evaluate to true." count = 1 [[issues]] -file = "src/Monolog/CompatibilityProcessingHandlerTrait.php" -code = "duplicate-definition" -message = 'Trait `Sentry\Monolog\CompatibilityProcessingHandlerTrait` is already defined elsewhere.' +file = "src/Monolog/CompatibilityLogLevelTrait.php" +code = "unreachable-else-clause" +message = "Unreachable else clause" count = 1 [[issues]] @@ -678,6 +528,18 @@ code = "redundant-condition" message = "This condition (type `true`) will always evaluate to true." count = 1 +[[issues]] +file = "src/Monolog/CompatibilityProcessingHandlerTrait.php" +code = "unreachable-else-clause" +message = "Unreachable else clause" +count = 1 + +[[issues]] +file = "src/Monolog/ExceptionToSentryIssueHandler.php" +code = "deprecated-class-constant" +message = 'Use of deprecated class constant `Monolog\Logger::DEBUG`.' +count = 1 + [[issues]] file = "src/Monolog/ExceptionToSentryIssueHandler.php" code = "less-specific-return-statement" @@ -702,6 +564,12 @@ code = "possibly-invalid-argument" message = 'Possible argument type mismatch for argument #1 of `Monolog\Handler\AbstractProcessingHandler::handle`: expected `Monolog\LogRecord`, but possibly received `Monolog\LogRecord|array`.' count = 1 +[[issues]] +file = "src/Monolog/LogToSentryIssueHandler.php" +code = "deprecated-class-constant" +message = 'Use of deprecated class constant `Monolog\Logger::DEBUG`.' +count = 1 + [[issues]] file = "src/Monolog/LogToSentryIssueHandler.php" code = "less-specific-return-statement" @@ -736,7 +604,7 @@ count = 1 file = "src/Monolog/LogToSentryIssueHandler.php" code = "possibly-invalid-argument" message = 'Possible argument type mismatch for argument #1 of `Monolog\Handler\AbstractHandler::isHandling`: expected `Monolog\LogRecord`, but possibly received `Monolog\LogRecord|array`.' -count = 2 +count = 1 [[issues]] file = "src/Monolog/LogToSentryIssueHandler.php" @@ -774,12 +642,6 @@ code = "mixed-operand" message = "Left operand in `>=` comparison has `mixed` type." count = 2 -[[issues]] -file = "src/NoOpClient.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - [[issues]] file = "src/NoOpClient.php" code = "redundant-comparison" @@ -942,6 +804,12 @@ code = "mixed-return-statement" message = 'Could not infer a precise return type for function `Sentry\Options::getMaxBreadcrumbs`. Saw type `mixed`.' count = 1 +[[issues]] +file = "src/Options.php" +code = "mixed-return-statement" +message = 'Could not infer a precise return type for function `Sentry\Options::getMaxBreadth`. Saw type `mixed`.' +count = 1 + [[issues]] file = "src/Options.php" code = "mixed-return-statement" @@ -1032,12 +900,6 @@ code = "mixed-return-statement" message = 'Could not infer a precise return type for function `Sentry\Options::shouldCaptureSilencedErrors`. Saw type `mixed`.' count = 1 -[[issues]] -file = "src/Options.php" -code = "mixed-return-statement" -message = 'Could not infer a precise return type for function `Sentry\Options::getMaxBreadth`. Saw type `mixed`.' -count = 1 - [[issues]] file = "src/Options.php" code = "mixed-return-statement" @@ -1048,366 +910,54 @@ count = 1 file = "src/OptionsResolver.php" code = "mixed-assignment" message = "Assigning `mixed` type to a variable may lead to unexpected behavior." -count = 7 - -[[issues]] -file = "src/OptionsResolver.php" -code = "mixed-property-type-coercion" -message = "A value with a less specific type `array|list{mixed}>` is being assigned to property `$$allowedTypes` (array>)." -count = 1 +count = 2 [[issues]] -file = "src/OptionsResolver.php" -code = "mixed-return-statement" -message = 'Could not infer a precise return type for function `Sentry\OptionsResolver::validateValue`. Saw type `mixed`.' +file = "src/Profiling/ContinuousProfiler.php" +code = "mixed-argument" +message = 'Invalid argument type for argument #1 of `Sentry\Profiling\ContinuousProfiler::completeChunks`: expected `iterable`, but found `mixed`.' count = 1 [[issues]] -file = "src/OptionsResolver.php" -code = "redundant-condition" -message = "This condition (type `true`) will always evaluate to true." +file = "src/Profiling/Profile.php" +code = "invalid-return-statement" +message = '''Invalid return type for function `Sentry\Profiling\Profile::getFormattedData`: expected `array{'device': array{'architecture': string}, 'environment': string, 'event_id': string, 'os': array{'build_number': string, 'name': string, 'version': string}, 'platform': string('php'), 'profile': array{'frames': array, 'samples': array, 'stacks': array>}, 'release': string, 'runtime': array{'name': string, 'version': string}, 'timestamp': string, 'transaction': array{'active_thread_id': string, 'id': string, 'name': string, 'trace_id': string}, 'version': string}|null`, but found `array{'device': array{'architecture': null|string}, 'environment': string, 'event_id': string, 'os': array{'build_number': string, 'name': string, 'version': null|string}, 'platform': string('php'), 'profile': array{'frames': list, 'samples': list, 'stacks': array>}, 'release': string, 'runtime': array{'name': string, 'sapi': null|string, 'version': null|string}, 'timestamp': non-empty-string, 'transaction': array{'active_thread_id': string, 'id': string, 'name': null|string, 'trace_id': null|string}, 'version': string}`.''' count = 1 [[issues]] -file = "src/OptionsResolver.php" -code = "redundant-type-comparison" -message = "Redundant type assertion: `$allowedValue` is already `array`." +file = "src/Serializer/AbstractSerializer.php" +code = "generic-object-iteration" +message = "Iterating over a generic `object`. This will iterate its public properties." count = 1 [[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "impossible-assignment" -message = "Invalid assignment: the right-hand side has type `never` and cannot produce a value." +file = "src/Serializer/AbstractSerializer.php" +code = "invalid-operand" +message = "Invalid type `scalar` for middle operand in string concatenation." count = 1 [[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "invalid-method-access" -message = "Attempting to access a method on a non-object type (`unknown-ref(ExcimerLogEntry)`)." +file = "src/Serializer/AbstractSerializer.php" +code = "invalid-operand" +message = "Left operand in `&&` operation is an `object`." count = 1 [[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "invalid-method-access" -message = "Attempting to access a method on a non-object type (`unknown-ref(ExcimerProfiler)`)." -count = 8 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" +file = "src/Serializer/AbstractSerializer.php" code = "mixed-argument" -message = 'Invalid argument type for argument #1 of `Sentry\Profiling\ContinuousProfiler::completeChunks`: expected `iterable`, but found `mixed`.' +message = "Invalid argument type for argument #1 of `method_exists`: expected `object|string`, but found `nonnull`." count = 1 [[issues]] -file = "src/Profiling/ContinuousProfiler.php" +file = "src/Serializer/AbstractSerializer.php" code = "mixed-assignment" message = "Assigning `mixed` type to a variable may lead to unexpected behavior." -count = 2 +count = 5 [[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "mixed-operand" -message = "Left operand in `>=` comparison has `mixed` type." -count = 1 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "mixed-operand" -message = "Left operand in binary operation has type `mixed`." -count = 1 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "mixed-operand" -message = "Right operand in `<` comparison has `mixed` type." -count = 1 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "mixed-operand" -message = "Right operand in binary operation has type `mixed`." -count = 1 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "non-existent-class" -message = "Class `ExcimerProfiler` not found." -count = 1 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "non-existent-class-like" -message = "Cannot find class, interface, enum, or type alias `ExcimerLogEntry`." -count = 4 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "non-existent-class-like" -message = "Cannot find class, interface, enum, or type alias `ExcimerProfiler`." -count = 1 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "non-existent-class-like" -message = "Class, Interface, or Trait `ExcimerLogEntry` does not exist." -count = 2 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "non-existent-constant" -message = "Undefined constant: `EXCIMER_REAL`." -count = 1 - -[[issues]] -file = "src/Profiling/ContinuousProfiler.php" -code = "possibly-invalid-array-access" -message = "Cannot perform array access on value of type `unknown-ref(ExcimerLogEntry)`." -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "invalid-iterator" -message = "The expression provided to `foreach` is not iterable. It resolved to type `mixed`, which is not iterable." -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #1 of `Sentry\Profiling\ProfileFrame::__construct`: expected `string`, but found `mixed`.' -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #2 of `Sentry\Profiling\ProfileSample::__construct`: expected `float`, but found `mixed`.' -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #2 of `Sentry\Util\PrefixStripper::stripPrefixFromFilePath`: expected `string`, but found `mixed`.' -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #3 of `Sentry\Profiling\ProfileFrame::__construct`: expected `string`, but found `mixed`.' -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-argument" -message = "Invalid argument type for argument #3 of `preg_replace_callback`: expected `array|string`, but found `mixed`." -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #4 of `Sentry\Profiling\ProfileFrame::__construct`: expected `null|string`, but found `mixed`.' -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #5 of `Sentry\Profiling\ProfileFrame::__construct`: expected `int|null`, but found `mixed`.' -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-array-access" -message = "Unsafe array access on type `mixed`." -count = 4 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-assignment" -message = "Assigning `mixed` type to a variable may lead to unexpected behavior." -count = 10 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-assignment" -message = "Assigning `nonnull` type to a variable may lead to unexpected behavior." -count = 3 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-operand" -message = "Invalid left operand: type `nonnull` cannot be reliably used in string concatenation." -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-operand" -message = "Invalid right operand: type `nonnull` cannot be reliably used in string concatenation." -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-operand" -message = "Left operand in `>` comparison has `mixed` type." -count = 2 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-operand" -message = "Left operand in binary operation has type `mixed`." -count = 3 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "mixed-operand" -message = "Right operand in binary operation has type `mixed`." -count = 3 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "non-existent-class-like" -message = "Cannot find class, interface, enum, or type alias `ExcimerLogEntry`." -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "non-existent-class-like" -message = "Class, Interface, or Trait `ExcimerLogEntry` does not exist." -count = 1 - -[[issues]] -file = "src/Profiling/ExcimerLogConverter.php" -code = "possibly-invalid-array-access" -message = "Cannot perform array access on value of type `unknown-ref(ExcimerLogEntry)`." -count = 2 - -[[issues]] -file = "src/Profiling/Profile.php" -code = "invalid-method-access" -message = "Attempting to access a method on a non-object type (`unknown-ref(ExcimerLog)`)." -count = 1 - -[[issues]] -file = "src/Profiling/Profile.php" -code = "invalid-return-statement" -message = '''Invalid return type for function `Sentry\Profiling\Profile::getFormattedData`: expected `array{'device': array{'architecture': string}, 'environment': string, 'event_id': string, 'os': array{'build_number': string, 'name': string, 'version': string}, 'platform': string('php'), 'profile': array{'frames': array, 'samples': array, 'stacks': array>}, 'release': string, 'runtime': array{'name': string, 'version': string}, 'timestamp': string, 'transaction': array{'active_thread_id': string, 'id': string, 'name': string, 'trace_id': string}, 'version': string}|null`, but found `array{'device': array{'architecture': null|string}, 'environment': string, 'event_id': string, 'os': array{'build_number': string, 'name': string, 'version': null|string}, 'platform': string('php'), 'profile': array{'frames': array{}|non-empty-list, 'samples': array{}|non-empty-list, 'stacks': array>}, 'release': string, 'runtime': array{'name': string, 'sapi': null|string, 'version': null|string}, 'timestamp': non-empty-string, 'transaction': array{'active_thread_id': string, 'id': string, 'name': null|string, 'trace_id': null|string}, 'version': string}`.''' -count = 1 - -[[issues]] -file = "src/Profiling/Profile.php" -code = "mixed-assignment" -message = "Assigning `mixed` type to a variable may lead to unexpected behavior." -count = 1 - -[[issues]] -file = "src/Profiling/Profile.php" -code = "mixed-operand" -message = "Left operand in `>=` comparison has `mixed` type." -count = 1 - -[[issues]] -file = "src/Profiling/Profile.php" -code = "non-existent-class-like" -message = "Cannot find class, interface, enum, or type alias `ExcimerLog`." -count = 2 - -[[issues]] -file = "src/Profiling/Profile.php" -code = "possibly-invalid-argument" -message = '''Possible argument type mismatch for argument #1 of `Sentry\Profiling\ExcimerLogConverter::convert`: expected `iterable}|unknown-ref(ExcimerLogEntry)>`, but possibly received `array}>|unknown-ref(ExcimerLog)`.''' -count = 1 - -[[issues]] -file = "src/Profiling/Profiler.php" -code = "invalid-method-access" -message = "Attempting to access a method on a non-object type (`unknown-ref(ExcimerProfiler)`)." -count = 3 - -[[issues]] -file = "src/Profiling/Profiler.php" -code = "mixed-argument" -message = '''Invalid argument type for argument #1 of `Sentry\Profiling\Profile::setExcimerLog`: expected `array}>|unknown-ref(ExcimerLog)`, but found `mixed`.''' -count = 1 - -[[issues]] -file = "src/Profiling/Profiler.php" -code = "non-existent-class" -message = "Class `ExcimerProfiler` not found." -count = 1 - -[[issues]] -file = "src/Profiling/Profiler.php" -code = "non-existent-class-like" -message = "Cannot find class, interface, enum, or type alias `ExcimerProfiler`." -count = 1 - -[[issues]] -file = "src/Profiling/Profiler.php" -code = "non-existent-constant" -message = "Undefined constant: `EXCIMER_REAL`." -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "generic-object-iteration" -message = "Iterating over a generic `object`. This will iterate its public properties." -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "impossible-type-comparison" -message = "Impossible type assertion: `$callable` of type `(callable(...mixed): mixed)` can never be `object`." -count = 2 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "invalid-operand" -message = "Invalid type `scalar` for middle operand in string concatenation." -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "invalid-operand" -message = "Left operand in `&&` operation is an `object`." -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "invalid-return-statement" -message = 'Invalid return type for function `Sentry\Serializer\AbstractSerializer::serializeValue`: expected `bool|float|int|null|string`, but found `bool|null|numeric`.' -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "mixed-argument" -message = "Invalid argument type for argument #1 of `method_exists`: expected `class-string|object`, but found `nonnull`." -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "mixed-assignment" -message = "Assigning `mixed` type to a variable may lead to unexpected behavior." -count = 5 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "no-value" -message = "Argument #1 passed to function `method_exists` has type `never`, meaning it cannot produce a value." -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "no-value" -message = "Argument #1 passed to method `ReflectionMethod::__construct` has type `never`, meaning it cannot produce a value." -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "null-operand" -message = "Right operand in `!=` comparison is `null`." +file = "src/Serializer/AbstractSerializer.php" +code = "null-operand" +message = "Right operand in `!=` comparison is `null`." count = 1 [[issues]] @@ -1422,18 +972,6 @@ code = "redundant-cast" message = "Redundant cast to `(string)`: the expression already has this type." count = 1 -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "redundant-logical-operation" -message = "Redundant `&&` operation: left operand is always falsy and right operand is not evaluated." -count = 1 - -[[issues]] -file = "src/Serializer/AbstractSerializer.php" -code = "redundant-logical-operation" -message = "Redundant `&&` operation: left operand is always truthy and right operand is evaluated." -count = 1 - [[issues]] file = "src/Serializer/EnvelopItems/EventItem.php" code = "mixed-array-assignment" @@ -1470,12 +1008,6 @@ code = "mixed-assignment" message = "Assigning `mixed` type to a variable may lead to unexpected behavior." count = 1 -[[issues]] -file = "src/Serializer/RepresentationSerializer.php" -code = "invalid-operand" -message = "Invalid type `never` for left operand in string concatenation." -count = 1 - [[issues]] file = "src/Serializer/Traits/BreadcrumbSerializerTrait.php" code = "invalid-return-statement" @@ -1494,12 +1026,6 @@ code = "deprecated-function" message = "Call to deprecated function: `curl_close`." count = 2 -[[issues]] -file = "src/Spotlight/SpotlightClient.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 2 - [[issues]] file = "src/Spotlight/SpotlightClient.php" code = "mixed-argument" @@ -1518,78 +1044,18 @@ code = "redundant-comparison" message = "Redundant `<` comparison: left-hand side is never less than right-hand side." count = 2 -[[issues]] -file = "src/Stacktrace.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - -[[issues]] -file = "src/Stacktrace.php" -code = "no-value" -message = 'Argument #1 passed to method `Sentry\Util\DebugType::getDebugType` has type `never`, meaning it cannot produce a value.' -count = 1 - -[[issues]] -file = "src/StacktraceBuilder.php" -code = "less-specific-nested-argument-type" -message = 'Argument type mismatch for argument #1 of `Sentry\Stacktrace::__construct`: expected `array`, but provided type `non-empty-list` is less specific.' -count = 1 - [[issues]] file = "src/StacktraceBuilder.php" code = "possibly-invalid-argument" message = '''Possible argument type mismatch for argument #1 of `Sentry\StacktraceBuilder::buildFromBacktrace`: expected `list, 'class'?: class-string, 'file'?: string, 'function'?: string, 'line'?: int, 'type'?: string}>`, but possibly received `array`.''' count = 1 -[[issues]] -file = "src/State/Scope.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 2 - [[issues]] file = "src/State/Scope.php" code = "mixed-assignment" message = "Assigning `mixed` type to a variable may lead to unexpected behavior." count = 3 -[[issues]] -file = "src/State/Scope.php" -code = "mixed-property-type-coercion" -message = 'A value with a less specific type `non-empty-array|non-empty-list<(callable(...mixed): mixed)>` is being assigned to property `$$eventProcessors` (array).' -count = 1 - -[[issues]] -file = "src/State/Scope.php" -code = "no-value" -message = 'Argument #1 passed to method `Sentry\Util\DebugType::getDebugType` has type `never`, meaning it cannot produce a value.' -count = 1 - -[[issues]] -file = "src/State/Scope.php" -code = "redundant-comparison" -message = "Redundant `!==` comparison: left-hand side is always not identical to right-hand side." -count = 1 - -[[issues]] -file = "src/State/Scope.php" -code = "redundant-condition" -message = "This condition (type `true`) will always evaluate to true." -count = 1 - -[[issues]] -file = "src/State/Scope.php" -code = "redundant-logical-operation" -message = "Redundant `&&` operation: left operand is evaluated and right operand is always falsy." -count = 1 - -[[issues]] -file = "src/Tracing/DynamicSamplingContext.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #2 of `Sentry\Tracing\DynamicSamplingContext::set`: expected `string`, but found `mixed`.' -count = 1 - [[issues]] file = "src/Tracing/DynamicSamplingContext.php" code = "possibly-null-argument" @@ -1602,54 +1068,12 @@ code = "implicit-to-string-cast" message = 'Implicit conversion to `string` for right operand via `Psr\Http\Message\UriInterface::__toString()`.' count = 1 -[[issues]] -file = "src/Tracing/GuzzleTracingMiddleware.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #1 of `Sentry\Tracing\SpanStatus::createFromHttpStatusCode`: expected `int`, but found `mixed`.' -count = 1 - [[issues]] file = "src/Tracing/GuzzleTracingMiddleware.php" code = "mixed-assignment" message = "Assigning `mixed` type to a variable may lead to unexpected behavior." count = 1 -[[issues]] -file = "src/Tracing/GuzzleTracingMiddleware.php" -code = "mixed-method-access" -message = "Attempting to access a method on a non-object type (`mixed`)." -count = 2 - -[[issues]] -file = "src/Tracing/GuzzleTracingMiddleware.php" -code = "mixed-method-access" -message = "Attempting to access a method on a non-object type (`nonnull`)." -count = 7 - -[[issues]] -file = "src/Tracing/GuzzleTracingMiddleware.php" -code = "mixed-operand" -message = "Left operand in `<` comparison has `mixed` type." -count = 1 - -[[issues]] -file = "src/Tracing/GuzzleTracingMiddleware.php" -code = "mixed-operand" -message = "Left operand in `>=` comparison has `mixed` type." -count = 3 - -[[issues]] -file = "src/Tracing/GuzzleTracingMiddleware.php" -code = "non-existent-class-like" -message = 'Class, Interface, or Trait `GuzzleHttp\Exception\RequestException` does not exist.' -count = 3 - -[[issues]] -file = "src/Tracing/GuzzleTracingMiddleware.php" -code = "non-existent-method" -message = 'Method `getresponse` does not exist on type `GuzzleHttp\Exception\RequestException`.' -count = 1 - [[issues]] file = "src/Tracing/GuzzleTracingMiddleware.php" code = "possibly-null-argument" @@ -1668,18 +1092,6 @@ code = "invalid-type-cast" message = "Non numeric string of type `string` implicitly cast to `float`." count = 4 -[[issues]] -file = "src/Tracing/Traits/TraceHeaderParserTrait.php" -code = "mixed-argument" -message = "Invalid argument type for argument #3 of `sprintf`: expected `Stringable|null|scalar`, but found `nonnull`." -count = 1 - -[[issues]] -file = "src/Tracing/Traits/TraceHeaderParserTrait.php" -code = "mixed-assignment" -message = "Assigning `mixed` type to a variable may lead to unexpected behavior." -count = 1 - [[issues]] file = "src/Tracing/Traits/TraceHeaderParserTrait.php" code = "possible-method-access-on-null" @@ -1692,12 +1104,6 @@ code = "reference-to-undefined-variable" message = "Reference created from a previously undefined variable `$matches`." count = 1 -[[issues]] -file = "src/Tracing/Transaction.php" -code = "incompatible-property-type" -message = 'Property `Sentry\Tracing\Transaction::$transaction` has an incompatible type declaration from docblock.' -count = 1 - [[issues]] file = "src/Tracing/Transaction.php" code = "invalid-return-statement" @@ -1722,18 +1128,6 @@ code = "implicit-to-string-cast" message = 'Implicit conversion to `string` for left operand via `Sentry\Severity::__toString()`.' count = 2 -[[issues]] -file = "src/Transport/HttpTransport.php" -code = "mixed-argument" -message = "Invalid argument type for argument #2 of `sprintf`: expected `Stringable|null|scalar`, but found `mixed`." -count = 1 - -[[issues]] -file = "src/Transport/HttpTransport.php" -code = "mixed-argument" -message = "Invalid argument type for argument #3 of `sprintf`: expected `Stringable|null|scalar`, but found `mixed`." -count = 1 - [[issues]] file = "src/Transport/HttpTransport.php" code = "possible-method-access-on-null" @@ -1746,12 +1140,6 @@ code = "possibly-null-operand" message = 'Possibly null left operand used in string concatenation (type `Sentry\Severity|null`).' count = 2 -[[issues]] -file = "src/UserDataBag.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - [[issues]] file = "src/UserDataBag.php" code = "mixed-argument" @@ -1782,30 +1170,6 @@ code = "mixed-assignment" message = "Assigning `mixed` type to a variable may lead to unexpected behavior." count = 1 -[[issues]] -file = "src/UserDataBag.php" -code = "no-value" -message = 'Argument #1 passed to method `Sentry\Util\DebugType::getDebugType` has type `never`, meaning it cannot produce a value.' -count = 1 - -[[issues]] -file = "src/UserDataBag.php" -code = "redundant-comparison" -message = "Redundant `!==` comparison: left-hand side is always not identical to right-hand side." -count = 1 - -[[issues]] -file = "src/UserDataBag.php" -code = "redundant-condition" -message = "This condition (type `true`) will always evaluate to true." -count = 1 - -[[issues]] -file = "src/UserDataBag.php" -code = "redundant-logical-operation" -message = "Redundant `&&` operation: left operand is evaluated and right operand is always falsy." -count = 1 - [[issues]] file = "src/UserDataBag.php" code = "redundant-type-comparison" @@ -1818,12 +1182,6 @@ code = "invalid-iterator" message = "The expression provided to `foreach` is not iterable. It resolved to type `mixed`, which is not iterable." count = 1 -[[issues]] -file = "src/Util/Arr.php" -code = "less-specific-argument" -message = 'Argument type mismatch for argument #1 of `Sentry\Util\Arr::isList`: expected `array`, but provided type `non-empty-array` is less specific.' -count = 1 - [[issues]] file = "src/Util/Arr.php" code = "mixed-assignment" @@ -1842,24 +1200,6 @@ code = "mixed-operand" message = "Invalid right operand: type `mixed` cannot be reliably used in string concatenation." count = 1 -[[issues]] -file = "src/Util/Arr.php" -code = "redundant-comparison" -message = "Redundant `!==` comparison: left-hand side is always not identical to right-hand side." -count = 1 - -[[issues]] -file = "src/Util/Arr.php" -code = "redundant-condition" -message = "This condition (type `true`) will always evaluate to true." -count = 1 - -[[issues]] -file = "src/Util/DebugType.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - [[issues]] file = "src/Util/DebugType.php" code = "mixed-argument" @@ -1869,7 +1209,7 @@ count = 1 [[issues]] file = "src/Util/DebugType.php" code = "possibly-false-argument" -message = "Argument #1 of function `key` is possibly `false`, but parameter type `array|object` does not accept it." +message = "Argument #1 of function `key` is possibly `false`, but parameter type `array|object` does not accept it." count = 1 [[issues]] @@ -1890,18 +1230,6 @@ code = "avoid-catching-error" message = "Avoid catching 'Error' class instances." count = 1 -[[issues]] -file = "src/Util/Str.php" -code = "impossible-condition" -message = "Redundant ternary operator: condition is always falsy." -count = 1 - -[[issues]] -file = "src/Util/Str.php" -code = "impossible-condition" -message = "This condition (type `false`) will always evaluate to false." -count = 1 - [[issues]] file = "src/Util/Str.php" code = "redundant-comparison" @@ -1913,15 +1241,3 @@ file = "src/Util/Str.php" code = "redundant-comparison" message = "Redundant `===` comparison: left-hand side is never identical to right-hand side." count = 1 - -[[issues]] -file = "src/Util/Str.php" -code = "redundant-logical-operation" -message = "Redundant `&&` operation: left operand is evaluated and right operand is always falsy." -count = 1 - -[[issues]] -file = "src/functions.php" -code = "mixed-assignment" -message = "Assigning `mixed` type to a variable may lead to unexpected behavior." -count = 1 diff --git a/composer.json b/composer.json index 8803a6557c..37080347f6 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "psr/log": "^1.0|^2.0|^3.0" }, "require-dev": { - "carthage-software/mago": "1.30.0", + "carthage-software/mago": "1.60.2", "friendsofphp/php-cs-fixer": "^3.4", "guzzlehttp/guzzle": "^7.0|^8.0", "guzzlehttp/promises": "^2.0.3|^3.0.0", diff --git a/mago.toml b/mago.toml index b4534de5de..ff35aa6c5a 100644 --- a/mago.toml +++ b/mago.toml @@ -1,12 +1,13 @@ [source] paths = ["src"] -includes = ["vendor"] +includes = ["vendor", "stubs"] excludes = [ "tests/resources/**", "tests/Fixtures/**", "src/Util/ClockMock.php", "vendor/open-telemetry/gen-otlp-protobuf/GPBMetadata/**", ] +extensions = ["php", "stub"] [analyzer] baseline = "analysis-baseline.toml" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7181043026..3c3a4e8036 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -396,12 +396,6 @@ parameters: count: 1 path: src/Serializer/AbstractSerializer.php - - - message: '#^Parameter \#3 \$value of function curl_setopt expects int, float given\.$#' - identifier: argument.type - count: 2 - path: src/Spotlight/SpotlightClient.php - - message: '#^Parameter \#3 \$value of function curl_setopt expects non\-empty\-string, string given\.$#' identifier: argument.type @@ -438,12 +432,6 @@ parameters: count: 1 path: src/UserDataBag.php - - - message: '#^PHPDoc tag @var with type list\\}\> is not subtype of native type list\''\|''\:\:'', args\?\: list\, object\?\: object\}\>\.$#' - identifier: varTag.nativeType - count: 1 - path: src/Util/CodeLocationResolver.php - - message: '#^Instanceof between mixed and __PHP_Incomplete_Class will always evaluate to false\.$#' identifier: instanceof.alwaysFalse diff --git a/src/Attachment/Attachment.php b/src/Attachment/Attachment.php index 9fdeea4383..9aa0611f5b 100644 --- a/src/Attachment/Attachment.php +++ b/src/Attachment/Attachment.php @@ -42,8 +42,8 @@ public function getContentType(): string * If no low overhead way exists, then the result should be cached so that calling it multiple times * does not decrease performance. * - * @return int the size in bytes or null if the length could not be determined, for example if the file - * does not exist + * @return int|null the size in bytes or null if the length could not be determined, for example if the file + * does not exist */ abstract public function getSize(): ?int; @@ -51,8 +51,8 @@ abstract public function getSize(): ?int; * Fetches and returns the data. Calling this can have a non-trivial impact on memory usage, depending * on the type and size of attachment. * - * @return string the content as bytes or null if the content could not be retrieved, for example if the file - * does not exist + * @return string|null the content as bytes or null if the content could not be retrieved, for example if the + * file does not exist */ abstract public function getData(): ?string; diff --git a/src/ClientReport/ClientReportAggregator.php b/src/ClientReport/ClientReportAggregator.php index d6f8d7e308..5e4666ef39 100644 --- a/src/ClientReport/ClientReportAggregator.php +++ b/src/ClientReport/ClientReportAggregator.php @@ -28,7 +28,7 @@ class ClientReportAggregator * ] *``` * - * @var array> + * @var array> */ private $reports = []; diff --git a/src/Dsn.php b/src/Dsn.php index 0993db3e8a..512d942a1a 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -89,7 +89,7 @@ public static function createFromString(string $value): self } foreach (['scheme', 'host', 'path', 'user'] as $component) { - if (!isset($parsedDsn[$component]) || (isset($parsedDsn[$component]) && empty($parsedDsn[$component]))) { + if (empty($parsedDsn[$component])) { throw new \InvalidArgumentException(\sprintf('The "%s" DSN must contain a scheme, a host, a user and a path component.', $value)); } } diff --git a/src/Spotlight/SpotlightClient.php b/src/Spotlight/SpotlightClient.php index 0b56517b3c..f8c7e9b9cf 100644 --- a/src/Spotlight/SpotlightClient.php +++ b/src/Spotlight/SpotlightClient.php @@ -29,8 +29,8 @@ public static function sendRequest(Request $request, string $url): Response curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, [ 'Content-Type: application/x-sentry-envelope', ]); - curl_setopt($curlHandle, \CURLOPT_TIMEOUT, 2.0); - curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, 1.0); + curl_setopt($curlHandle, \CURLOPT_TIMEOUT, 2); + curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($curlHandle, \CURLOPT_ENCODING, ''); curl_setopt($curlHandle, \CURLOPT_POST, true); curl_setopt($curlHandle, \CURLOPT_POSTFIELDS, $requestData); diff --git a/src/State/MutableScope.php b/src/State/MutableScope.php index cecacdf826..fdd1b6b1f7 100644 --- a/src/State/MutableScope.php +++ b/src/State/MutableScope.php @@ -161,6 +161,22 @@ public function setUser($user): self return $this; } + /** + * Sets a callable that resolves the user each time it is read, which + * happens for every event, log and metric, so it should be cheap. The + * data set on the scope takes precedence over the data it returns. + * + * @param callable(): (UserDataBag|null) $userResolver + * + * @return $this + */ + public function setUserResolver(callable $userResolver): self + { + $this->scopeData->setUserResolver($userResolver); + + return $this; + } + /** * Removes all data of the user context. * diff --git a/src/State/ScopeData.php b/src/State/ScopeData.php index 202e5d77ea..c926ac351e 100644 --- a/src/State/ScopeData.php +++ b/src/State/ScopeData.php @@ -43,6 +43,11 @@ class ScopeData */ private $user; + /** + * @var (callable(): (UserDataBag|null))|null The callable that resolves the user each time it is read + */ + private $userResolver; + /** * @var array> The list of contexts associated to this scope */ @@ -135,7 +140,45 @@ public function clearBreadcrumbs(): void public function getUser(): ?UserDataBag { - return $this->user; + if ($this->userResolver === null) { + return $this->user; + } + + $userResolver = $this->userResolver; + // unset the callback to prevent recursion in case getUser is called in the callback + $this->userResolver = null; + + try { + $resolvedUser = $userResolver(); + } catch (\Throwable $exception) { + $resolvedUser = null; + } finally { + $this->userResolver = $userResolver; + } + + if ($resolvedUser === null) { + return $this->user; + } + + if ($this->user === null) { + return clone $resolvedUser; + } + + $user = clone $this->user; + $user->setId($user->getId() ?? $resolvedUser->getId()); + $user->setEmail($user->getEmail() ?? $resolvedUser->getEmail()); + $user->setUsername($user->getUsername() ?? $resolvedUser->getUsername()); + $user->setIpAddress($user->getIpAddress() ?? $resolvedUser->getIpAddress()); + + return (clone $resolvedUser)->merge($user); + } + + /** + * @param callable(): (UserDataBag|null) $userResolver + */ + public function setUserResolver(callable $userResolver): void + { + $this->userResolver = $userResolver; } /** @@ -161,6 +204,7 @@ public function setUser($user): void public function removeUser(): void { $this->user = null; + $this->userResolver = null; } /** @@ -328,6 +372,7 @@ public function addAttachment(Attachment $attachment): void public function clear(): void { $this->user = null; + $this->userResolver = null; $this->level = null; $this->fingerprint = []; $this->breadcrumbs = []; @@ -363,6 +408,8 @@ public function merge(self $other): self $merged->user = clone $this->user; } + $merged->userResolver = $other->userResolver ?? $this->userResolver; + $merged->level = $other->level ?? $this->level; $merged->fingerprint = array_merge($this->fingerprint, $other->fingerprint); $merged->breadcrumbs = self::mergeBreadcrumbs($this->breadcrumbs, $other->breadcrumbs); diff --git a/src/Tracing/Transaction.php b/src/Tracing/Transaction.php index 44a6a81dbf..dec5c22059 100644 --- a/src/Tracing/Transaction.php +++ b/src/Tracing/Transaction.php @@ -33,11 +33,6 @@ final class Transaction extends Span */ private $scope; - /** - * @var Transaction The transaction - */ - protected $transaction; - /** * @var TransactionMetadata */ @@ -104,7 +99,7 @@ public function getDynamicSamplingContext(): DynamicSamplingContext return $this->metadata->getDynamicSamplingContext(); } - $samplingContext = DynamicSamplingContext::fromTransaction($this->transaction, SentrySdk::getClient($this->scope)); + $samplingContext = DynamicSamplingContext::fromTransaction($this, SentrySdk::getClient($this->scope)); $this->getMetadata()->setDynamicSamplingContext($samplingContext); return $samplingContext; diff --git a/src/Transport/HttpTransport.php b/src/Transport/HttpTransport.php index c09c3b5564..60a1872b43 100644 --- a/src/Transport/HttpTransport.php +++ b/src/Transport/HttpTransport.php @@ -155,6 +155,9 @@ public function send(Event $event): Result ['exception' => $exception, 'event' => $event] ); + // No response was received, so this is recorded like a failed connection + ClientReportAggregator::getInstance()->addEvent($event, Reason::networkError()); + return new Result(ResultStatus::failed()); } diff --git a/src/Util/CodeLocationResolver.php b/src/Util/CodeLocationResolver.php index cc968e70c5..e89063ba20 100644 --- a/src/Util/CodeLocationResolver.php +++ b/src/Util/CodeLocationResolver.php @@ -42,7 +42,7 @@ public function __construct(Options $options, RepresentationSerializerInterface */ public function resolve(int $limit = 20): ?array { - /** @var list $backtrace */ + /** @var list'|'::'}> $backtrace */ $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, $limit); return $this->resolveFromBacktrace($backtrace); diff --git a/tests/State/ScopeTest.php b/tests/State/ScopeTest.php index d4d31fff54..3ce78aa253 100644 --- a/tests/State/ScopeTest.php +++ b/tests/State/ScopeTest.php @@ -382,6 +382,143 @@ public function testSetUserThrowsOnInvalidArgument(): void $scope->setUser('foo'); } + public function testSetUserResolver(): void + { + $scope = new IsolationScope(); + $scope->setUser(UserDataBag::createFromUserIpAddress('127.0.0.1')); + + $resolvable = false; + $calls = 0; + + $scope->setUserResolver(static function () use (&$resolvable, &$calls): ?UserDataBag { + ++$calls; + + return $resolvable ? UserDataBag::createFromUserIdentifier('unique_id') : null; + }); + + $this->assertEquals(UserDataBag::createFromUserIpAddress('127.0.0.1'), $scope->getUser()); + $this->assertSame(1, $calls); + + $resolvable = true; + + $event = $this->applyScope($scope, Event::createEvent()); + + $this->assertNotNull($event); + $this->assertEquals(UserDataBag::createFromArray(['id' => 'unique_id', 'ip_address' => '127.0.0.1']), $event->getUser()); + $this->assertSame(2, $calls); + + $resolvable = false; + + $this->assertEquals(UserDataBag::createFromUserIpAddress('127.0.0.1'), $scope->getUser()); + } + + public function testSetUserResolverDoesNotOverrideTheUser(): void + { + $scope = new IsolationScope(); + $scope->setUser(['id' => 'unique_id', 'subscription' => 'basic']); + + $scope->setUserResolver(static function (): UserDataBag { + return UserDataBag::createFromArray([ + 'id' => 'resolved_id', + 'email' => 'foo@example.com', + 'segment' => 'my_segment', + 'subscription' => 'pro', + 'plan' => 'yearly', + ]); + }); + + $this->assertEquals( + UserDataBag::createFromArray([ + 'id' => 'unique_id', + 'email' => 'foo@example.com', + 'segment' => 'my_segment', + 'subscription' => 'basic', + 'plan' => 'yearly', + ]), + $scope->getUser() + ); + } + + public function testSetUserResolverDoesNotChangeTheResolvedUser(): void + { + $resolvedUser = UserDataBag::createFromUserIdentifier('unique_id'); + + $scope = new IsolationScope(); + $scope->setUserResolver(static function () use ($resolvedUser): UserDataBag { + return $resolvedUser; + }); + + $event = Event::createEvent(); + $event->setUser(UserDataBag::createFromUserIpAddress('127.0.0.1')); + + $this->applyScope($scope, $event); + + $this->assertEquals(UserDataBag::createFromUserIdentifier('unique_id'), $resolvedUser); + } + + public function testSetUserResolverKeepsTheUserIfTheResolverThrows(): void + { + $scope = new IsolationScope(); + $scope->setUser(UserDataBag::createFromUserIpAddress('127.0.0.1')); + + $scope->setUserResolver(static function (): UserDataBag { + throw new \RuntimeException('foo'); + }); + + $this->assertEquals(UserDataBag::createFromUserIpAddress('127.0.0.1'), $scope->getUser()); + } + + public function testSetUserResolverIsNotCalledAgainWhileItRuns(): void + { + $scope = new IsolationScope(); + $calls = 0; + + $scope->setUserResolver(static function () use ($scope, &$calls): ?UserDataBag { + ++$calls; + + return $scope->getUser(); + }); + + $this->assertNull($scope->getUser()); + $this->assertSame(1, $calls); + + $scope->getUser(); + + $this->assertSame(2, $calls); + } + + public function testRemoveUserRemovesTheUserResolver(): void + { + $scope = new IsolationScope(); + $scope->setUserResolver(static function (): UserDataBag { + return UserDataBag::createFromUserIdentifier('unique_id'); + }); + + $this->assertEquals(UserDataBag::createFromUserIdentifier('unique_id'), $scope->getUser()); + + $scope->removeUser(); + + $this->assertNull($scope->getUser()); + } + + public function testUserResolverOfTheIsolationScopeTakesPrecedenceOverTheGlobalScope(): void + { + $globalScope = new GlobalScope(); + $globalScope->setUserResolver(static function (): UserDataBag { + return UserDataBag::createFromUserIdentifier('global_id'); + }); + + $isolationScope = new IsolationScope(); + + $this->assertEquals(UserDataBag::createFromUserIdentifier('global_id'), $globalScope->merge($isolationScope)->getUser()); + + $isolationScope->setUserResolver(static function (): UserDataBag { + return UserDataBag::createFromUserIdentifier('isolation_id'); + }); + + $this->assertEquals(UserDataBag::createFromUserIdentifier('isolation_id'), $globalScope->merge($isolationScope)->getUser()); + } + public function testRemoveUser(): void { $scope = new IsolationScope(); @@ -646,6 +783,9 @@ public function testClear(): void $scope->setTags(['bar' => 'foo']); $scope->addFeatureFlag('feature', true); $scope->setUser(UserDataBag::createFromUserIdentifier('unique_id')); + $scope->setUserResolver(static function (): UserDataBag { + return UserDataBag::createFromUserIdentifier('resolved_id'); + }); $scope->clear(); $event = $this->applyScope($scope, Event::createEvent()); diff --git a/tests/Transport/HttpTransportTest.php b/tests/Transport/HttpTransportTest.php index 353bb175a2..7e26fc8e7d 100644 --- a/tests/Transport/HttpTransportTest.php +++ b/tests/Transport/HttpTransportTest.php @@ -165,6 +165,10 @@ public static function sendDataProvider(): iterable public function testSendFailsDueToHttpClientException(): void { + SentrySdk::init(new Client(new Options([ + 'send_client_reports' => true, + ]), StubTransport::getInstance())); + $exception = new \Exception('foo'); $event = Event::createEvent(); @@ -198,6 +202,7 @@ public function testSendFailsDueToHttpClientException(): void $result = $transport->send($event); $this->assertSame(ResultStatus::failed(), $result->getStatus()); + $this->assertClientReports(['error' => ['network_error' => 1]]); } public function testRecordsClientReportWhenSerializationFails(): void