Skip to content

Commit 6406d66

Browse files
committed
Began fixing dialyzer warnings.
1 parent 79efa8d commit 6406d66

File tree

10 files changed

+47
-44
lines changed

10 files changed

+47
-44
lines changed

lib/code_corps/analytics/segment_plug_tracker.ex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,27 @@ defmodule CodeCorps.Analytics.SegmentPlugTracker do
1111

1212
@spec maybe_track(Plug.Conn.t) :: Plug.Conn.t
1313
def maybe_track(conn) do
14-
success = successful?(conn)
14+
successful? = successful?(conn)
1515

1616
action = SegmentDataExtractor.get_action(conn)
1717
resource = SegmentDataExtractor.get_resource(conn)
1818

19-
case success && SegmentTrackingSupport.includes?(action, resource) do
20-
true ->
21-
user_id = SegmentDataExtractor.get_user_id(conn, resource)
22-
SegmentTracker.track(user_id, action, resource)
23-
mark_tracked(conn)
24-
false ->
25-
mark_untracked(conn)
19+
if successful? && SegmentTrackingSupport.includes?(action, resource) do
20+
user_id = SegmentDataExtractor.get_user_id(conn, resource)
21+
SegmentTracker.track(user_id, action, resource)
22+
mark_tracked(conn)
23+
else
24+
mark_untracked(conn)
2625
end
2726
end
2827

28+
@spec successful?(Plug.Conn.t) :: boolean
2929
defp successful?(%Plug.Conn{status: status}) when status in [200, 201, 204], do: true
3030
defp successful?(_), do: false
3131

32+
@spec mark_untracked(Plug.Conn.t) :: Plug.Conn.t
3233
defp mark_untracked(conn), do: conn |> Plug.Conn.assign(:segment_tracked, false)
34+
35+
@spec mark_tracked(Plug.Conn.t) :: Plug.Conn.t
3336
defp mark_tracked(conn), do: conn |> Plug.Conn.assign(:segment_tracked, true)
3437
end

lib/code_corps/analytics/segment_tracker.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ defmodule CodeCorps.Analytics.SegmentTracker do
1111
@api Application.get_env(:code_corps, :analytics)
1212

1313
@doc """
14-
Calls `identify` in the configured API module.
14+
Calls `identify` in the configured API module.
1515
"""
1616
@spec identify(CodeCorps.User.t) :: any
1717
def identify(%CodeCorps.User{} = user) do
1818
@api.identify(user.id, SegmentTraitsBuilder.build(user))
1919
end
2020

2121
@doc """
22-
Calls `track` in the configured API module.
22+
Calls `track` in the configured API module.
2323
"""
24-
@spec track(integer, atom | String.t, struct) :: any
24+
@spec track(String.t, atom | String.t, struct) :: any
2525
def track(user_id, action, data) when is_atom(action) do
2626
event = SegmentEventNameBuilder.build(action, data)
2727
traits = SegmentTraitsBuilder.build(data)

lib/code_corps/github/api/errors/pagination_error.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ defmodule CodeCorps.GitHub.API.Errors.PaginationError do
1818
def new({pages, errors}) do
1919
%__MODULE__{
2020
retrieved_pages: pages,
21-
client_errors: errors |> Enum.filter(&is_client_error?/1),
22-
api_errors: errors |> Enum.filter(&is_api_error?/1)
21+
client_errors: errors |> Enum.filter(&client_error?/1),
22+
api_errors: errors |> Enum.filter(&api_error?/1)
2323
}
2424
end
2525

26-
defp is_client_error?(%HTTPClientError{}), do: true
27-
defp is_client_error?(_), do: false
28-
defp is_api_error?(%APIError{}), do: true
29-
defp is_api_error?(_), do: false
26+
defp client_error?(%HTTPClientError{}), do: true
27+
defp client_error?(_), do: false
28+
defp api_error?(%APIError{}), do: true
29+
defp api_error?(_), do: false
3030
end

lib/code_corps/github/event/issue_comment/issue_comment.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
defmodule CodeCorps.GitHub.Event.IssueComment do
22
@moduledoc ~S"""
33
In charge of handling a GitHub Webhook payload for the IssueComment event type
4+
45
[https://developer.github.com/v3/activity/events/types/#issuecommentevent](https://developer.github.com/v3/activity/events/types/#issuecommentevent)
56
"""
67

@@ -12,8 +13,6 @@ defmodule CodeCorps.GitHub.Event.IssueComment do
1213
}
1314
alias GitHub.Sync
1415

15-
@type outcome :: Sync.outcome | {:error, :unexpected_payload}
16-
1716
@doc ~S"""
1817
Handles the "IssueComment" GitHub webhook
1918
@@ -23,7 +22,8 @@ defmodule CodeCorps.GitHub.Event.IssueComment do
2322
- validate the action is properly supported
2423
- sync the comment using `CodeCorps.GitHub.Sync.Comment`
2524
"""
26-
@spec handle(map) :: outcome
25+
@impl CodeCorps.GitHub.Event.Handler
26+
@spec handle(map) :: {:ok, any} | {:error, atom}
2727
def handle(payload) do
2828
with {:ok, :valid} <- validate_payload(payload) do
2929
Sync.issue_comment_event(payload)
@@ -34,9 +34,10 @@ defmodule CodeCorps.GitHub.Event.IssueComment do
3434

3535
@spec validate_payload(map) :: {:ok, :valid} | {:error, :unexpected_payload}
3636
defp validate_payload(%{} = payload) do
37-
case payload |> Validator.valid? do
38-
true -> {:ok, :valid}
39-
false -> {:error, :unexpected_payload}
37+
if Validator.valid?(payload) do
38+
{:ok, :valid}
39+
else
40+
{:error, :unexpected_payload}
4041
end
4142
end
4243
end

