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).
This commit is contained in:
parent
345d163108
commit
3cb18a47fc
1 changed files with 13 additions and 15 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue