From 123996bbc0c4e495042386a89a7d0461f52c2af8 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Tue, 19 May 2026 09:25:01 -0300 Subject: [PATCH] refactor(social): TokenRedactor::redact accepts nullable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lets the call sites drop the explicit null check ternary. The redactor itself owns the null handling — one less conditional at every caller. --- app/Exceptions/Social/SocialPublishException.php | 2 +- app/Services/Social/TokenRedactor.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Exceptions/Social/SocialPublishException.php b/app/Exceptions/Social/SocialPublishException.php index 8d007728..2af28382 100644 --- a/app/Exceptions/Social/SocialPublishException.php +++ b/app/Exceptions/Social/SocialPublishException.php @@ -28,7 +28,7 @@ public function context(): array 'category' => $this->category->value, 'platform_error_code' => $this->platformErrorCode, 'user_message' => $this->userMessage, - 'raw_response' => $this->rawResponse !== null ? TokenRedactor::redact($this->rawResponse) : null, + 'raw_response' => TokenRedactor::redact($this->rawResponse), ]; } diff --git a/app/Services/Social/TokenRedactor.php b/app/Services/Social/TokenRedactor.php index bc154048..8da132e5 100644 --- a/app/Services/Social/TokenRedactor.php +++ b/app/Services/Social/TokenRedactor.php @@ -12,8 +12,12 @@ */ class TokenRedactor { - public static function redact(string $body): string + public static function redact(?string $body): ?string { + if ($body === null) { + return null; + } + return preg_replace( [ '/access_token=([^&"\s]+)/',