ManageIQ/manageiq-ui-classic

View on GitHub
app/helpers/application_helper/listnav.rb

Summary

Maintainability
C
1 day
Test Coverage
D
66%

Method render_listnav_filename has 81 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def render_listnav_filename
      common_layouts = %w[
        physical_storage
        auth_key_pair_cloud
        placement_group
Severity: Major
Found in app/helpers/application_helper/listnav.rb - About 3 hrs to fix

Method li_link has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def li_link(args)
      args[:if] = (args[:count] != 0) if args[:count]
      args[:if] = true unless args.key?(:if)

      link_text, title = build_link_text(args)
Severity: Minor
Found in app/helpers/application_helper/listnav.rb - About 2 hrs 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 build_link_text has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def build_link_text(args)
      if args.key?(:tables)
        entity_name = ui_lookup(:tables => args[:tables])
        link_text   = args.key?(:link_text) ? "#{args[:link_text]} (#{args[:count]})" : "#{entity_name} (#{args[:count]})"
        title       = _("Show all %{names}") % {:names => entity_name}
Severity: Minor
Found in app/helpers/application_helper/listnav.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

Method multiple_relationship_link has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def multiple_relationship_link(record, table_name)
      return unless role_allows?(:feature => "#{table_name}_show_list")
      return if table_name == 'container_route' && !record.respond_to?(:container_routes)

      plural = ui_lookup(:tables => table_name.to_s)
Severity: Minor
Found in app/helpers/application_helper/listnav.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

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

    def li_link(args)
      args[:if] = (args[:count] != 0) if args[:count]
      args[:if] = true unless args.key?(:if)

      link_text, title = build_link_text(args)
Severity: Minor
Found in app/helpers/application_helper/listnav.rb - About 1 hr to fix

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

    def miq_accordion_panel(title, condition, id, &block)
      id = valid_html_id(id)
      control_id = "control_#{id}"
      content_tag(:div, :class => "panel panel-default") do
        out = content_tag(:div, :class => "panel-heading", 'role' => 'tab', 'tabindex' => 0, :id => control_id) do
Severity: Minor
Found in app/helpers/application_helper/listnav.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 single_relationship_link has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def single_relationship_link(record, table_name, property_name = nil)
      property_name ||= table_name
      ent = record.send(property_name)
      name = ui_lookup(:table => table_name.to_s)

Severity: Minor
Found in app/helpers/application_helper/listnav.rb - About 35 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

Use match? instead of =~ when MatchData is not used.
Open

      raise "HTML ID is not valid" if id =~ /[^\w]/

In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

Example:

# bad
def foo
  if x =~ /re/
    do_something
  end
end

# bad
def foo
  if x.match(/re/)
    do_something
  end
end

# bad
def foo
  if /re/ === x
    do_something
  end
end

# good
def foo
  if x.match?(/re/)
    do_something
  end
end

# good
def foo
  if x =~ /re/
    do_something(Regexp.last_match)
  end
end

# good
def foo
  if x.match(/re/)
    do_something($~)
  end
end

# good
def foo
  if /re/ === x
    do_something($~)
  end
end

There are no issues that match your filters.

Category
Status