From 694a14cbc0d51c44e46b85436fc9caf462fb029d Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 29 Sep 2025 16:23:16 +0800 Subject: [PATCH] refactor(sentry): simplify transaction null checks using nullsafe operator Replace explicit null checks with PHP 8's nullsafe operator (?->) for cleaner and more concise transaction validation. This change maintains the same logic while improving code readability by combining null and method call checks in a single expression. Changes: - CoroutineAspect: Simplified transaction check in process method - EventHandleListener: Updated 5 methods to use nullsafe operator for transaction validation --- src/sentry/src/Tracing/Aspect/CoroutineAspect.php | 2 +- .../src/Tracing/Listener/EventHandleListener.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sentry/src/Tracing/Aspect/CoroutineAspect.php b/src/sentry/src/Tracing/Aspect/CoroutineAspect.php index 0b638e2f3..3f1f20c80 100644 --- a/src/sentry/src/Tracing/Aspect/CoroutineAspect.php +++ b/src/sentry/src/Tracing/Aspect/CoroutineAspect.php @@ -61,7 +61,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) $transaction = SentrySdk::getCurrentHub()->getTransaction(); // If there's no active transaction, skip tracing. - if (! $transaction || ! $transaction->getSampled()) { + if (! $transaction?->getSampled()) { return $proceedingJoinPoint->process(); } diff --git a/src/sentry/src/Tracing/Listener/EventHandleListener.php b/src/sentry/src/Tracing/Listener/EventHandleListener.php index 4bea5f9f5..1f56f55cc 100644 --- a/src/sentry/src/Tracing/Listener/EventHandleListener.php +++ b/src/sentry/src/Tracing/Listener/EventHandleListener.php @@ -404,7 +404,7 @@ protected function handleCommandFinished(CommandEvent\AfterExecute $event): void { $transaction = SentrySdk::getCurrentHub()->getTransaction(); - if (! $transaction || ! $transaction->getSampled()) { + if (! $transaction?->getSampled()) { return; } @@ -517,7 +517,7 @@ protected function handleCrontabTaskFinished(CrontabEvent\FailToExecute|CrontabE { $transaction = SentrySdk::getCurrentHub()->getTransaction(); - if (! $transaction || ! $transaction->getSampled()) { + if (! $transaction?->getSampled()) { return; } @@ -585,7 +585,7 @@ protected function handleAmqpMessageProcessed(AmqpEvent\AfterConsume|AmqpEvent\F { $transaction = SentrySdk::getCurrentHub()->getTransaction(); - if (! $transaction || ! $transaction->getSampled()) { + if (! $transaction?->getSampled()) { return; } @@ -653,7 +653,7 @@ protected function handleKafkaMessageProcessed(KafkaEvent\AfterConsume|KafkaEven { $transaction = SentrySdk::getCurrentHub()->getTransaction(); - if (! $transaction || ! $transaction->getSampled()) { + if (! $transaction?->getSampled()) { return; } @@ -704,7 +704,7 @@ protected function handleAsyncQueueJobProcessed(AsyncQueueEvent\AfterHandle|Asyn { $transaction = SentrySdk::getCurrentHub()->getTransaction(); - if (! $transaction || ! $transaction->getSampled()) { + if (! $transaction?->getSampled()) { return; }