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
This commit is contained in:
Graham McIntire 2026-02-09 11:48:05 -06:00
parent d8606bb609
commit 185266a1f9
No known key found for this signature in database
2 changed files with 17 additions and 9 deletions

View file

@ -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

View file

@ -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