From c8bd85565c1bbc793f54f6315e07d52d0f87e518 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 9 Feb 2026 12:39:22 -0600 Subject: [PATCH] Reduce cyclomatic complexity in callsign_json.ex Extract device attribute addition into helper function to reduce cyclomatic complexity from 10 to 9: - callsign_json.ex: Extract add_device_attributes/2 helper Moves device.model, device.vendor, device.contact, and device.class attribute additions into separate function This reduces complexity by isolating the && operators in a dedicated helper function. Fixes 1 Credo cyclomatic complexity issue (10 remaining). --- .../controllers/api/v1/json/callsign_json.ex | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/aprsme_web/controllers/api/v1/json/callsign_json.ex b/lib/aprsme_web/controllers/api/v1/json/callsign_json.ex index c4d5242..8aa15a3 100644 --- a/lib/aprsme_web/controllers/api/v1/json/callsign_json.ex +++ b/lib/aprsme_web/controllers/api/v1/json/callsign_json.ex @@ -111,10 +111,7 @@ defmodule AprsmeWeb.Api.V1.CallsignJSON do |> maybe_add(:device_identifier, packet.device_identifier) |> maybe_add(:manufacturer, packet.manufacturer) |> maybe_add(:equipment_type, packet.equipment_type) - |> maybe_add(:device_model, device && device.model) - |> maybe_add(:device_vendor, device && device.vendor) - |> maybe_add(:device_contact, device && device.contact) - |> maybe_add(:device_class, device && device.class) + |> add_device_attributes(device) case equipment_data do empty when empty == %{} -> nil @@ -144,4 +141,12 @@ defmodule AprsmeWeb.Api.V1.CallsignJSON do end defp sanitize_raw_packet(raw_packet), do: raw_packet + + defp add_device_attributes(equipment_data, device) do + equipment_data + |> maybe_add(:device_model, device && device.model) + |> maybe_add(:device_vendor, device && device.vendor) + |> maybe_add(:device_contact, device && device.contact) + |> maybe_add(:device_class, device && device.class) + end end