From 185266a1f994e76688fb2d3ed568e5c5328d437e Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 9 Feb 2026 11:48:05 -0600 Subject: [PATCH] Refactor: reduce nesting depth in 2 functions Extract nested logic into helper functions to improve readability: - broadcast_task_supervisor.ex: extract broadcast_to_topics/3 helper - log_sanitizer.ex: extract redact_match/1 helper Progress: 2/42 refactoring opportunities fixed --- lib/aprsme/broadcast_task_supervisor.ex | 11 ++++++++--- lib/aprsme/log_sanitizer.ex | 15 +++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/aprsme/broadcast_task_supervisor.ex b/lib/aprsme/broadcast_task_supervisor.ex index 09a4283..0f0f9f2 100644 --- a/lib/aprsme/broadcast_task_supervisor.ex +++ b/lib/aprsme/broadcast_task_supervisor.ex @@ -51,9 +51,7 @@ defmodule Aprsme.BroadcastTaskSupervisor do # Process in chunks to balance load |> Stream.chunk_every(10) |> Enum.each(fn topic_chunk -> - Enum.each(topic_chunk, fn topic -> - Phoenix.PubSub.broadcast(pubsub, topic, message) - end) + broadcast_to_topics(topic_chunk, message, pubsub) end) end) @@ -102,4 +100,11 @@ defmodule Aprsme.BroadcastTaskSupervisor do rescue _ -> 0.0 end + + # Private helper to broadcast to multiple topics + defp broadcast_to_topics(topics, message, pubsub) do + Enum.each(topics, fn topic -> + Phoenix.PubSub.broadcast(pubsub, topic, message) + end) + end end diff --git a/lib/aprsme/log_sanitizer.ex b/lib/aprsme/log_sanitizer.ex index acef9f3..113b78a 100644 --- a/lib/aprsme/log_sanitizer.ex +++ b/lib/aprsme/log_sanitizer.ex @@ -43,17 +43,20 @@ defmodule Aprsme.LogSanitizer do def sanitize_map(data), do: data + # Helper to redact a matched sensitive pattern + defp redact_match(match) do + case String.split(match, ["=", ":"]) do + [key, _value] -> "#{key}=[REDACTED]" + _ -> "[REDACTED]" + end + end + @doc """ Sanitize a string by replacing sensitive patterns """ def sanitize_string(data) when is_binary(data) do Enum.reduce(@sensitive_patterns, data, fn pattern, acc -> - Regex.replace(pattern, acc, fn match -> - case String.split(match, ["=", ":"]) do - [key, _value] -> "#{key}=[REDACTED]" - _ -> "[REDACTED]" - end - end) + Regex.replace(pattern, acc, &redact_match/1) end) end