ManageIQ/manageiq-ui-classic

View on GitHub
app/controllers/chargeback_report_controller.rb

Summary

Maintainability
B
5 hrs
Test Coverage
C
76%

Method fetch_saved_report has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

  def fetch_saved_report(id)
    rr = MiqReportResult.for_user(current_user).find_by(:id => id)
    if rr.nil? # Saved report no longer exists
      @report = nil
      add_flash(_("Error: Report no longer exists in the database"), :error)
Severity: Minor
Found in app/controllers/chargeback_report_controller.rb - About 3 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 fetch_saved_report has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def fetch_saved_report(id)
    rr = MiqReportResult.for_user(current_user).find_by(:id => id)
    if rr.nil? # Saved report no longer exists
      @report = nil
      add_flash(_("Error: Report no longer exists in the database"), :error)
Severity: Minor
Found in app/controllers/chargeback_report_controller.rb - About 1 hr to fix

Avoid deeply nested control flow statements.
Open

            if @report.graph.present?
              @render_chart = true
              @ght_type = "hybrid"
            else
              @ght_type = "tabular"
Severity: Major
Found in app/controllers/chargeback_report_controller.rb - About 45 mins to fix

Avoid more than 3 levels of block nesting.
Open

          if rr.contains_records?
            @html = report_first_page(rr) # Get the first page of the results
            if @report.graph.present?
              @render_chart = true
              @ght_type = "hybrid"

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

private (on line 37) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
Open

  def self.session_key_prefix

Checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

Example:

# bad

class C
  private

  def self.method
    puts 'hi'
  end
end

Example:

# good

class C
  def self.method
    puts 'hi'
  end

  private_class_method :method
end

Example:

# good

class C
  class << self
    private

    def method
      puts 'hi'
    end
  end
end

There are no issues that match your filters.

Category
Status