ManageIQ/manageiq-ui-classic

View on GitHub
app/services/ems_physical_infra_dashboard_service.rb

Summary

Maintainability
B
5 hrs
Test Coverage
B
82%

Method attributes_data has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def attributes_data
    attributes = %i[physical_chassis
                    physical_racks
                    physical_servers
                    physical_storages
Severity: Minor
Found in app/services/ems_physical_infra_dashboard_service.rb - About 1 hr to fix

Method notification_data has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def notification_data(components, component_type)
    if components&.first.respond_to?(:health_state)
      count = 0
      health_states = components.each_with_object({}) do |component, health_state|
        health_state[component.health_state&.downcase] = (health_state[component.health_state&.downcase] || 0) + 1
Severity: Minor
Found in app/services/ems_physical_infra_dashboard_service.rb - About 1 hr to fix

Method notification_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def notification_data(components, component_type)
    if components&.first.respond_to?(:health_state)
      count = 0
      health_states = components.each_with_object({}) do |component, health_state|
        health_state[component.health_state&.downcase] = (health_state[component.health_state&.downcase] || 0) + 1
Severity: Minor
Found in app/services/ems_physical_infra_dashboard_service.rb - About 55 mins 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

Method servers_group has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def servers_group
    # Get recent Servers
    all_servers = Hash.new(0)
    servers_with_host = Hash.new(0)
    valid_servers = Hash.new(0)
Severity: Minor
Found in app/services/ems_physical_infra_dashboard_service.rb - About 55 mins 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

Method format_server_utilization_data has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def format_server_utilization_data(total_servers, valid_servers, warning_servers, critical_servers, servers_with_host)
Severity: Minor
Found in app/services/ems_physical_infra_dashboard_service.rb - About 35 mins to fix

Call super to initialize state of the parent class.
Open

  def initialize(ems_id, controller)
    @ems_id = ems_id
    @resource = @ems_id.present? ? Array(find_record_with_rbac(EmsPhysicalInfra, @ems_id)) : EmsPhysicalInfra.all
    @controller = controller
  end

Checks for the presence of constructors and lifecycle callbacks without calls to super.

This cop does not consider method_missing (and respond_to_missing?) because in some cases it makes sense to overtake what is considered a missing method. In other cases, the theoretical ideal handling could be challenging or verbose for no actual gain.

Autocorrection is not supported because the position of super cannot be determined automatically.

Object and BasicObject are allowed by this cop because of their stateless nature. However, sometimes you might want to allow other parent classes from this cop, for example in the case of an abstract class that is not meant to be called with super. In those cases, you can use the AllowedParentClasses option to specify which classes should be allowed in addition to Object and BasicObject.

Example:

# bad
class Employee < Person
  def initialize(name, salary)
    @salary = salary
  end
end

# good
class Employee < Person
  def initialize(name, salary)
    super(name)
    @salary = salary
  end
end

# bad
Employee = Class.new(Person) do
  def initialize(name, salary)
    @salary = salary
  end
end

# good
Employee = Class.new(Person) do
  def initialize(name, salary)
    super(name)
    @salary = salary
  end
end

# bad
class Parent
  def self.inherited(base)
    do_something
  end
end

# good
class Parent
  def self.inherited(base)
    super
    do_something
  end
end

# good
class ClassWithNoParent
  def initialize
    do_something
  end
end

Example: AllowedParentClasses: [MyAbstractClass]

# good
class MyConcreteClass < MyAbstractClass
  def initialize
    do_something
  end
end

There are no issues that match your filters.

Category
Status