Skip to content

Commit

Permalink
Began fixing dialyzer warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
asummers committed Nov 23, 2017
1 parent 79efa8d commit 6406d66
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 44 deletions.
19 changes: 11 additions & 8 deletions lib/code_corps/analytics/segment_plug_tracker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions lib/code_corps/analytics/segment_tracker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ 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
@api.identify(user.id, SegmentTraitsBuilder.build(user))
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)
Expand Down
12 changes: 6 additions & 6 deletions lib/code_corps/github/api/errors/pagination_error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 7 additions & 6 deletions lib/code_corps/github/event/issue_comment/issue_comment.ex
Original file line number Diff line number Diff line change
@@ -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)
"""

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
15 changes: 7 additions & 8 deletions lib/code_corps/github/event/issues/issues.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
15 changes: 7 additions & 8 deletions lib/code_corps/github/event/pull_request/pull_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/code_corps/model/github_repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/code_corps/model/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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
5 changes: 3 additions & 2 deletions lib/code_corps/services/user_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ 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])
|> Map.get(:stripe_connect_customers)
|> 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
2 changes: 1 addition & 1 deletion lib/code_corps/stripe_service/stripe_connect_customer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule CodeCorps.StripeService.StripeConnectCustomerService do
do
%StripeConnectCustomer{}
|> StripeConnectCustomer.create_changeset(params)
|> Repo.insert
|> Repo.insert()
else
failure -> failure
end
Expand Down

0 comments on commit 6406d66

Please sign in to comment.