From 3cb18a47fc85be1f069db77640f7a07c36d804d2 Mon Sep 17 00:00:00 2001 From: Graham McIntie Date: Sun, 15 Feb 2026 15:18:35 -0600 Subject: [PATCH] Fix Credo nesting in Splynx MRR calculation Extract parse_mrr/1 helper to reduce nesting depth in calculate_total_mrr. Credo --strict: 0 issues. Dialyzer: pass (no new warnings). --- lib/towerops/splynx/sync.ex | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/towerops/splynx/sync.ex b/lib/towerops/splynx/sync.ex index 05a73f1a..5af37e66 100644 --- a/lib/towerops/splynx/sync.ex +++ b/lib/towerops/splynx/sync.ex @@ -47,23 +47,21 @@ defmodule Towerops.Splynx.Sync do end defp calculate_total_mrr(customers) do - Enum.reduce(customers, 0.0, fn customer, total -> - case customer["mrr_total"] do - value when is_binary(value) -> - case Float.parse(value) do - {num, _} -> total + num - :error -> total - end - - value when is_number(value) -> - total + value - - _ -> - total - end - end) + customers + |> Enum.map(&parse_mrr/1) + |> Enum.sum() end + defp parse_mrr(%{"mrr_total" => value}) when is_binary(value) do + case Float.parse(value) do + {num, _} -> num + :error -> 0.0 + end + end + + defp parse_mrr(%{"mrr_total" => value}) when is_number(value), do: value + defp parse_mrr(_), do: 0.0 + defp humanize_sync_error(:unauthorized), do: "Authentication failed — check your API key and secret" defp humanize_sync_error(:forbidden), do: "Access denied — your API credentials may not have sufficient permissions" defp humanize_sync_error({:rate_limited, retry_after}), do: "Rate limited by Splynx — retry after #{retry_after}s"