diff --git a/src/Client.php b/src/Client.php index b9506cafd..cc0bc7eb1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -188,7 +188,7 @@ public function captureEvent(Event $event, ?EventHint $hint = null, ?Scope $scop } } catch (\Throwable $exception) { $this->logger->error( - sprintf('Failed to send the event to Sentry. Reason: "%s".', $exception->getMessage()), + \sprintf('Failed to send the event to Sentry. Reason: "%s".', $exception->getMessage()), ['exception' => $exception, 'event' => $event] ); } @@ -294,7 +294,7 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco $event->setEnvironment($this->options->getEnvironment() ?? Event::DEFAULT_ENVIRONMENT); } - $eventDescription = sprintf( + $eventDescription = \sprintf( '%s%s [%s]', $event->getLevel() !== null ? $event->getLevel() . ' ' : '', (string) $event->getType(), @@ -306,7 +306,7 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco // only sample with the `sample_rate` on errors/messages if ($isEvent && $sampleRate < 1 && mt_rand(1, 100) / 100.0 > $sampleRate) { - $this->logger->info(sprintf('The %s will be discarded because it has been sampled.', $eventDescription), ['event' => $event]); + $this->logger->info(\sprintf('The %s will be discarded because it has been sampled.', $eventDescription), ['event' => $event]); return null; } @@ -323,7 +323,7 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco if ($event === null) { $this->logger->info( - sprintf('The %s will be discarded because one of the event processors returned "null".', $eventDescription), + \sprintf('The %s will be discarded because one of the event processors returned "null".', $eventDescription), ['event' => $beforeEventProcessors] ); @@ -336,7 +336,7 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco if ($event === null) { $this->logger->info( - sprintf( + \sprintf( 'The %s will be discarded because the "%s" callback returned "null".', $eventDescription, $this->getBeforeSendCallbackName($beforeSendCallback) @@ -371,7 +371,7 @@ private function applyIgnoreOptions(Event $event, string $eventDescription): ?Ev foreach ($exceptions as $exception) { if ($this->isIgnoredException($exception->getType())) { $this->logger->info( - sprintf('The %s will be discarded because it matches an entry in "ignore_exceptions".', $eventDescription), + \sprintf('The %s will be discarded because it matches an entry in "ignore_exceptions".', $eventDescription), ['event' => $event] ); @@ -389,7 +389,7 @@ private function applyIgnoreOptions(Event $event, string $eventDescription): ?Ev if (\in_array($transactionName, $this->options->getIgnoreTransactions(), true)) { $this->logger->info( - sprintf('The %s will be discarded because it matches a entry in "ignore_transactions".', $eventDescription), + \sprintf('The %s will be discarded because it matches a entry in "ignore_transactions".', $eventDescription), ['event' => $event] ); diff --git a/src/Dsn.php b/src/Dsn.php index 071a6292f..37aaca162 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -72,17 +72,17 @@ public static function createFromString(string $value): self $parsedDsn = parse_url($value); if ($parsedDsn === false) { - throw new \InvalidArgumentException(sprintf('The "%s" DSN is invalid.', $value)); + throw new \InvalidArgumentException(\sprintf('The "%s" DSN is invalid.', $value)); } foreach (['scheme', 'host', 'path', 'user'] as $component) { if (!isset($parsedDsn[$component]) || (isset($parsedDsn[$component]) && empty($parsedDsn[$component]))) { - throw new \InvalidArgumentException(sprintf('The "%s" DSN must contain a scheme, a host, a user and a path component.', $value)); + throw new \InvalidArgumentException(\sprintf('The "%s" DSN must contain a scheme, a host, a user and a path component.', $value)); } } if (!\in_array($parsedDsn['scheme'], ['http', 'https'], true)) { - throw new \InvalidArgumentException(sprintf('The scheme of the "%s" DSN must be either "http" or "https".', $value)); + throw new \InvalidArgumentException(\sprintf('The scheme of the "%s" DSN must be either "http" or "https".', $value)); } $segmentPaths = explode('/', $parsedDsn['path']); diff --git a/src/Event.php b/src/Event.php index aded2808b..8b096d3cd 100644 --- a/src/Event.php +++ b/src/Event.php @@ -777,7 +777,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, get_debug_type($exception))); } } diff --git a/src/EventHint.php b/src/EventHint.php index ceff03315..58b6ffc57 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, get_debug_type($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, get_debug_type($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, get_debug_type($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".', get_debug_type($extra))); } $hint->exception = $exception; diff --git a/src/FrameBuilder.php b/src/FrameBuilder.php index 143252d57..46aa3461d 100644 --- a/src/FrameBuilder.php +++ b/src/FrameBuilder.php @@ -78,8 +78,8 @@ public function buildFromBacktraceFrame(string $file, int $line, array $backtrac $functionName = Frame::ANONYMOUS_CLASS_PREFIX . $this->stripPrefixFromFilePath($this->options, substr($backtraceFrame['class'], \strlen(Frame::ANONYMOUS_CLASS_PREFIX))); } - $rawFunctionName = sprintf('%s::%s', $backtraceFrame['class'], $backtraceFrame['function']); - $functionName = sprintf('%s::%s', preg_replace('/(?::\d+\$|0x)[a-fA-F0-9]+$/', '', $functionName), $backtraceFrame['function']); + $rawFunctionName = \sprintf('%s::%s', $backtraceFrame['class'], $backtraceFrame['function']); + $functionName = \sprintf('%s::%s', preg_replace('/(?::\d+\$|0x)[a-fA-F0-9]+$/', '', $functionName), $backtraceFrame['function']); } elseif (isset($backtraceFrame['function'])) { $functionName = $backtraceFrame['function']; } diff --git a/src/Integration/FrameContextifierIntegration.php b/src/Integration/FrameContextifierIntegration.php index 9b1a7b3b6..8935d055d 100644 --- a/src/Integration/FrameContextifierIntegration.php +++ b/src/Integration/FrameContextifierIntegration.php @@ -165,7 +165,7 @@ private function getSourceCodeExcerpt(int $maxContextLines, string $filePath, in } } catch (\Throwable $exception) { $this->logger->warning( - sprintf('Failed to get the source code excerpt for the file "%s".', $filePath), + \sprintf('Failed to get the source code excerpt for the file "%s".', $filePath), ['exception' => $exception] ); } diff --git a/src/Integration/IntegrationRegistry.php b/src/Integration/IntegrationRegistry.php index 12c91911f..be2df22eb 100644 --- a/src/Integration/IntegrationRegistry.php +++ b/src/Integration/IntegrationRegistry.php @@ -64,7 +64,7 @@ public function setupIntegrations(Options $options, LoggerInterface $logger): ar } if (\count($installed) > 0) { - $logger->debug(sprintf('The "%s" integration(s) have been installed.', implode(', ', $installed))); + $logger->debug(\sprintf('The "%s" integration(s) have been installed.', implode(', ', $installed))); } return $integrations; @@ -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".', get_debug_type($integrations))); } } diff --git a/src/Integration/RequestIntegration.php b/src/Integration/RequestIntegration.php index d4ab50ce1..72e17ac77 100644 --- a/src/Integration/RequestIntegration.php +++ b/src/Integration/RequestIntegration.php @@ -267,7 +267,7 @@ private function parseUploadedFiles(array $uploadedFiles): array } elseif (\is_array($item)) { $result[$key] = $this->parseUploadedFiles($item); } else { - throw new \UnexpectedValueException(sprintf('Expected either an object implementing the "%s" interface or an array. Got: "%s".', UploadedFileInterface::class, \is_object($item) ? \get_class($item) : \gettype($item))); + throw new \UnexpectedValueException(\sprintf('Expected either an object implementing the "%s" interface or an array. Got: "%s".', UploadedFileInterface::class, \is_object($item) ? \get_class($item) : \gettype($item))); } } diff --git a/src/Logger/DebugFileLogger.php b/src/Logger/DebugFileLogger.php index 610182f87..abee3948d 100644 --- a/src/Logger/DebugFileLogger.php +++ b/src/Logger/DebugFileLogger.php @@ -24,6 +24,6 @@ public function __construct(string $filePath) */ public function log($level, $message, array $context = []): void { - file_put_contents($this->filePath, sprintf("sentry/sentry: [%s] %s\n", $level, (string) $message), \FILE_APPEND); + file_put_contents($this->filePath, \sprintf("sentry/sentry: [%s] %s\n", $level, (string) $message), \FILE_APPEND); } } diff --git a/src/Logger/DebugStdOutLogger.php b/src/Logger/DebugStdOutLogger.php index eaaba6a10..d83ee31ca 100644 --- a/src/Logger/DebugStdOutLogger.php +++ b/src/Logger/DebugStdOutLogger.php @@ -14,6 +14,6 @@ class DebugStdOutLogger extends AbstractLogger */ public function log($level, $message, array $context = []): void { - file_put_contents('php://stdout', sprintf("sentry/sentry: [%s] %s\n", $level, (string) $message)); + file_put_contents('php://stdout', \sprintf("sentry/sentry: [%s] %s\n", $level, (string) $message)); } } diff --git a/src/Metrics/Types/AbstractType.php b/src/Metrics/Types/AbstractType.php index 1b80bb6c3..ecafca06d 100644 --- a/src/Metrics/Types/AbstractType.php +++ b/src/Metrics/Types/AbstractType.php @@ -119,7 +119,7 @@ public function addCodeLocation(int $stackLevel): void public function getMri(): string { - return sprintf( + return \sprintf( '%s:%s@%s', $this->getType(), $this->getKey(), diff --git a/src/Monolog/Handler.php b/src/Monolog/Handler.php index ddce8f243..3e8d52bba 100644 --- a/src/Monolog/Handler.php +++ b/src/Monolog/Handler.php @@ -55,7 +55,7 @@ protected function doWrite($record): void $event = Event::createEvent(); $event->setLevel(self::getSeverityFromLevel($record['level'])); $event->setMessage($record['message']); - $event->setLogger(sprintf('monolog.%s', $record['channel'])); + $event->setLogger(\sprintf('monolog.%s', $record['channel'])); $hint = new EventHint(); diff --git a/src/Profiling/Profile.php b/src/Profiling/Profile.php index 06d895558..3e88e9cf2 100644 --- a/src/Profiling/Profile.php +++ b/src/Profiling/Profile.php @@ -254,14 +254,14 @@ public function getFormattedData(Event $event): ?array } if (!$this->validateMaxDuration((float) $duration)) { - $this->logger->warning(sprintf('The profile is %ss which is longer than the allowed %ss, the profile will be discarded.', (float) $duration, self::MAX_PROFILE_DURATION)); + $this->logger->warning(\sprintf('The profile is %ss which is longer than the allowed %ss, the profile will be discarded.', (float) $duration, self::MAX_PROFILE_DURATION)); return null; } $startTime = \DateTime::createFromFormat('U.u', number_format($this->startTimeStamp, 4, '.', ''), new \DateTimeZone('UTC')); if ($startTime === false) { - $this->logger->warning(sprintf('The start time (%s) of the profile is not valid, the profile will be discarded.', $this->startTimeStamp)); + $this->logger->warning(\sprintf('The start time (%s) of the profile is not valid, the profile will be discarded.', $this->startTimeStamp)); return null; } diff --git a/src/Profiling/Profiler.php b/src/Profiling/Profiler.php index 7f4eb37c7..f379b53b2 100644 --- a/src/Profiling/Profiler.php +++ b/src/Profiling/Profiler.php @@ -82,7 +82,7 @@ private function initProfiler(): void $this->profiler = new \ExcimerProfiler(); $this->profile->setStartTimeStamp(microtime(true)); - $this->profiler->setEventType(EXCIMER_REAL); + $this->profiler->setEventType(\EXCIMER_REAL); $this->profiler->setPeriod(self::SAMPLE_RATE); $this->profiler->setMaxDepth(self::MAX_STACK_DEPTH); } diff --git a/src/Serializer/AbstractSerializer.php b/src/Serializer/AbstractSerializer.php index 766175a9e..07bc36118 100644 --- a/src/Serializer/AbstractSerializer.php +++ b/src/Serializer/AbstractSerializer.php @@ -285,7 +285,7 @@ protected function serializeCallable($callable): string } if (!\is_callable($callable)) { - throw new \InvalidArgumentException(sprintf('Expecting callable, got %s', \is_object($callable) ? \get_class($callable) : \gettype($callable))); + throw new \InvalidArgumentException(\sprintf('Expecting callable, got %s', \is_object($callable) ? \get_class($callable) : \gettype($callable))); } try { diff --git a/src/Serializer/EnvelopItems/CheckInItem.php b/src/Serializer/EnvelopItems/CheckInItem.php index e3e2778bf..c996db4c3 100644 --- a/src/Serializer/EnvelopItems/CheckInItem.php +++ b/src/Serializer/EnvelopItems/CheckInItem.php @@ -41,6 +41,6 @@ public static function toEnvelopeItem(Event $event): string } } - return sprintf("%s\n%s", JSON::encode($header), JSON::encode($payload)); + return \sprintf("%s\n%s", JSON::encode($header), JSON::encode($payload)); } } diff --git a/src/Serializer/EnvelopItems/EventItem.php b/src/Serializer/EnvelopItems/EventItem.php index 9b0eb50fe..dd37f70ff 100644 --- a/src/Serializer/EnvelopItems/EventItem.php +++ b/src/Serializer/EnvelopItems/EventItem.php @@ -144,7 +144,7 @@ public static function toEnvelopeItem(Event $event): string ]; } - return sprintf("%s\n%s", JSON::encode($header), JSON::encode($payload)); + return \sprintf("%s\n%s", JSON::encode($header), JSON::encode($payload)); } /** diff --git a/src/Serializer/EnvelopItems/MetricsItem.php b/src/Serializer/EnvelopItems/MetricsItem.php index 7109f09b7..8b78ccec2 100644 --- a/src/Serializer/EnvelopItems/MetricsItem.php +++ b/src/Serializer/EnvelopItems/MetricsItem.php @@ -71,7 +71,7 @@ public static function toEnvelopeItem(Event $event): string 'length' => mb_strlen($metricMetaPayload), ]; - return sprintf( + return \sprintf( "%s\n%s\n%s\n%s", JSON::encode($statsdHeader), $statsdPayload, @@ -80,7 +80,7 @@ public static function toEnvelopeItem(Event $event): string ); } - return sprintf( + return \sprintf( "%s\n%s", JSON::encode($statsdHeader), $statsdPayload diff --git a/src/Serializer/EnvelopItems/ProfileItem.php b/src/Serializer/EnvelopItems/ProfileItem.php index 90fdca9ec..646506478 100644 --- a/src/Serializer/EnvelopItems/ProfileItem.php +++ b/src/Serializer/EnvelopItems/ProfileItem.php @@ -30,6 +30,6 @@ public static function toEnvelopeItem(Event $event): string return ''; } - return sprintf("%s\n%s", JSON::encode($header), JSON::encode($payload)); + return \sprintf("%s\n%s", JSON::encode($header), JSON::encode($payload)); } } diff --git a/src/Serializer/EnvelopItems/TransactionItem.php b/src/Serializer/EnvelopItems/TransactionItem.php index 91520922d..99ffbc2ae 100644 --- a/src/Serializer/EnvelopItems/TransactionItem.php +++ b/src/Serializer/EnvelopItems/TransactionItem.php @@ -134,7 +134,7 @@ public static function toEnvelopeItem(Event $event): string $payload['transaction_info']['source'] = (string) $transactionMetadata->getSource(); } - return sprintf("%s\n%s", JSON::encode($header), JSON::encode($payload)); + return \sprintf("%s\n%s", JSON::encode($header), JSON::encode($payload)); } /** diff --git a/src/Serializer/PayloadSerializer.php b/src/Serializer/PayloadSerializer.php index e531a9a0e..7dbfd2aa9 100644 --- a/src/Serializer/PayloadSerializer.php +++ b/src/Serializer/PayloadSerializer.php @@ -69,7 +69,7 @@ public function serialize(Event $event): string if ($event->getSdkMetadata('profile') !== null) { $profileItem = ProfileItem::toEnvelopeItem($event); if ($profileItem !== '') { - $items = sprintf("%s\n%s", $transactionItem, $profileItem); + $items = \sprintf("%s\n%s", $transactionItem, $profileItem); break; } } @@ -83,6 +83,6 @@ public function serialize(Event $event): string break; } - return sprintf("%s\n%s", JSON::encode($envelopeHeader), $items); + return \sprintf("%s\n%s", JSON::encode($envelopeHeader), $items); } } diff --git a/src/Severity.php b/src/Severity.php index 8fdf161b3..d0fa899d0 100644 --- a/src/Severity.php +++ b/src/Severity.php @@ -73,7 +73,7 @@ final class Severity implements \Stringable public function __construct(string $value = self::INFO) { if (!\in_array($value, self::ALLOWED_SEVERITIES, true)) { - throw new \InvalidArgumentException(sprintf('The "%s" is not a valid enum value.', $value)); + throw new \InvalidArgumentException(\sprintf('The "%s" is not a valid enum value.', $value)); } $this->value = $value; diff --git a/src/Stacktrace.php b/src/Stacktrace.php index 52633602c..f75d73269 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, get_debug_type($frame))); } } @@ -86,7 +86,7 @@ public function addFrame(Frame $frame): self public function removeFrame(int $index): self { if (!isset($this->frames[$index])) { - throw new \OutOfBoundsException(sprintf('Cannot remove the frame at index %d.', $index)); + throw new \OutOfBoundsException(\sprintf('Cannot remove the frame at index %d.', $index)); } if (\count($this->frames) === 1) { diff --git a/src/State/Hub.php b/src/State/Hub.php index a1c01a5e2..4fa9a4382 100644 --- a/src/State/Hub.php +++ b/src/State/Hub.php @@ -260,7 +260,7 @@ public function startTransaction(TransactionContext $context, array $customSampl if ($options === null || !$options->isTracingEnabled()) { $transaction->setSampled(false); - $logger->warning(sprintf('Transaction [%s] was started but tracing is not enabled.', (string) $transaction->getTraceId()), ['context' => $context]); + $logger->warning(\sprintf('Transaction [%s] was started but tracing is not enabled.', (string) $transaction->getTraceId()), ['context' => $context]); return $transaction; } @@ -289,7 +289,7 @@ public function startTransaction(TransactionContext $context, array $customSampl if (!$this->isValidSampleRate($sampleRate)) { $transaction->setSampled(false); - $logger->warning(sprintf('Transaction [%s] was started but not sampled because sample rate (decided by %s) is invalid.', (string) $transaction->getTraceId(), $sampleSource), ['context' => $context]); + $logger->warning(\sprintf('Transaction [%s] was started but not sampled because sample rate (decided by %s) is invalid.', (string) $transaction->getTraceId(), $sampleSource), ['context' => $context]); return $transaction; } @@ -299,7 +299,7 @@ public function startTransaction(TransactionContext $context, array $customSampl if ($sampleRate === 0.0) { $transaction->setSampled(false); - $logger->info(sprintf('Transaction [%s] was started but not sampled because sample rate (decided by %s) is %s.', (string) $transaction->getTraceId(), $sampleSource, $sampleRate), ['context' => $context]); + $logger->info(\sprintf('Transaction [%s] was started but not sampled because sample rate (decided by %s) is %s.', (string) $transaction->getTraceId(), $sampleSource, $sampleRate), ['context' => $context]); return $transaction; } @@ -308,24 +308,24 @@ public function startTransaction(TransactionContext $context, array $customSampl } if (!$transaction->getSampled()) { - $logger->info(sprintf('Transaction [%s] was started but not sampled, decided by %s.', (string) $transaction->getTraceId(), $sampleSource), ['context' => $context]); + $logger->info(\sprintf('Transaction [%s] was started but not sampled, decided by %s.', (string) $transaction->getTraceId(), $sampleSource), ['context' => $context]); return $transaction; } - $logger->info(sprintf('Transaction [%s] was started and sampled, decided by %s.', (string) $transaction->getTraceId(), $sampleSource), ['context' => $context]); + $logger->info(\sprintf('Transaction [%s] was started and sampled, decided by %s.', (string) $transaction->getTraceId(), $sampleSource), ['context' => $context]); $transaction->initSpanRecorder(); $profilesSampleRate = $options->getProfilesSampleRate(); if ($profilesSampleRate === null) { - $logger->info(sprintf('Transaction [%s] is not profiling because `profiles_sample_rate` option is not set.', (string) $transaction->getTraceId())); + $logger->info(\sprintf('Transaction [%s] is not profiling because `profiles_sample_rate` option is not set.', (string) $transaction->getTraceId())); } elseif ($this->sample($profilesSampleRate)) { - $logger->info(sprintf('Transaction [%s] started profiling because it was sampled.', (string) $transaction->getTraceId())); + $logger->info(\sprintf('Transaction [%s] started profiling because it was sampled.', (string) $transaction->getTraceId())); $transaction->initProfiler()->start(); } else { - $logger->info(sprintf('Transaction [%s] is not profiling because it was not sampled.', (string) $transaction->getTraceId())); + $logger->info(\sprintf('Transaction [%s] is not profiling because it was not sampled.', (string) $transaction->getTraceId())); } return $transaction; diff --git a/src/State/Scope.php b/src/State/Scope.php index 546072f4e..e4e054c3c 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, get_debug_type($user))); } if (\is_array($user)) { @@ -419,7 +419,7 @@ public function applyToEvent(Event $event, ?EventHint $hint = null, ?Options $op } if (!$event instanceof Event) { - throw new \InvalidArgumentException(sprintf('The event processor must return null or an instance of the %s class', Event::class)); + throw new \InvalidArgumentException(\sprintf('The event processor must return null or an instance of the %s class', Event::class)); } } diff --git a/src/Tracing/PropagationContext.php b/src/Tracing/PropagationContext.php index f63dc4285..fce1b2207 100644 --- a/src/Tracing/PropagationContext.php +++ b/src/Tracing/PropagationContext.php @@ -64,7 +64,7 @@ public static function fromEnvironment(string $sentryTrace, string $baggage): se */ public function toTraceparent(): string { - return sprintf('%s-%s', (string) $this->traceId, (string) $this->spanId); + return \sprintf('%s-%s', (string) $this->traceId, (string) $this->spanId); } /** @@ -72,7 +72,7 @@ public function toTraceparent(): string */ public function toW3CTraceparent(): string { - return sprintf('00-%s-%s-00', (string) $this->traceId, (string) $this->spanId); + return \sprintf('00-%s-%s-00', (string) $this->traceId, (string) $this->spanId); } /** diff --git a/src/Tracing/Span.php b/src/Tracing/Span.php index 17d4ea25f..649d8e7cb 100644 --- a/src/Tracing/Span.php +++ b/src/Tracing/Span.php @@ -510,7 +510,7 @@ public function setMetricsSummary( MetricsUnit $unit, array $tags ): void { - $mri = sprintf('%s:%s@%s', $type, $key, (string) $unit); + $mri = \sprintf('%s:%s@%s', $type, $key, (string) $unit); $bucketKey = $mri . serialize($tags); if ( @@ -567,7 +567,7 @@ public function toTraceparent(): string $sampled = $this->sampled ? '-1' : '-0'; } - return sprintf('%s-%s%s', (string) $this->traceId, (string) $this->spanId, $sampled); + return \sprintf('%s-%s%s', (string) $this->traceId, (string) $this->spanId, $sampled); } /** @@ -584,7 +584,7 @@ public function toW3CTraceparent(): string $sampled = '00'; } - return sprintf('00-%s-%s-%s', (string) $this->traceId, (string) $this->spanId, $sampled); + return \sprintf('00-%s-%s-%s', (string) $this->traceId, (string) $this->spanId, $sampled); } /** diff --git a/src/Transport/HttpTransport.php b/src/Transport/HttpTransport.php index 6fab31833..db9ef1046 100644 --- a/src/Transport/HttpTransport.php +++ b/src/Transport/HttpTransport.php @@ -69,7 +69,7 @@ public function send(Event $event): Result { $this->sendRequestToSpotlight($event); - $eventDescription = sprintf( + $eventDescription = \sprintf( '%s%s [%s]', $event->getLevel() !== null ? $event->getLevel() . ' ' : '', (string) $event->getType(), @@ -77,23 +77,23 @@ public function send(Event $event): Result ); if ($this->options->getDsn() === null) { - $this->logger->info(sprintf('Skipping %s, because no DSN is set.', $eventDescription), ['event' => $event]); + $this->logger->info(\sprintf('Skipping %s, because no DSN is set.', $eventDescription), ['event' => $event]); return new Result(ResultStatus::skipped(), $event); } - $targetDescription = sprintf( + $targetDescription = \sprintf( '%s [project:%s]', $this->options->getDsn()->getHost(), $this->options->getDsn()->getProjectId() ); - $this->logger->info(sprintf('Sending %s to %s.', $eventDescription, $targetDescription), ['event' => $event]); + $this->logger->info(\sprintf('Sending %s to %s.', $eventDescription, $targetDescription), ['event' => $event]); $eventType = $event->getType(); if ($this->rateLimiter->isRateLimited($eventType)) { $this->logger->warning( - sprintf('Rate limit exceeded for sending requests of type "%s".', (string) $eventType), + \sprintf('Rate limit exceeded for sending requests of type "%s".', (string) $eventType), ['event' => $event] ); @@ -107,7 +107,7 @@ public function send(Event $event): Result $response = $this->httpClient->sendRequest($request, $this->options); } catch (\Throwable $exception) { $this->logger->error( - sprintf('Failed to send %s to %s. Reason: "%s".', $eventDescription, $targetDescription, $exception->getMessage()), + \sprintf('Failed to send %s to %s. Reason: "%s".', $eventDescription, $targetDescription, $exception->getMessage()), ['exception' => $exception, 'event' => $event] ); @@ -116,7 +116,7 @@ public function send(Event $event): Result if ($response->hasError()) { $this->logger->error( - sprintf('Failed to send %s to %s. Reason: "%s".', $eventDescription, $targetDescription, $response->getError()), + \sprintf('Failed to send %s to %s. Reason: "%s".', $eventDescription, $targetDescription, $response->getError()), ['event' => $event] ); @@ -128,7 +128,7 @@ public function send(Event $event): Result $resultStatus = ResultStatus::createFromHttpStatusCode($response->getStatusCode()); $this->logger->info( - sprintf('Sent %s to %s. Result: "%s" (status: %s).', $eventDescription, $targetDescription, strtolower((string) $resultStatus), $response->getStatusCode()), + \sprintf('Sent %s to %s. Result: "%s" (status: %s).', $eventDescription, $targetDescription, strtolower((string) $resultStatus), $response->getStatusCode()), ['response' => $response, 'event' => $event] ); @@ -168,13 +168,13 @@ private function sendRequestToSpotlight(Event $event): void if ($spotLightResponse->hasError()) { $this->logger->info( - sprintf('Failed to send the event to Spotlight. Reason: "%s".', $spotLightResponse->getError()), + \sprintf('Failed to send the event to Spotlight. Reason: "%s".', $spotLightResponse->getError()), ['event' => $event] ); } } catch (\Throwable $exception) { $this->logger->info( - sprintf('Failed to send the event to Spotlight. Reason: "%s".', $exception->getMessage()), + \sprintf('Failed to send the event to Spotlight. Reason: "%s".', $exception->getMessage()), ['exception' => $exception, 'event' => $event] ); } diff --git a/src/Transport/RateLimiter.php b/src/Transport/RateLimiter.php index dbc8bcf22..6a4f89bf8 100644 --- a/src/Transport/RateLimiter.php +++ b/src/Transport/RateLimiter.php @@ -94,7 +94,7 @@ public function handleResponse(Response $response): bool } $this->logger->warning( - sprintf('Rate limited exceeded for category "%s", backing off until "%s".', $category, gmdate(\DATE_ATOM, $retryAfter)) + \sprintf('Rate limited exceeded for category "%s", backing off until "%s".', $category, gmdate(\DATE_ATOM, $retryAfter)) ); } } @@ -108,7 +108,7 @@ public function handleResponse(Response $response): bool $this->rateLimits['all'] = $retryAfter; $this->logger->warning( - sprintf('Rate limited exceeded for all categories, backing off until "%s".', gmdate(\DATE_ATOM, $retryAfter)) + \sprintf('Rate limited exceeded for all categories, backing off until "%s".', gmdate(\DATE_ATOM, $retryAfter)) ); return true; diff --git a/src/UserDataBag.php b/src/UserDataBag.php index ec536faef..dcc374f1f 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".', get_debug_type($id))); } $this->id = $id; @@ -221,7 +221,7 @@ public function getIpAddress(): ?string public function setIpAddress(?string $ipAddress): self { if ($ipAddress !== null && filter_var($ipAddress, \FILTER_VALIDATE_IP) === false) { - throw new \InvalidArgumentException(sprintf('The "%s" value is not a valid IP address.', $ipAddress)); + throw new \InvalidArgumentException(\sprintf('The "%s" value is not a valid IP address.', $ipAddress)); } $this->ipAddress = $ipAddress; diff --git a/src/Util/JSON.php b/src/Util/JSON.php index 9824cbd74..48b843423 100644 --- a/src/Util/JSON.php +++ b/src/Util/JSON.php @@ -42,7 +42,7 @@ public static function encode($data, int $options = 0, int $maxDepth = 512): str $encounteredAnyError = json_last_error() !== \JSON_ERROR_NONE; if (($encounteredAnyError && ($encodedData === 'null' || $encodedData === false)) || !\in_array(json_last_error(), $allowedErrors, true)) { - throw new JsonException(sprintf('Could not encode value into JSON format. Error was: "%s".', json_last_error_msg())); + throw new JsonException(\sprintf('Could not encode value into JSON format. Error was: "%s".', json_last_error_msg())); } return $encodedData; @@ -62,7 +62,7 @@ public static function decode(string $data) $decodedData = json_decode($data, true); if (json_last_error() !== \JSON_ERROR_NONE) { - throw new JsonException(sprintf('Could not decode value from JSON format. Error was: "%s".', json_last_error_msg())); + throw new JsonException(\sprintf('Could not decode value from JSON format. Error was: "%s".', json_last_error_msg())); } return $decodedData; diff --git a/src/Util/SentryUid.php b/src/Util/SentryUid.php index 7adbc1cca..253952572 100644 --- a/src/Util/SentryUid.php +++ b/src/Util/SentryUid.php @@ -22,7 +22,7 @@ public static function generate(): string $uuid = bin2hex(random_bytes(16)); - return sprintf('%08s%04s4%03s%04x%012s', + return \sprintf('%08s%04s4%03s%04x%012s', // 32 bits for "time_low" substr($uuid, 0, 8), // 16 bits for "time_mid" diff --git a/tests/HttpClient/TestServer.php b/tests/HttpClient/TestServer.php index 901dc26f6..d915187ef 100644 --- a/tests/HttpClient/TestServer.php +++ b/tests/HttpClient/TestServer.php @@ -49,7 +49,7 @@ public function startTestServer(): string $pipes = []; $this->serverProcess = proc_open( - $command = sprintf( + $command = \sprintf( 'php -S localhost:%d -t %s', $this->serverPort, realpath(__DIR__ . '/../testserver') diff --git a/tests/Integration/FrameContextifierIntegrationTest.php b/tests/Integration/FrameContextifierIntegrationTest.php index e4458be4c..5667826b0 100644 --- a/tests/Integration/FrameContextifierIntegrationTest.php +++ b/tests/Integration/FrameContextifierIntegrationTest.php @@ -161,7 +161,7 @@ private function getFixtureFileContent(string $file): string $fileContent = file_get_contents($file); if ($fileContent === false) { - throw new \RuntimeException(sprintf('The fixture file at path "%s" could not be read.', $file)); + throw new \RuntimeException(\sprintf('The fixture file at path "%s" could not be read.', $file)); } return $fileContent; diff --git a/tests/Integration/IntegrationRegistryTest.php b/tests/Integration/IntegrationRegistryTest.php index 63e46b29a..fefa624e7 100644 --- a/tests/Integration/IntegrationRegistryTest.php +++ b/tests/Integration/IntegrationRegistryTest.php @@ -38,7 +38,7 @@ public function testSetupIntegrations(Options $options, array $expectedIntegrati if (\count($expectedIntegrations) > 0) { $logger->expects($this->once()) ->method('debug') - ->with(sprintf('The "%s" integration(s) have been installed.', implode(', ', array_keys($expectedIntegrations))), []); + ->with(\sprintf('The "%s" integration(s) have been installed.', implode(', ', array_keys($expectedIntegrations))), []); } else { $logger->expects($this->never()) ->method('debug');