From b95390879570f4c258cbc47e9de89ae2dc27213a Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Wed, 24 Sep 2025 09:10:47 +0200 Subject: [PATCH 1/4] ref: remove polyfill --- src/CheckInStatus.php | 2 +- src/Dsn.php | 2 +- src/Event.php | 2 +- src/EventHint.php | 8 ++++---- src/EventId.php | 2 +- src/EventType.php | 2 +- src/FrameBuilder.php | 2 +- src/Integration/IntegrationRegistry.php | 2 +- src/MonitorScheduleUnit.php | 2 +- src/Severity.php | 2 +- src/Stacktrace.php | 2 +- src/State/Scope.php | 2 +- src/Tracing/DynamicSamplingContext.php | 2 +- src/Tracing/SpanId.php | 2 +- src/Tracing/SpanStatus.php | 2 +- src/Tracing/TraceId.php | 2 +- src/Tracing/TransactionSource.php | 2 +- src/Transport/ResultStatus.php | 2 +- src/UserDataBag.php | 2 +- tests/Integration/IntegrationRegistryTest.php | 4 ++-- tests/Logs/LogsAggregatorTest.php | 2 +- tests/Monolog/LogsHandlerTest.php | 2 +- tests/StacktraceTest.php | 6 +++--- tests/UserDataBagTest.php | 4 ++-- 24 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/CheckInStatus.php b/src/CheckInStatus.php index c29547107..ecb5a09b7 100644 --- a/src/CheckInStatus.php +++ b/src/CheckInStatus.php @@ -7,7 +7,7 @@ /** * This enum represents all the possible status of a check in. */ -final class CheckInStatus implements \Stringable +final class CheckInStatus { /** * @var string The value of the enum instance diff --git a/src/Dsn.php b/src/Dsn.php index b6f952297..e9741a44f 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -10,7 +10,7 @@ * * @author Stefano Arlandini */ -final class Dsn implements \Stringable +final class Dsn { /** * @var string Regex to match the organization ID in the host. diff --git a/src/Event.php b/src/Event.php index 5244f945c..bfdf12fb9 100644 --- a/src/Event.php +++ b/src/Event.php @@ -842,7 +842,7 @@ public function setExceptions(array $exceptions): self { foreach ($exceptions as $exception) { if (!$exception instanceof ExceptionDataBag) { - throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', ExceptionDataBag::class, get_debug_type($exception))); + throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', ExceptionDataBag::class, gettype($exception))); } } diff --git a/src/EventHint.php b/src/EventHint.php index 58b6ffc57..95dd66e0f 100644 --- a/src/EventHint.php +++ b/src/EventHint.php @@ -56,19 +56,19 @@ public static function fromArray(array $hintData): self $extra = $hintData['extra'] ?? []; if ($exception !== null && !$exception instanceof \Throwable) { - throw new \InvalidArgumentException(\sprintf('The value of the "exception" field must be an instance of a class implementing the "%s" interface. Got: "%s".', \Throwable::class, get_debug_type($exception))); + throw new \InvalidArgumentException(\sprintf('The value of the "exception" field must be an instance of a class implementing the "%s" interface. Got: "%s".', \Throwable::class, \gettype($exception))); } if ($mechanism !== null && !$mechanism instanceof ExceptionMechanism) { - throw new \InvalidArgumentException(\sprintf('The value of the "mechanism" field must be an instance of the "%s" class. Got: "%s".', ExceptionMechanism::class, get_debug_type($mechanism))); + throw new \InvalidArgumentException(\sprintf('The value of the "mechanism" field must be an instance of the "%s" class. Got: "%s".', ExceptionMechanism::class, \gettype($mechanism))); } if ($stacktrace !== null && !$stacktrace instanceof Stacktrace) { - throw new \InvalidArgumentException(\sprintf('The value of the "stacktrace" field must be an instance of the "%s" class. Got: "%s".', Stacktrace::class, get_debug_type($stacktrace))); + throw new \InvalidArgumentException(\sprintf('The value of the "stacktrace" field must be an instance of the "%s" class. Got: "%s".', Stacktrace::class, \gettype($stacktrace))); } if (!\is_array($extra)) { - throw new \InvalidArgumentException(\sprintf('The value of the "extra" field must be an array. Got: "%s".', get_debug_type($extra))); + throw new \InvalidArgumentException(\sprintf('The value of the "extra" field must be an array. Got: "%s".', gettype($extra))); } $hint->exception = $exception; diff --git a/src/EventId.php b/src/EventId.php index e88de486c..a63c3d6df 100644 --- a/src/EventId.php +++ b/src/EventId.php @@ -11,7 +11,7 @@ * * @author Stefano Arlandini */ -final class EventId implements \Stringable +final class EventId { /** * @var string The ID diff --git a/src/EventType.php b/src/EventType.php index 3c2d13fb3..72575de48 100644 --- a/src/EventType.php +++ b/src/EventType.php @@ -10,7 +10,7 @@ * * @author Stefano Arlandini */ -final class EventType implements \Stringable +final class EventType { /** * @var string The value of the enum instance diff --git a/src/FrameBuilder.php b/src/FrameBuilder.php index 8c102ef28..6eae5feb9 100644 --- a/src/FrameBuilder.php +++ b/src/FrameBuilder.php @@ -179,7 +179,7 @@ private function getFunctionArguments(array $backtraceFrame): array } else { $reflectionFunction = new \ReflectionMethod($backtraceFrame['class'], '__call'); } - } elseif ($backtraceFrame['function'] !== '__lambda_func' && !str_starts_with($backtraceFrame['function'], '{closure') && \function_exists($backtraceFrame['function'])) { + } elseif ($backtraceFrame['function'] !== '__lambda_func' && strpos($backtraceFrame['function'], '{closure') !== 0 && \function_exists($backtraceFrame['function'])) { $reflectionFunction = new \ReflectionFunction($backtraceFrame['function']); } } catch (\ReflectionException $e) { diff --git a/src/Integration/IntegrationRegistry.php b/src/Integration/IntegrationRegistry.php index be2df22eb..e2f932881 100644 --- a/src/Integration/IntegrationRegistry.php +++ b/src/Integration/IntegrationRegistry.php @@ -123,7 +123,7 @@ private function getIntegrationsToSetup(Options $options): array $integrations = $userIntegrations($defaultIntegrations); if (!\is_array($integrations)) { - throw new \UnexpectedValueException(\sprintf('Expected the callback set for the "integrations" option to return a list of integrations. Got: "%s".', get_debug_type($integrations))); + throw new \UnexpectedValueException(\sprintf('Expected the callback set for the "integrations" option to return a list of integrations. Got: "%s".', gettype($integrations))); } } diff --git a/src/MonitorScheduleUnit.php b/src/MonitorScheduleUnit.php index 950d95ed8..72f32b9f2 100644 --- a/src/MonitorScheduleUnit.php +++ b/src/MonitorScheduleUnit.php @@ -4,7 +4,7 @@ namespace Sentry; -final class MonitorScheduleUnit implements \Stringable +final class MonitorScheduleUnit { /** * @var string The value of the enum instance diff --git a/src/Severity.php b/src/Severity.php index 89dcabc7d..3841bd8b2 100644 --- a/src/Severity.php +++ b/src/Severity.php @@ -10,7 +10,7 @@ * * @author Stefano Arlandini */ -final class Severity implements \Stringable +final class Severity { /** * This constant represents the "debug" severity level. diff --git a/src/Stacktrace.php b/src/Stacktrace.php index f75d73269..aae40ab5b 100644 --- a/src/Stacktrace.php +++ b/src/Stacktrace.php @@ -31,7 +31,7 @@ public function __construct(array $frames) foreach ($frames as $frame) { if (!$frame instanceof Frame) { - throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', Frame::class, get_debug_type($frame))); + throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', Frame::class, gettype($frame))); } } diff --git a/src/State/Scope.php b/src/State/Scope.php index e4e054c3c..8b02bed44 100644 --- a/src/State/Scope.php +++ b/src/State/Scope.php @@ -208,7 +208,7 @@ public function getUser(): ?UserDataBag public function setUser($user): self { if (!\is_array($user) && !$user instanceof UserDataBag) { - throw new \TypeError(\sprintf('The $user argument must be either an array or an instance of the "%s" class. Got: "%s".', UserDataBag::class, get_debug_type($user))); + throw new \TypeError(\sprintf('The $user argument must be either an array or an instance of the "%s" class. Got: "%s".', UserDataBag::class, gettype($user))); } if (\is_array($user)) { diff --git a/src/Tracing/DynamicSamplingContext.php b/src/Tracing/DynamicSamplingContext.php index 0304504ce..594af8e99 100644 --- a/src/Tracing/DynamicSamplingContext.php +++ b/src/Tracing/DynamicSamplingContext.php @@ -125,7 +125,7 @@ public static function fromHeader(string $header): self $keyValueAndProperties = explode(';', $listMember, 2); $keyValue = trim($keyValueAndProperties[0]); - if (!str_contains($keyValue, '=')) { + if (strpos($keyValue, '=') === false) { continue; } diff --git a/src/Tracing/SpanId.php b/src/Tracing/SpanId.php index f0843681f..c4933f8df 100644 --- a/src/Tracing/SpanId.php +++ b/src/Tracing/SpanId.php @@ -9,7 +9,7 @@ /** * This class represents an span ID. */ -final class SpanId implements \Stringable +final class SpanId { /** * @var string The ID diff --git a/src/Tracing/SpanStatus.php b/src/Tracing/SpanStatus.php index 33c384552..0852ad33b 100644 --- a/src/Tracing/SpanStatus.php +++ b/src/Tracing/SpanStatus.php @@ -4,7 +4,7 @@ namespace Sentry\Tracing; -final class SpanStatus implements \Stringable +final class SpanStatus { /** * @var string The value of the enum instance diff --git a/src/Tracing/TraceId.php b/src/Tracing/TraceId.php index 596ec33b3..5092ec468 100644 --- a/src/Tracing/TraceId.php +++ b/src/Tracing/TraceId.php @@ -9,7 +9,7 @@ /** * This class represents an trace ID. */ -final class TraceId implements \Stringable +final class TraceId { /** * @var string The ID diff --git a/src/Tracing/TransactionSource.php b/src/Tracing/TransactionSource.php index e751edd62..9739886ad 100644 --- a/src/Tracing/TransactionSource.php +++ b/src/Tracing/TransactionSource.php @@ -9,7 +9,7 @@ * * @see https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations */ -final class TransactionSource implements \Stringable +final class TransactionSource { /** * @var string The value of the enum instance diff --git a/src/Transport/ResultStatus.php b/src/Transport/ResultStatus.php index 130bc56a5..605b3b689 100644 --- a/src/Transport/ResultStatus.php +++ b/src/Transport/ResultStatus.php @@ -8,7 +8,7 @@ * This enum represents all possible reasons an event sending operation succeeded * or failed. */ -class ResultStatus implements \Stringable +class ResultStatus { /** * @var string The value of the enum instance diff --git a/src/UserDataBag.php b/src/UserDataBag.php index dcc374f1f..6ceb017f5 100644 --- a/src/UserDataBag.php +++ b/src/UserDataBag.php @@ -133,7 +133,7 @@ public function getId() public function setId($id): self { if ($id !== null && !\is_string($id) && !\is_int($id)) { - throw new \UnexpectedValueException(\sprintf('Expected an integer or string value for the $id argument. Got: "%s".', get_debug_type($id))); + throw new \UnexpectedValueException(\sprintf('Expected an integer or string value for the $id argument. Got: "%s".', gettype($id))); } $this->id = $id; diff --git a/tests/Integration/IntegrationRegistryTest.php b/tests/Integration/IntegrationRegistryTest.php index 43caf2872..2ea0dccc7 100644 --- a/tests/Integration/IntegrationRegistryTest.php +++ b/tests/Integration/IntegrationRegistryTest.php @@ -252,12 +252,12 @@ public static function setupIntegrationsThrowsExceptionIfValueReturnedFromOption { yield [ 12.34, - 'Expected the callback set for the "integrations" option to return a list of integrations. Got: "float".', + 'Expected the callback set for the "integrations" option to return a list of integrations. Got: "double".', ]; yield [ new \stdClass(), - 'Expected the callback set for the "integrations" option to return a list of integrations. Got: "stdClass".', + 'Expected the callback set for the "integrations" option to return a list of integrations. Got: "object".', ]; } diff --git a/tests/Logs/LogsAggregatorTest.php b/tests/Logs/LogsAggregatorTest.php index 377b9deff..c7a7ca5f1 100644 --- a/tests/Logs/LogsAggregatorTest.php +++ b/tests/Logs/LogsAggregatorTest.php @@ -52,7 +52,7 @@ public function testAttributes(array $attributes, array $expected): void $log->attributes()->toSimpleArray(), static function (string $key) { // We are not testing internal Sentry attributes here, only the ones the user supplied - return !str_starts_with($key, 'sentry.'); + return strpos($key, 'sentry.') !== 0; }, \ARRAY_FILTER_USE_KEY ) diff --git a/tests/Monolog/LogsHandlerTest.php b/tests/Monolog/LogsHandlerTest.php index 20d69ec9a..3aafdf07c 100644 --- a/tests/Monolog/LogsHandlerTest.php +++ b/tests/Monolog/LogsHandlerTest.php @@ -56,7 +56,7 @@ public function testHandle($record, Log $expectedLog): void $log->attributes()->toSimpleArray(), static function (string $key) { // We are not testing Sentry's own attributes here, only the ones the user supplied so filter them out of the expected attributes - return !str_starts_with($key, 'sentry.'); + return strpos($key, 'sentry.') !== 0; }, \ARRAY_FILTER_USE_KEY ) diff --git a/tests/StacktraceTest.php b/tests/StacktraceTest.php index be0ae1ee0..5747d0af0 100644 --- a/tests/StacktraceTest.php +++ b/tests/StacktraceTest.php @@ -39,18 +39,18 @@ public static function constructorThrowsIfFramesListContainsUnexpectedValueDataP new Frame(__FUNCTION__, __FILE__, __LINE__), 10, ], - '/^Expected an instance of the "Sentry\\\\Frame" class\. Got: "int"\.$/', + '/^Expected an instance of the "Sentry\\\\Frame" class\. Got: "integer"\.$/', ]; yield [ [(object) []], - '/^Expected an instance of the "Sentry\\\\Frame" class\. Got: "stdClass"\.$/', + '/^Expected an instance of the "Sentry\\\\Frame" class\. Got: "object"\.$/', ]; yield [ [new class { }], - '/^Expected an instance of the "Sentry\\\\Frame" class\. Got: "class@anonymous.*"\.$/', + '/^Expected an instance of the "Sentry\\\\Frame" class\. Got: "object"\.$/', ]; } diff --git a/tests/UserDataBagTest.php b/tests/UserDataBagTest.php index 8fd8fb0c0..af198cfd7 100644 --- a/tests/UserDataBagTest.php +++ b/tests/UserDataBagTest.php @@ -153,12 +153,12 @@ public static function unexpectedValueForIdFieldDataProvider(): iterable { yield [ 12.34, - 'Expected an integer or string value for the $id argument. Got: "float".', + 'Expected an integer or string value for the $id argument. Got: "double".', ]; yield [ new \stdClass(), - 'Expected an integer or string value for the $id argument. Got: "stdClass".', + 'Expected an integer or string value for the $id argument. Got: "object".', ]; } From 1d57f950c38d88456aaf85db022c350e2af99c00 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Wed, 24 Sep 2025 09:14:00 +0200 Subject: [PATCH 2/4] cs fix --- src/Event.php | 2 +- src/EventHint.php | 2 +- src/Integration/IntegrationRegistry.php | 2 +- src/Stacktrace.php | 2 +- src/State/Scope.php | 2 +- src/UserDataBag.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Event.php b/src/Event.php index bfdf12fb9..9ea324d5a 100644 --- a/src/Event.php +++ b/src/Event.php @@ -842,7 +842,7 @@ public function setExceptions(array $exceptions): self { foreach ($exceptions as $exception) { if (!$exception instanceof ExceptionDataBag) { - throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', ExceptionDataBag::class, gettype($exception))); + throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', ExceptionDataBag::class, \gettype($exception))); } } diff --git a/src/EventHint.php b/src/EventHint.php index 95dd66e0f..773798a9a 100644 --- a/src/EventHint.php +++ b/src/EventHint.php @@ -68,7 +68,7 @@ public static function fromArray(array $hintData): self } if (!\is_array($extra)) { - throw new \InvalidArgumentException(\sprintf('The value of the "extra" field must be an array. Got: "%s".', gettype($extra))); + throw new \InvalidArgumentException(\sprintf('The value of the "extra" field must be an array. Got: "%s".', \gettype($extra))); } $hint->exception = $exception; diff --git a/src/Integration/IntegrationRegistry.php b/src/Integration/IntegrationRegistry.php index e2f932881..28e152fa4 100644 --- a/src/Integration/IntegrationRegistry.php +++ b/src/Integration/IntegrationRegistry.php @@ -123,7 +123,7 @@ private function getIntegrationsToSetup(Options $options): array $integrations = $userIntegrations($defaultIntegrations); if (!\is_array($integrations)) { - throw new \UnexpectedValueException(\sprintf('Expected the callback set for the "integrations" option to return a list of integrations. Got: "%s".', gettype($integrations))); + throw new \UnexpectedValueException(\sprintf('Expected the callback set for the "integrations" option to return a list of integrations. Got: "%s".', \gettype($integrations))); } } diff --git a/src/Stacktrace.php b/src/Stacktrace.php index aae40ab5b..6f6fa95f3 100644 --- a/src/Stacktrace.php +++ b/src/Stacktrace.php @@ -31,7 +31,7 @@ public function __construct(array $frames) foreach ($frames as $frame) { if (!$frame instanceof Frame) { - throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', Frame::class, gettype($frame))); + throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', Frame::class, \gettype($frame))); } } diff --git a/src/State/Scope.php b/src/State/Scope.php index 8b02bed44..ed80d55c9 100644 --- a/src/State/Scope.php +++ b/src/State/Scope.php @@ -208,7 +208,7 @@ public function getUser(): ?UserDataBag public function setUser($user): self { if (!\is_array($user) && !$user instanceof UserDataBag) { - throw new \TypeError(\sprintf('The $user argument must be either an array or an instance of the "%s" class. Got: "%s".', UserDataBag::class, gettype($user))); + throw new \TypeError(\sprintf('The $user argument must be either an array or an instance of the "%s" class. Got: "%s".', UserDataBag::class, \gettype($user))); } if (\is_array($user)) { diff --git a/src/UserDataBag.php b/src/UserDataBag.php index 6ceb017f5..0beb9746e 100644 --- a/src/UserDataBag.php +++ b/src/UserDataBag.php @@ -133,7 +133,7 @@ public function getId() public function setId($id): self { if ($id !== null && !\is_string($id) && !\is_int($id)) { - throw new \UnexpectedValueException(\sprintf('Expected an integer or string value for the $id argument. Got: "%s".', gettype($id))); + throw new \UnexpectedValueException(\sprintf('Expected an integer or string value for the $id argument. Got: "%s".', \gettype($id))); } $this->id = $id; From 3fd9c6f9fe56bbf53c5a54c300b61c0bd32cf6e9 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Wed, 24 Sep 2025 11:43:20 +0200 Subject: [PATCH 3/4] add vendored polyfill --- src/Event.php | 3 +- src/EventHint.php | 10 +-- src/Integration/IntegrationRegistry.php | 3 +- src/Stacktrace.php | 4 +- src/State/Scope.php | 3 +- src/UserDataBag.php | 4 +- src/Util/DebugType.php | 72 +++++++++++++++++++ tests/Integration/IntegrationRegistryTest.php | 4 +- tests/StacktraceTest.php | 6 +- tests/UserDataBagTest.php | 4 +- 10 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 src/Util/DebugType.php diff --git a/src/Event.php b/src/Event.php index f2eda7d90..ad5d9e538 100644 --- a/src/Event.php +++ b/src/Event.php @@ -9,6 +9,7 @@ use Sentry\Logs\Log; use Sentry\Profiling\Profile; use Sentry\Tracing\Span; +use Sentry\Util\DebugType; /** * This is the base class for classes containing event data. @@ -802,7 +803,7 @@ public function setExceptions(array $exceptions): self { foreach ($exceptions as $exception) { if (!$exception instanceof ExceptionDataBag) { - throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', ExceptionDataBag::class, \gettype($exception))); + throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', ExceptionDataBag::class, DebugType::getDebugType($exception))); } } diff --git a/src/EventHint.php b/src/EventHint.php index 773798a9a..3fa868c3e 100644 --- a/src/EventHint.php +++ b/src/EventHint.php @@ -4,6 +4,8 @@ namespace Sentry; +use Sentry\Util\DebugType; + /** * This class represents hints on how to process an event. */ @@ -56,19 +58,19 @@ public static function fromArray(array $hintData): self $extra = $hintData['extra'] ?? []; if ($exception !== null && !$exception instanceof \Throwable) { - throw new \InvalidArgumentException(\sprintf('The value of the "exception" field must be an instance of a class implementing the "%s" interface. Got: "%s".', \Throwable::class, \gettype($exception))); + throw new \InvalidArgumentException(\sprintf('The value of the "exception" field must be an instance of a class implementing the "%s" interface. Got: "%s".', \Throwable::class, DebugType::getDebugType($exception))); } if ($mechanism !== null && !$mechanism instanceof ExceptionMechanism) { - throw new \InvalidArgumentException(\sprintf('The value of the "mechanism" field must be an instance of the "%s" class. Got: "%s".', ExceptionMechanism::class, \gettype($mechanism))); + throw new \InvalidArgumentException(\sprintf('The value of the "mechanism" field must be an instance of the "%s" class. Got: "%s".', ExceptionMechanism::class, DebugType::getDebugType($mechanism))); } if ($stacktrace !== null && !$stacktrace instanceof Stacktrace) { - throw new \InvalidArgumentException(\sprintf('The value of the "stacktrace" field must be an instance of the "%s" class. Got: "%s".', Stacktrace::class, \gettype($stacktrace))); + throw new \InvalidArgumentException(\sprintf('The value of the "stacktrace" field must be an instance of the "%s" class. Got: "%s".', Stacktrace::class, DebugType::getDebugType($stacktrace))); } if (!\is_array($extra)) { - throw new \InvalidArgumentException(\sprintf('The value of the "extra" field must be an array. Got: "%s".', \gettype($extra))); + throw new \InvalidArgumentException(\sprintf('The value of the "extra" field must be an array. Got: "%s".', DebugType::getDebugType($extra))); } $hint->exception = $exception; diff --git a/src/Integration/IntegrationRegistry.php b/src/Integration/IntegrationRegistry.php index 28e152fa4..0d67f9384 100644 --- a/src/Integration/IntegrationRegistry.php +++ b/src/Integration/IntegrationRegistry.php @@ -6,6 +6,7 @@ use Psr\Log\LoggerInterface; use Sentry\Options; +use Sentry\Util\DebugType; /** * @internal @@ -123,7 +124,7 @@ private function getIntegrationsToSetup(Options $options): array $integrations = $userIntegrations($defaultIntegrations); if (!\is_array($integrations)) { - throw new \UnexpectedValueException(\sprintf('Expected the callback set for the "integrations" option to return a list of integrations. Got: "%s".', \gettype($integrations))); + throw new \UnexpectedValueException(\sprintf('Expected the callback set for the "integrations" option to return a list of integrations. Got: "%s".', DebugType::getDebugType($integrations))); } } diff --git a/src/Stacktrace.php b/src/Stacktrace.php index 6f6fa95f3..8040c2513 100644 --- a/src/Stacktrace.php +++ b/src/Stacktrace.php @@ -4,6 +4,8 @@ namespace Sentry; +use Sentry\Util\DebugType; + /** * This class contains all the information about an error stacktrace. * @@ -31,7 +33,7 @@ public function __construct(array $frames) foreach ($frames as $frame) { if (!$frame instanceof Frame) { - throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', Frame::class, \gettype($frame))); + throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', Frame::class, DebugType::getDebugType($frame))); } } diff --git a/src/State/Scope.php b/src/State/Scope.php index ed80d55c9..faa1ce163 100644 --- a/src/State/Scope.php +++ b/src/State/Scope.php @@ -14,6 +14,7 @@ use Sentry\Tracing\Span; use Sentry\Tracing\Transaction; use Sentry\UserDataBag; +use Sentry\Util\DebugType; /** * The scope holds data that should implicitly be sent with Sentry events. It @@ -208,7 +209,7 @@ public function getUser(): ?UserDataBag public function setUser($user): self { if (!\is_array($user) && !$user instanceof UserDataBag) { - throw new \TypeError(\sprintf('The $user argument must be either an array or an instance of the "%s" class. Got: "%s".', UserDataBag::class, \gettype($user))); + throw new \TypeError(\sprintf('The $user argument must be either an array or an instance of the "%s" class. Got: "%s".', UserDataBag::class, DebugType::getDebugType($user))); } if (\is_array($user)) { diff --git a/src/UserDataBag.php b/src/UserDataBag.php index 46546e125..922b52c7f 100644 --- a/src/UserDataBag.php +++ b/src/UserDataBag.php @@ -4,6 +4,8 @@ namespace Sentry; +use Sentry\Util\DebugType; + /** * This class stores the information about the authenticated user for a request. * @@ -123,7 +125,7 @@ public function getId() public function setId($id): self { if ($id !== null && !\is_string($id) && !\is_int($id)) { - throw new \UnexpectedValueException(\sprintf('Expected an integer or string value for the $id argument. Got: "%s".', \gettype($id))); + throw new \UnexpectedValueException(\sprintf('Expected an integer or string value for the $id argument. Got: "%s".', DebugType::getDebugType($id))); } $this->id = $id; diff --git a/src/Util/DebugType.php b/src/Util/DebugType.php new file mode 100644 index 000000000..603a87929 --- /dev/null +++ b/src/Util/DebugType.php @@ -0,0 +1,72 @@ + Date: Wed, 24 Sep 2025 12:05:04 +0200 Subject: [PATCH 4/4] lints and ref --- phpstan-baseline.neon | 3 +++ psalm.xml.dist | 1 + src/Util/DebugType.php | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5b0382806..e2efa67d3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,8 @@ parameters: ignoreErrors: + - + message: "#.*#" + path: src/Util/DebugType.php - message: "#^Method Sentry\\\\Client\\:\\:getIntegration\\(\\) should return \\(T of Sentry\\\\Integration\\\\IntegrationInterface\\)\\|null but returns \\(T of Sentry\\\\Integration\\\\IntegrationInterface\\)\\|null\\.$#" count: 1 diff --git a/psalm.xml.dist b/psalm.xml.dist index ea60216a6..dc733ed56 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -10,6 +10,7 @@ + diff --git a/src/Util/DebugType.php b/src/Util/DebugType.php index 603a87929..42e1ad0ea 100644 --- a/src/Util/DebugType.php +++ b/src/Util/DebugType.php @@ -1,6 +1,8 @@