18F/e-manifest

View on GitHub
app/controllers/concerns/manifest_params.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method has too many lines. [14/10]
Open

  def deep_reject!(hash, &block)
    hash.each do |k, v|
      if (v.is_a?(Hash) || v.is_a?(ActionController::Parameters))
        deep_reject!(v, &block)
      elsif v.is_a?(Array)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method deep_reject! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  def deep_reject!(hash, &block)
    hash.each do |k, v|
      if (v.is_a?(Hash) || v.is_a?(ActionController::Parameters))
        deep_reject!(v, &block)
      elsif v.is_a?(Array)
Severity: Minor
Found in app/controllers/concerns/manifest_params.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Use yield instead of block.call.
Open

      if block.call(k, v)

This cop identifies the use of a &block parameter and block.call where yield would do just as well.

Example:

# bad
def method(&block)
  block.call
end
def another(&func)
  func.call 1, 2, 3
end

# good
def method
  yield
end
def another
  yield 1, 2, 3
end

Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
Open

      if block.call(k, v)

Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

Example:

# bad
if condition
  do_stuff(bar)
end

unless qux.empty?
  Foo.do_something
end

# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?

Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
Open

          if item.is_a?(Hash)

Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

Example:

# bad
if condition
  do_stuff(bar)
end

unless qux.empty?
  Foo.do_something
end

# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?

Unused block argument - k. If it's necessary, use _ or _k as an argument name to indicate that it won't be used.
Open

    deep_reject!(params.fetch(:manifest, {})) { |k, v| v.blank? }

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Don't use parentheses around the condition of an if.
Open

      if (v.is_a?(Hash) || v.is_a?(ActionController::Parameters))

This cop checks for the presence of superfluous parentheses around the condition of if/unless/while/until.

Example:

# bad
x += 1 while (x < 10)
foo unless (bar || baz)

if (x > 10)
elsif (x < 3)
end

# good
x += 1 while x < 10
foo unless bar || baz

if x > 10
elsif x < 3
end

Missing top-level module documentation comment.
Open

module ManifestParams

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

There are no issues that match your filters.

Category
Status