Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce nested code in some functions #336

Merged
merged 1 commit into from
Dec 27, 2016

Conversation

milmazz
Copy link
Contributor

@milmazz milmazz commented Dec 26, 2016

No description provided.

:error ->
Map.put(map, name, [{[version], parents}])
end
end)
end

defp process_merge_package_version({:ok, list}, map, name, _, _, _), do: Map.put(map, name, list)
defp process_merge_package_version(:error, map, name, version, parents, list),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function takes too many parameters (arity is 6, max is 5).

:error ->
Map.put(map, name, [{[version], parents}])
end
end)
end

defp process_merge_package_version({:ok, list}, map, name, _, _, _), do: Map.put(map, name, list)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function takes too many parameters (arity is 6, max is 5).

if Enum.sort(deps) != Enum.sort(Registry.deps(name, version)),
do: Mix.raise "Registry dependencies mismatch against lock (#{name} #{version})"
end
if deps, do: verify_dependencies(deps, name, version)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function body is nested too deep (max depth is 2, was 3).

@milmazz milmazz force-pushed the reduce_function_body_nested_too_deep branch from 91ea205 to 80cc04e Compare December 27, 2016 00:04
Copy link
Member

@ericmj ericmj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, my only minor comment is that we should have only one pipe per line (I know we don't follow this in some places in this code base).

We should probably also bump the credo arity check to a higher number.


list
|> try_merge_package_version(version, parents)
|> process_merge_package_version(map, name, version, parents, list)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think previously code was clearer, new function takes too many arguments.

end)
end
end

defp show_status(nil, name, version), do: Hex.Shell.info IO.ANSI.format [:green, " #{name} #{version}"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually prefix such functions with print_ instead of show_.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also there is too much things are happening inside this clause, I think we should use do ... end syntax.

_ ->
:ok
end
end)
end

defp verify_registry(deps, name, version, checksum) do
registry_checksum = Registry.checksum(name, version)
if checksum && Base.decode16!(checksum, case: :lower) != registry_checksum,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do ... end syntax would be preferable here.

{Atom.to_string(opts[:hex]), Atom.to_string(app), req, !!opts[:optional]}
end)

if Enum.sort(deps) != Enum.sort(Registry.deps(name, version)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do ... end syntax would be preferable here.

@@ -58,6 +53,9 @@ defmodule Hex.Crypto.PBES2_HMAC_SHA2 do
end
def decrypt(_, _, _, _), do: :error

defp process_fetch_p2s({:ok, salt}, hash, passwd), do: {:ok, %{hash: hash, password: passwd}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe handle_p2s? process_fetch_p2s seems misleading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I was looking for a better name in this function...

content_encryptor_error ->
content_encryptor_error
end
protected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably have fetch_content_encryptor function instead:

defp fetch_content_encryptor(key_manager, protected, opts) do
  case ContentEncryptor.init(protected, opts) do
    {:ok, content_encryptor} ->
      {:ok, key_manager, content_encryptor}
    error ->
      error
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also works, I'll change this section as you suggested.

@milmazz milmazz force-pushed the reduce_function_body_nested_too_deep branch from 80cc04e to db9fbd3 Compare December 27, 2016 06:26
@elixir-bot
Copy link

Ebert has finished reviewing this Pull Request and has found:

  • 3 fixed issues! 🎉

You can see more details about this review at https://ebertapp.io/github/hexpm/hex/pulls/336.

@milmazz
Copy link
Contributor Author

milmazz commented Dec 27, 2016

my only minor comment is that we should have only one pipe per line

@ericmj Already take care of that in the latest commit.

@lexmag Thanks for your review, please let me know what do you think about the latest commit.

Copy link
Contributor

@lexmag lexmag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. 💛

@ericmj ericmj merged commit 6a84c4f into hexpm:master Dec 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants