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).
This commit is contained in:
Graham McIntire 2026-02-09 12:39:22 -06:00
parent 41000e3482
commit c8bd85565c
No known key found for this signature in database

View file

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