From ca7ee33eb4b2bc1c4d37c778d4d0cbfadd1ab550 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 16 Aug 2026 19:55:01 -0400 Subject: [PATCH] refactor(admin_audit): improve audit parameter handling refactor(admin_audit): improve audit parameter handling refactor(admin_audit): improve audit parameter handling - clarify missing-parameter validation and logging; - support DateTimeInterface values; - simplify the vsprintf invocation. Signed-off-by: Josh --- apps/admin_audit/lib/Actions/Action.php | 34 ++++++++++--------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/apps/admin_audit/lib/Actions/Action.php b/apps/admin_audit/lib/Actions/Action.php index 31464a2c1a3..280de21a473 100644 --- a/apps/admin_audit/lib/Actions/Action.php +++ b/apps/admin_audit/lib/Actions/Action.php @@ -33,37 +33,31 @@ class Action { ): void { foreach ($elements as $element) { if (!array_key_exists($element, $params)) { - if ($obfuscateParameters) { - $this->logger->critical( - '$params["' . $element . '"] was missing.', - ['app' => 'admin_audit'] - ); - } else { - $this->logger->critical( - '$params["' . $element . '"] was missing. Transferred value: {params}', - ['app' => 'admin_audit', 'params' => $params] - ); + $message = '$params["' . $element . '"] was missing.'; + $context = ['app' => 'admin_audit']; + + if (!$obfuscateParameters) { + $message .= ' Transferred value: {params}'; + $context['params'] = $params; } + + $this->logger->critical($message, $context); return; } } $replaceArray = []; foreach ($elements as $element) { - if ($params[$element] instanceof \DateTime) { - $params[$element] = $params[$element]->format('Y-m-d H:i:s'); + $value = $params[$element]; + if ($value instanceof \DateTimeInterface) { + $value = $value->format('Y-m-d H:i:s'); } - $replaceArray[] = $params[$element]; + $replaceArray[] = $value; } $this->logger->info( - vsprintf( - $text, - $replaceArray - ), - [ - 'app' => 'admin_audit' - ] + vsprintf($text, $replaceArray), + ['app' => 'admin_audit'], ); } }