ManageIQ/manageiq

View on GitHub
app/models/mixins/service_mixin.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
96%

Use filter_map instead.
Open

    srs.collect { |sr| sr.public_send(sr.resource_type.underscore) }.compact
Severity: Minor
Found in app/models/mixins/service_mixin.rb by rubocop

Use sum { ... } instead of collect { ... }.sum.
Open

    service_resources.collect(&:group_idx).uniq.collect { |idx| max_group_delay(idx, delay_type(action)) }.sum
Severity: Minor
Found in app/models/mixins/service_mixin.rb by rubocop

This loop will have at most one iteration.
Open

    each_group_resource(grp_idx) { |_sr| return true }
Severity: Minor
Found in app/models/mixins/service_mixin.rb by rubocop

Checks for loops that will have at most one iteration.

A loop that can never reach the second iteration is a possible error in the code. In rare cases where only one iteration (or at most one iteration) is intended behavior, the code should be refactored to use if conditionals.

NOTE: Block methods that are used with Enumerables are considered to be loops.

AllowedPatterns can be used to match against the block receiver in order to allow code that would otherwise be registered as an offense (eg. times used not in an Enumerable context).

Example:

# bad
while node
  do_something(node)
  node = node.parent
  break
end

# good
while node
  do_something(node)
  node = node.parent
end

# bad
def verify_list(head)
  item = head
  begin
    if verify(item)
      return true
    else
      return false
    end
  end while(item)
end

# good
def verify_list(head)
  item = head
  begin
    if verify(item)
      item = item.next
    else
      return false
    end
  end while(item)

  true
end

# bad
def find_something(items)
  items.each do |item|
    if something?(item)
      return item
    else
      raise NotFoundError
    end
  end
end

# good
def find_something(items)
  items.each do |item|
    if something?(item)
      return item
    end
  end
  raise NotFoundError
end

# bad
2.times { raise ArgumentError }

Example: AllowedPatterns: ['(exactly|atleast|atmost)(\d+).times'] (default)

# good
exactly(2).times { raise StandardError }

Ensure you correctly provided all the arguments.
Open

    return enum_for(:each_group_resource) unless block
Severity: Minor
Found in app/models/mixins/service_mixin.rb by rubocop

Ensures that to_enum/enum_for, called for the current method, has correct arguments.

Example:

# bad
def foo(x, y = 1)
  return to_enum(__callee__, x) # `y` is missing
end

# good
def foo(x, y = 1)
  # Alternatives to `__callee__` are `__method__` and `:foo`.
  return to_enum(__callee__, x, y)
end

# good
def foo(x, y = 1)
  # It is also allowed if it is wrapped in some method like Sorbet.
  return to_enum(T.must(__callee__), x, y)
end

There are no issues that match your filters.

Category
Status