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:
parent
41000e3482
commit
c8bd85565c
1 changed files with 9 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue