fix: replace cond blocks with pattern matching and case (CSM-021)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-11 09:04:56 +02:00
parent d231f42363
commit 2be43ca06d
4 changed files with 38 additions and 22 deletions

View File

@@ -62,14 +62,12 @@ defmodule BDS.AI do
model = get_setting("ai.#{kind_key}.model")
encrypted_api_key = get_setting(encrypted_key("ai.#{kind_key}.api_key"))
cond do
is_nil(url) and is_nil(model) and is_nil(encrypted_api_key) ->
{:ok, nil}
true ->
with {:ok, api_key} <- get_secret(encrypted_api_key, backend) do
{:ok, %{kind: kind, url: url, api_key: api_key, model: model}}
end
if is_nil(url) and is_nil(model) and is_nil(encrypted_api_key) do
{:ok, nil}
else
with {:ok, api_key} <- get_secret(encrypted_api_key, backend) do
{:ok, %{kind: kind, url: url, api_key: api_key, model: model}}
end
end
end

View File

@@ -1434,18 +1434,17 @@ defmodule BDS.Scripting.ApiDocs do
|> Enum.uniq()
end
defp example_response_value(returns) do
cond do
returns == "nil" ->
nil
defp example_response_value("nil"), do: nil
nullable_return?(returns) ->
defp example_response_value(returns) do
case {nullable_return?(returns), String.ends_with?(returns, "[]")} do
{true, _} ->
{:nullable, example_response_value(non_nil_return(returns))}
String.ends_with?(returns, "[]") ->
{_, true} ->
[example_value_for_type(String.trim_trailing(returns, "[]"))]
true ->
_ ->
example_value_for_type(returns)
end
end
@@ -1475,10 +1474,10 @@ defmodule BDS.Scripting.ApiDocs do
end
defp example_field_value(type) do
cond do
String.contains?(type, " | nil") -> nil
String.ends_with?(type, "[]") -> [example_value_for_type(String.trim_trailing(type, "[]"))]
true -> example_value_for_type(type)
case {String.contains?(type, " | nil"), String.ends_with?(type, "[]")} do
{true, _} -> nil
{_, true} -> [example_value_for_type(String.trim_trailing(type, "[]"))]
_ -> example_value_for_type(type)
end
end