From 072b145e7327b53654ed751e776bdc66285fa032 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 9 Feb 2026 13:16:35 -0600 Subject: [PATCH] Reduce cyclomatic complexity in streaming_packets_pubsub Extract bounds validation helpers to reduce complexity: - streaming_packets_pubsub.ex: Extract validation helpers Creates all_bounds_numeric?/4, valid_latitude_range?/1, valid_longitude_range?/1 Moves complex boolean conditions into readable helper functions Reduces complexity from 13 to within limits Fixes 1 Credo cyclomatic complexity issue (5 remaining). --- lib/aprsme/streaming_packets_pubsub.ex | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/aprsme/streaming_packets_pubsub.ex b/lib/aprsme/streaming_packets_pubsub.ex index c58aa3c..b0b663c 100644 --- a/lib/aprsme/streaming_packets_pubsub.ex +++ b/lib/aprsme/streaming_packets_pubsub.ex @@ -146,16 +146,28 @@ defmodule Aprsme.StreamingPacketsPubSub do # Private functions defp valid_bounds?(%{north: n, south: s, east: e, west: w}) do - is_number(n) and is_number(s) and is_number(e) and is_number(w) and + all_bounds_numeric?(n, s, e, w) and n >= s and - n >= -90 and n <= 90 and - s >= -90 and s <= 90 and - e >= -180 and e <= 180 and - w >= -180 and w <= 180 + valid_latitude_range?(n) and + valid_latitude_range?(s) and + valid_longitude_range?(e) and + valid_longitude_range?(w) end defp valid_bounds?(_), do: false + defp all_bounds_numeric?(n, s, e, w) do + is_number(n) and is_number(s) and is_number(e) and is_number(w) + end + + defp valid_latitude_range?(lat) do + lat >= -90 and lat <= 90 + end + + defp valid_longitude_range?(lon) do + lon >= -180 and lon <= 180 + end + defp packet_in_bounds?(lat, lon, %{north: n, south: s, east: e, west: w}) do lat_in_bounds = lat >= s and lat <= n