ManageIQ/manageiq-ui-classic

View on GitHub
app/helpers/report_helper.rb

Summary

Maintainability
A
1 hr
Test Coverage
D
68%

Method chart_fields_options has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def chart_fields_options
    chart_data_columns = if @edit[:new][:group] != 'No'
                           groupings = @edit[:new][:col_options].find_all do |_field, col_options|
                             col_options[:grouping].present? && !col_options[:grouping].empty?
                           end
Severity: Minor
Found in app/helpers/report_helper.rb - About 45 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 get_reports_menu has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def get_reports_menu(hide_custom = false, group = current_group)
    reports = group.try(:settings).try(:[], :report_menus) || default_reports_menu
    unless hide_custom
      # Select all custom reports
      query = {:template_type => 'report', :rpt_type => 'Custom'}
Severity: Minor
Found in app/helpers/report_helper.rb - About 25 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

                               field_key = if field =~ /\./
Severity: Minor
Found in app/helpers/report_helper.rb by rubocop

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

Use String#include? instead of a regex match with literal-only pattern.
Open

                               field_key = if field =~ /\./
Severity: Minor
Found in app/helpers/report_helper.rb by rubocop

There are no issues that match your filters.

Category
Status