From 23595cb64dde72844e4725567b26821d1a0db9ed Mon Sep 17 00:00:00 2001 From: Andrew Summers Date: Wed, 22 Nov 2017 18:32:53 -0500 Subject: [PATCH] Began fixing dialyzer warnings. --- .../analytics/segment_plug_tracker.ex | 19 +++++++++++-------- lib/code_corps/analytics/segment_tracker.ex | 6 +++--- .../github/api/errors/pagination_error.ex | 12 ++++++------ .../event/issue_comment/issue_comment.ex | 13 +++++++------ lib/code_corps/github/event/issues/issues.ex | 15 +++++++-------- .../github/event/pull_request/pull_request.ex | 15 +++++++-------- lib/code_corps/model/github_repo.ex | 2 +- lib/code_corps/model/project.ex | 2 +- lib/code_corps/services/user_service.ex | 5 +++-- .../stripe_service/stripe_connect_customer.ex | 2 +- 10 files changed, 47 insertions(+), 44 deletions(-) diff --git a/lib/code_corps/analytics/segment_plug_tracker.ex b/lib/code_corps/analytics/segment_plug_tracker.ex index fbc2ba10e..d9dbc7545 100644 --- a/lib/code_corps/analytics/segment_plug_tracker.ex +++ b/lib/code_corps/analytics/segment_plug_tracker.ex @@ -11,24 +11,27 @@ defmodule CodeCorps.Analytics.SegmentPlugTracker do @spec maybe_track(Plug.Conn.t) :: Plug.Conn.t def maybe_track(conn) do - success = successful?(conn) + successful? = successful?(conn) action = SegmentDataExtractor.get_action(conn) resource = SegmentDataExtractor.get_resource(conn) - case success && SegmentTrackingSupport.includes?(action, resource) do - true -> - user_id = SegmentDataExtractor.get_user_id(conn, resource) - SegmentTracker.track(user_id, action, resource) - mark_tracked(conn) - false -> - mark_untracked(conn) + if successful? && SegmentTrackingSupport.includes?(action, resource) do + user_id = SegmentDataExtractor.get_user_id(conn, resource) + SegmentTracker.track(user_id, action, resource) + mark_tracked(conn) + else + mark_untracked(conn) end end + @spec successful?(Plug.Conn.t) :: boolean defp successful?(%Plug.Conn{status: status}) when status in [200, 201, 204], do: true defp successful?(_), do: false + @spec mark_untracked(Plug.Conn.t) :: Plug.Conn.t defp mark_untracked(conn), do: conn |> Plug.Conn.assign(:segment_tracked, false) + + @spec mark_tracked(Plug.Conn.t) :: Plug.Conn.t defp mark_tracked(conn), do: conn |> Plug.Conn.assign(:segment_tracked, true) end diff --git a/lib/code_corps/analytics/segment_tracker.ex b/lib/code_corps/analytics/segment_tracker.ex index 6f41c9470..241592adb 100644 --- a/lib/code_corps/analytics/segment_tracker.ex +++ b/lib/code_corps/analytics/segment_tracker.ex @@ -11,7 +11,7 @@ defmodule CodeCorps.Analytics.SegmentTracker do @api Application.get_env(:code_corps, :analytics) @doc """ - Calls `identify` in the configured API module. + Calls `identify` in the configured API module. """ @spec identify(CodeCorps.User.t) :: any def identify(%CodeCorps.User{} = user) do @@ -19,9 +19,9 @@ defmodule CodeCorps.Analytics.SegmentTracker do end @doc """ - Calls `track` in the configured API module. + Calls `track` in the configured API module. """ - @spec track(integer, atom | String.t, struct) :: any + @spec track(String.t, atom | String.t, struct) :: any def track(user_id, action, data) when is_atom(action) do event = SegmentEventNameBuilder.build(action, data) traits = SegmentTraitsBuilder.build(data) diff --git a/lib/code_corps/github/api/errors/pagination_error.ex b/lib/code_corps/github/api/errors/pagination_error.ex index 2fa2b904c..64d489a05 100644 --- a/lib/code_corps/github/api/errors/pagination_error.ex +++ b/lib/code_corps/github/api/errors/pagination_error.ex @@ -18,13 +18,13 @@ defmodule CodeCorps.GitHub.API.Errors.PaginationError do def new({pages, errors}) do %__MODULE__{ retrieved_pages: pages, - client_errors: errors |> Enum.filter(&is_client_error?/1), - api_errors: errors |> Enum.filter(&is_api_error?/1) + client_errors: errors |> Enum.filter(&client_error?/1), + api_errors: errors |> Enum.filter(&api_error?/1) } end - defp is_client_error?(%HTTPClientError{}), do: true - defp is_client_error?(_), do: false - defp is_api_error?(%APIError{}), do: true - defp is_api_error?(_), do: false + defp client_error?(%HTTPClientError{}), do: true + defp client_error?(_), do: false + defp api_error?(%APIError{}), do: true + defp api_error?(_), do: false end diff --git a/lib/code_corps/github/event/issue_comment/issue_comment.ex b/lib/code_corps/github/event/issue_comment/issue_comment.ex index 7f3115e03..1d0e0323b 100644 --- a/lib/code_corps/github/event/issue_comment/issue_comment.ex +++ b/lib/code_corps/github/event/issue_comment/issue_comment.ex @@ -1,6 +1,7 @@ defmodule CodeCorps.GitHub.Event.IssueComment do @moduledoc ~S""" In charge of handling a GitHub Webhook payload for the IssueComment event type + [https://developer.github.com/v3/activity/events/types/#issuecommentevent](https://developer.github.com/v3/activity/events/types/#issuecommentevent) """ @@ -12,8 +13,6 @@ defmodule CodeCorps.GitHub.Event.IssueComment do } alias GitHub.Sync - @type outcome :: Sync.outcome | {:error, :unexpected_payload} - @doc ~S""" Handles the "IssueComment" GitHub webhook @@ -23,7 +22,8 @@ defmodule CodeCorps.GitHub.Event.IssueComment do - validate the action is properly supported - sync the comment using `CodeCorps.GitHub.Sync.Comment` """ - @spec handle(map) :: outcome + @impl CodeCorps.GitHub.Event.Handler + @spec handle(map) :: {:ok, any} | {:error, atom} def handle(payload) do with {:ok, :valid} <- validate_payload(payload) do Sync.issue_comment_event(payload) @@ -34,9 +34,10 @@ defmodule CodeCorps.GitHub.Event.IssueComment do @spec validate_payload(map) :: {:ok, :valid} | {:error, :unexpected_payload} defp validate_payload(%{} = payload) do - case payload |> Validator.valid? do - true -> {:ok, :valid} - false -> {:error, :unexpected_payload} + if Validator.valid?(payload) do + {:ok, :valid} + else + {:error, :unexpected_payload} end end end diff --git a/lib/code_corps/github/event/issues/issues.ex b/lib/code_corps/github/event/issues/issues.ex index 73a1ecc5f..9f558e943 100644 --- a/lib/code_corps/github/event/issues/issues.ex +++ b/lib/code_corps/github/event/issues/issues.ex @@ -13,8 +13,6 @@ defmodule CodeCorps.GitHub.Event.Issues do } alias GitHub.Sync - @type outcome :: Sync.outcome | {:ok, :ignored} | {:error, :unexpected_payload} - @doc ~S""" Handles the "Issues" GitHub webhook @@ -24,7 +22,8 @@ defmodule CodeCorps.GitHub.Event.Issues do - validate the action is properly supported - sync the issue using `CodeCorps.GitHub.Sync.Issue` """ - @spec handle(map) :: outcome + @impl CodeCorps.GitHub.Event.Handler + @spec handle(map) :: {:ok, any} | {:error, atom} def handle(payload) do with {:ok, :valid} <- validate_payload(payload) do Sync.issue_event(payload) @@ -33,12 +32,12 @@ defmodule CodeCorps.GitHub.Event.Issues do end end - @spec validate_payload(map) :: {:ok, :valid} - | {:error, :unexpected_payload} + @spec validate_payload(map) :: {:ok, :valid} | {:error, :unexpected_payload} defp validate_payload(%{} = payload) do - case payload |> Validator.valid? do - true -> {:ok, :valid} - false -> {:error, :unexpected_payload} + if Validator.valid?(payload) do + {:ok, :valid} + else + {:error, :unexpected_payload} end end end diff --git a/lib/code_corps/github/event/pull_request/pull_request.ex b/lib/code_corps/github/event/pull_request/pull_request.ex index 442603c0e..88c784eb4 100644 --- a/lib/code_corps/github/event/pull_request/pull_request.ex +++ b/lib/code_corps/github/event/pull_request/pull_request.ex @@ -13,8 +13,6 @@ defmodule CodeCorps.GitHub.Event.PullRequest do } alias GitHub.Sync - @type outcome :: Sync.outcome | {:error, :unexpected_payload} - @doc ~S""" Handles the "PullRequest" GitHub webhook @@ -24,7 +22,8 @@ defmodule CodeCorps.GitHub.Event.PullRequest do - validate the action is properly supported - sync the pull request using `CodeCorps.GitHub.Sync.PullRequest` """ - @spec handle(map) :: outcome + @impl CodeCorps.GitHub.Event.Handler + @spec handle(map) :: {:ok, any} | {:error, atom} def handle(payload) do with {:ok, :valid} <- validate_payload(payload) do Sync.pull_request_event(payload) @@ -33,12 +32,12 @@ defmodule CodeCorps.GitHub.Event.PullRequest do end end - @spec validate_payload(map) :: {:ok, :valid} - | {:error, :unexpected_payload} + @spec validate_payload(map) :: {:ok, :valid} | {:error, :unexpected_payload} defp validate_payload(%{} = payload) do - case payload |> Validator.valid? do - true -> {:ok, :valid} - false -> {:error, :unexpected_payload} + if Validator.valid?(payload) do + {:ok, :valid} + else + {:error, :unexpected_payload} end end end diff --git a/lib/code_corps/model/github_repo.ex b/lib/code_corps/model/github_repo.ex index b06ee26f9..1540b00ee 100644 --- a/lib/code_corps/model/github_repo.ex +++ b/lib/code_corps/model/github_repo.ex @@ -44,7 +44,7 @@ defmodule CodeCorps.GithubRepo do |> assoc_constraint(:project) end - def update_changeset(struct, params \\ {}) do + def update_changeset(struct, params \\ %{}) do struct |> cast(params, [:project_id]) |> assoc_constraint(:project) diff --git a/lib/code_corps/model/project.ex b/lib/code_corps/model/project.ex index fbe846eba..cecd274e3 100644 --- a/lib/code_corps/model/project.ex +++ b/lib/code_corps/model/project.ex @@ -104,7 +104,7 @@ defmodule CodeCorps.Project do end end - @spec get_organization(integer | nil) :: CodeCorps.Organization.t :: nil + @spec get_organization(integer | nil) :: CodeCorps.Organization.t | nil defp get_organization(nil), do: nil defp get_organization(id), do: CodeCorps.Repo.get(CodeCorps.Organization, id) end diff --git a/lib/code_corps/services/user_service.ex b/lib/code_corps/services/user_service.ex index 4b298a68f..bce9029d4 100644 --- a/lib/code_corps/services/user_service.ex +++ b/lib/code_corps/services/user_service.ex @@ -92,6 +92,7 @@ defmodule CodeCorps.Services.UserService do end end + @spec do_update_connect_customers(%StripePlatformCustomer{}, map) :: [%StripeConnectCustomer{}] defp do_update_connect_customers(stripe_platform_customer, attributes) do stripe_platform_customer |> Repo.preload([stripe_connect_customers: :stripe_connect_account]) @@ -99,8 +100,8 @@ defmodule CodeCorps.Services.UserService do |> Enum.map(&do_update_connect_customer(&1, attributes)) end + @spec do_update_connect_customer(%StripeConnectCustomer{}, map) :: [%StripeConnectCustomer{}] defp do_update_connect_customer(%StripeConnectCustomer{} = stripe_connect_customer, attributes) do - stripe_connect_customer - |> StripeConnectCustomerService.update(attributes) + StripeConnectCustomerService.update(stripe_connect_customer, attributes) end end diff --git a/lib/code_corps/stripe_service/stripe_connect_customer.ex b/lib/code_corps/stripe_service/stripe_connect_customer.ex index 92072fbe6..be0082604 100644 --- a/lib/code_corps/stripe_service/stripe_connect_customer.ex +++ b/lib/code_corps/stripe_service/stripe_connect_customer.ex @@ -31,7 +31,7 @@ defmodule CodeCorps.StripeService.StripeConnectCustomerService do do %StripeConnectCustomer{} |> StripeConnectCustomer.create_changeset(params) - |> Repo.insert + |> Repo.insert() else failure -> failure end