lib/code_corps/github/event/issues/issues.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ defmodule CodeCorps.GitHub.Event.Issues do
1313
}
1414
alias GitHub.Sync
1515

16-
@type outcome :: Sync.outcome | {:ok, :ignored} | {:error, :unexpected_payload}
17-
1816
@doc ~S"""
1917
Handles the "Issues" GitHub webhook
2018
@@ -24,7 +22,8 @@ defmodule CodeCorps.GitHub.Event.Issues do
2422
- validate the action is properly supported
2523
- sync the issue using `CodeCorps.GitHub.Sync.Issue`
2624
"""
27-
@spec handle(map) :: outcome
25+
@impl CodeCorps.GitHub.Event.Handler
26+
@spec handle(map) :: {:ok, any} | {:error, atom}
2827
def handle(payload) do
2928
with {:ok, :valid} <- validate_payload(payload) do
3029
Sync.issue_event(payload)
@@ -33,12 +32,12 @@ defmodule CodeCorps.GitHub.Event.Issues do
3332
end
3433
end
3534

36-
@spec validate_payload(map) :: {:ok, :valid}
37-
| {:error, :unexpected_payload}
35+
@spec validate_payload(map) :: {:ok, :valid} | {:error, :unexpected_payload}
3836
defp validate_payload(%{} = payload) do
39-
case payload |> Validator.valid? do
40-
true -> {:ok, :valid}
41-
false -> {:error, :unexpected_payload}
37+
if Validator.valid?(payload) do
38+
{:ok, :valid}
39+
else
40+
{:error, :unexpected_payload}
4241
end
4342
end
4443
end

lib/code_corps/github/event/pull_request/pull_request.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ defmodule CodeCorps.GitHub.Event.PullRequest do
1313
}
1414
alias GitHub.Sync
1515

16-
@type outcome :: Sync.outcome | {:error, :unexpected_payload}
17-
1816
@doc ~S"""
1917
Handles the "PullRequest" GitHub webhook
2018
@@ -24,7 +22,8 @@ defmodule CodeCorps.GitHub.Event.PullRequest do
2422
- validate the action is properly supported
2523
- sync the pull request using `CodeCorps.GitHub.Sync.PullRequest`
2624
"""
27-
@spec handle(map) :: outcome
25+
@impl CodeCorps.GitHub.Event.Handler
26+
@spec handle(map) :: {:ok, any} | {:error, atom}
2827
def handle(payload) do
2928
with {:ok, :valid} <- validate_payload(payload) do
3029
Sync.pull_request_event(payload)
@@ -33,12 +32,12 @@ defmodule CodeCorps.GitHub.Event.PullRequest do
3332
end
3433
end
3534

36-
@spec validate_payload(map) :: {:ok, :valid}
37-
| {:error, :unexpected_payload}
35+
@spec validate_payload(map) :: {:ok, :valid} | {:error, :unexpected_payload}
3836
defp validate_payload(%{} = payload) do
39-
case payload |> Validator.valid? do
40-
true -> {:ok, :valid}
41-
false -> {:error, :unexpected_payload}
37+
if Validator.valid?(payload) do
38+
{:ok, :valid}
39+
else
40+
{:error, :unexpected_payload}
4241
end
4342
end
4443
end

lib/code_corps/model/github_repo.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule CodeCorps.GithubRepo do
4444
|> assoc_constraint(:project)
4545
end
4646

47-
def update_changeset(struct, params \\ {}) do
47+
def update_changeset(struct, params \\ %{}) do
4848
struct
4949
|> cast(params, [:project_id])
5050
|> assoc_constraint(:project)

lib/code_corps/model/project.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ defmodule CodeCorps.Project do
101101
end
102102
end
103103

104-
@spec get_organization(integer | nil) :: CodeCorps.Organization.t :: nil
104+
@spec get_organization(integer | nil) :: CodeCorps.Organization.t | nil
105105
defp get_organization(nil), do: nil
106106
defp get_organization(id), do: CodeCorps.Repo.get(CodeCorps.Organization, id)
107107
end

lib/code_corps/services/user_service.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,16 @@ defmodule CodeCorps.Services.UserService do
9292
end
9393
end
9494

95+
@spec do_update_connect_customers(%StripePlatformCustomer{}, map) :: [%StripeConnectCustomer{}]
9596
defp do_update_connect_customers(stripe_platform_customer, attributes) do
9697
stripe_platform_customer
9798
|> Repo.preload([stripe_connect_customers: :stripe_connect_account])
9899
|> Map.get(:stripe_connect_customers)
99100
|> Enum.map(&do_update_connect_customer(&1, attributes))
100101
end
101102

103+
@spec do_update_connect_customer(%StripeConnectCustomer{}, map) :: [%StripeConnectCustomer{}]
102104
defp do_update_connect_customer(%StripeConnectCustomer{} = stripe_connect_customer, attributes) do
103-
stripe_connect_customer
104-
|> StripeConnectCustomerService.update(attributes)
105+
StripeConnectCustomerService.update(stripe_connect_customer, attributes)
105106
end
106107
end

lib/code_corps/stripe_service/stripe_connect_customer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ defmodule CodeCorps.StripeService.StripeConnectCustomerService do
3131
do
3232
%StripeConnectCustomer{}
3333
|> StripeConnectCustomer.create_changeset(params)
34-
|> Repo.insert
34+
|> Repo.insert()
3535
else
3636
failure -> failure
3737
end

0 commit comments

Comments
 (0)