ManageIQ/manageiq-ui-classic

View on GitHub
app/controllers/application_controller/performance.rb

Summary

Maintainability
F
1 wk
Test Coverage
F
15%

File performance.rb has 1202 lines of code (exceeds 400 allowed). Consider refactoring.
Open

module ApplicationController::Performance
  extend ActiveSupport::Concern

  CHARTS_REPORTS_FOLDER = Rails.root.join("product", "charts", "miq_reports")
  CHARTS_LAYOUTS_FOLDER = Rails.root.join("product", "charts", "layouts")
Severity: Major
Found in app/controllers/application_controller/performance.rb - About 2 days to fix

Method perf_gen_charts has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_gen_charts(rpt, perf_options, parent = false)
    model_title = parent ? "Parent-#{perf_options[:parent]}" : perf_options[:model]
    charts = []
    chart_data = []
    case perf_options[:typ]
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 1 day 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 perf_chart_chooser has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_chart_chooser
    assert_privileges("perf_reload")
    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record

Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 5 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 perf_util_summary_section has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_util_summary_section(s)
    ss = []

    # Fill in the single day data from the timestamp report
    ts_rpt = @sb[:ts_rpt]
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 5 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 perf_util_daily_gen_data has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_util_daily_gen_data(_refresh = nil)
    @perf_record ||= @record
    @sb[:summary] = nil # Clear out existing summary report
    @sb[:trend_charts] = nil # Clear out the charts to be generated

Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 4 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 perf_util_daily_gen_data has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_util_daily_gen_data(_refresh = nil)
    @perf_record ||= @record
    @sb[:summary] = nil # Clear out existing summary report
    @sb[:trend_charts] = nil # Clear out the charts to be generated

Severity: Major
Found in app/controllers/application_controller/performance.rb - About 3 hrs to fix

Method perf_gen_charts has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_gen_charts(rpt, perf_options, parent = false)
    model_title = parent ? "Parent-#{perf_options[:parent]}" : perf_options[:model]
    charts = []
    chart_data = []
    case perf_options[:typ]
Severity: Major
Found in app/controllers/application_controller/performance.rb - About 3 hrs to fix

Method perf_gen_top_data_before_wait has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_gen_top_data_before_wait
    @perf_options[:ght_type] ||= "hybrid"
    @perf_options[:chart_type] = :performance
    cont_plus_model = request.parameters["controller"] + "-" + @perf_options[:top_model]
    metric_model = @perf_options[:top_model] == "Vm" ? "VmOrTemplate" : @perf_options[:top_model]
Severity: Minor
Found in app/controllers/application_controller/performance.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

Cyclomatic complexity for perf_util_daily_gen_data is too high. [22/11]
Open

  def perf_util_daily_gen_data(_refresh = nil)
    @perf_record ||= @record
    @sb[:summary] = nil # Clear out existing summary report
    @sb[:trend_charts] = nil # Clear out the charts to be generated

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Cyclomatic complexity for perf_chart_chooser is too high. [21/11]
Open

  def perf_chart_chooser
    assert_privileges("perf_reload")
    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Cyclomatic complexity for perf_gen_charts is too high. [21/11]
Open

  def perf_gen_charts(rpt, perf_options, parent = false)
    model_title = parent ? "Parent-#{perf_options[:parent]}" : perf_options[:model]
    charts = []
    chart_data = []
    case perf_options[:typ]

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method perf_gen_top_data_before_wait has 66 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_gen_top_data_before_wait
    @perf_options[:ght_type] ||= "hybrid"
    @perf_options[:chart_type] = :performance
    cont_plus_model = request.parameters["controller"] + "-" + @perf_options[:top_model]
    metric_model = @perf_options[:top_model] == "Vm" ? "VmOrTemplate" : @perf_options[:top_model]
Severity: Major
Found in app/controllers/application_controller/performance.rb - About 2 hrs to fix

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

  def perf_top_chart
    return if perfmenu_click?

    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record
Severity: Minor
Found in app/controllers/application_controller/performance.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

Cyclomatic complexity for perf_util_summary_section is too high. [18/11]
Open

  def perf_util_summary_section(s)
    ss = []

    # Fill in the single day data from the timestamp report
    ts_rpt = @sb[:ts_rpt]

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method perf_gen_data_before_wait has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_gen_data_before_wait
    interval_type = @perf_options[:typ].downcase
    case interval_type
    when "hourly", "daily"

Severity: Minor
Found in app/controllers/application_controller/performance.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 perf_chart_chooser has 59 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_chart_chooser
    assert_privileges("perf_reload")
    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record

Severity: Major
Found in app/controllers/application_controller/performance.rb - About 2 hrs to fix

Method perf_gen_data_before_wait has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_gen_data_before_wait
    interval_type = @perf_options[:typ].downcase
    case interval_type
    when "hourly", "daily"

Severity: Major
Found in app/controllers/application_controller/performance.rb - About 2 hrs to fix

Method perf_util_summary_section has 55 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_util_summary_section(s)
    ss = []

    # Fill in the single day data from the timestamp report
    ts_rpt = @sb[:ts_rpt]
Severity: Major
Found in app/controllers/application_controller/performance.rb - About 2 hrs to fix

Method perf_gen_init_options has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_gen_init_options(refresh = nil)
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record
    unless refresh == "n" || params[:refresh] == "n"
      @perf_options = Options.new
      tzs = TimeProfile.rollup_daily_metrics.all_timezones
Severity: Minor
Found in app/controllers/application_controller/performance.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 timeline_selected has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def timeline_selected(chart_click_data, data_row, ts)
    @record = find_record_with_rbac(data_row["resource_type"].constantize, data_row["resource_id"])
    return [true, nil] unless @record

    controller = data_row["resource_type"].underscore
Severity: Minor
Found in app/controllers/application_controller/performance.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

Cyclomatic complexity for perf_gen_top_data_before_wait is too high. [12/11]
Open

  def perf_gen_top_data_before_wait
    @perf_options[:ght_type] ||= "hybrid"
    @perf_options[:chart_type] = :performance
    cont_plus_model = request.parameters["controller"] + "-" + @perf_options[:top_model]
    metric_model = @perf_options[:top_model] == "Vm" ? "VmOrTemplate" : @perf_options[:top_model]

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method perf_top_chart has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_top_chart
    return if perfmenu_click?

    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 1 hr to fix

Method timeline_current has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  def timeline_current(chart_click_data, ts)
    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record
    new_opts = tl_session_data(request.parameters["controller"]) || ApplicationController::Timelines::Options.new
    new_opts[:model] = @perf_record.class.base_class.to_s
Severity: Minor
Found in app/controllers/application_controller/performance.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 timeline_selected has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def timeline_selected(chart_click_data, data_row, ts)
    @record = find_record_with_rbac(data_row["resource_type"].constantize, data_row["resource_id"])
    return [true, nil] unless @record

    controller = data_row["resource_type"].underscore
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 1 hr to fix

Method perf_gen_tag_data_before_wait has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_gen_tag_data_before_wait
    case @perf_options[:typ]
    when "Hourly"
      from_dt = create_time_in_utc(@perf_options[:hourly_date] + " 00:00:00", @perf_options[:tz]) # Get tz 12am in UTC
      to_dt = create_time_in_utc(@perf_options[:hourly_date] + " 23:59:59", @perf_options[:tz])   # Get tz 11:59pm in UTC
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 1 hr to fix

Method perf_gen_top_data_after_wait has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_gen_top_data_after_wait
    miq_task = MiqTask.find(params[:task_id]) # Not first time, read the task record
    if miq_task.task_results.kind_of?(Array)
      rpts = miq_task.task_results.reverse # Grab the array of report objects (reversed so reports can be popped off)
    else
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 1 hr to fix

Method timeline_current has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def timeline_current(chart_click_data, ts)
    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record
    new_opts = tl_session_data(request.parameters["controller"]) || ApplicationController::Timelines::Options.new
    new_opts[:model] = @perf_record.class.base_class.to_s
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 1 hr to fix

Method perf_remove_report_cols has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_remove_report_cols(report, charts = nil)
    charts ||= @charts.first
    new_rpt = MiqReport.new(report.attributes) # Make a copy of the report
    new_rpt.table = Marshal.load(Marshal.dump(report.table))
    keepcols = []
Severity: Minor
Found in app/controllers/application_controller/performance.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 chart_selected has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def chart_selected(chart_click_data, data_row, ts)
    @record = find_record_with_rbac(data_row["resource_type"].constantize, data_row["resource_id"])
    return [true, nil] unless @record

    # Set the perf options in the selected controller's sandbox
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 1 hr to fix

Method perf_gen_tag_data_after_wait has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_gen_tag_data_after_wait
    miq_task = MiqTask.find(params[:task_id])       # Not first time, read the task record
    rpt = miq_task.miq_report_result.report_results # Grab the report object from the blob
    miq_task.destroy                                # Get rid of the task and results

Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 1 hr to fix

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

  def perf_gen_top_data_after_wait
    miq_task = MiqTask.find(params[:task_id]) # Not first time, read the task record
    if miq_task.task_results.kind_of?(Array)
      rpts = miq_task.task_results.reverse # Grab the array of report objects (reversed so reports can be popped off)
    else
Severity: Minor
Found in app/controllers/application_controller/performance.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 chart_current_hourly has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def chart_current_hourly(ts)
    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record
    @perf_options[:typ] = "Hourly"
    @perf_options[:hourly_date] = [ts.month, ts.day, ts.year].join("/")
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 1 hr to fix

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

  def chart_current_daily
    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record
    @perf_options[:typ] = "Daily"
    perf_set_or_fix_dates(false) unless params[:task_id] # Set dates if first time thru
Severity: Minor
Found in app/controllers/application_controller/performance.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 display_selected has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def display_selected(chart_click_data, ts, data_row, bc_model)
    dt = @perf_options[:typ] == "Hourly" ? "on #{ts.to_date} at #{ts.strftime("%H:%M:%S %Z")}" : "on #{ts.to_date}"
    state = chart_click_data.type == "on" ? _("running") : _("stopped")
    if data_row["assoc_ids"][chart_click_data.model.downcase.to_sym][chart_click_data.type.to_sym].blank?
      message = _("No %{model} were %{state} %{time}") % {:model => chart_click_data.model, :state => state, :time => dt}
Severity: Minor
Found in app/controllers/application_controller/performance.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 chart_current_hourly has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def chart_current_hourly(ts)
    @record = identify_tl_or_perf_record
    @perf_record = @record.kind_of?(MiqServer) ? @record.vm : @record # Use related server vm record
    @perf_options[:typ] = "Hourly"
    @perf_options[:hourly_date] = [ts.month, ts.day, ts.year].join("/")
Severity: Minor
Found in app/controllers/application_controller/performance.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 chart_selected has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def chart_selected(chart_click_data, data_row, ts)
    @record = find_record_with_rbac(data_row["resource_type"].constantize, data_row["resource_id"])
    return [true, nil] unless @record

    # Set the perf options in the selected controller's sandbox
Severity: Minor
Found in app/controllers/application_controller/performance.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 perf_menu_click has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_menu_click
    # Parse the clicked item to get indexes and selection variables
    chart_click_data = parse_chart_click(params[:menu_click])
    # Swap in 'Instances' for 'VMs' in AZ breadcrumbs (poor man's cloud/infra split hack)
    bc_model = %w[availability_zone host_aggregate].include?(request.parameters['controller']) && chart_click_data.model == 'VMs' ? 'Instances' : chart_click_data.model
Severity: Minor
Found in app/controllers/application_controller/performance.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 process_chart_click has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def process_chart_click(chart_click_data, data_row, report, ts, bc_model)
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 35 mins to fix

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

  def chart_top_by_tag(chart_click_data, data_row, report, ts, bc_model)
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 35 mins to fix

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

  def process_chart_action(chart_click_data, data_row, report, ts, bc_model)
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 35 mins to fix

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

  def process_display_click(chart_click_data, data_row, report, ts, bc_model)
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 35 mins to fix

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

  def display_by_tag(chart_click_data, data_row, report, ts, bc_model)
Severity: Minor
Found in app/controllers/application_controller/performance.rb - About 35 mins to fix

Method perf_util_summary_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def perf_util_summary_info
    si = {}
    si[:info] = []
    si[:info].push([_("Utilization Trend Summary for"), @sb[:options][:model] == "MiqEnterprise" ? "Enterprise" : "#{ui_lookup(:model => @sb[:options][:model])} [#{@perf_record.name}]"])
    si[:info].push([_("Trend Interval"), "#{format_timezone(@sb[:options][:trend_start], @sb[:options][:tz], "date")} - #{format_timezone(@sb[:options][:trend_end], @sb[:options][:tz], "date")}"])
Severity: Minor
Found in app/controllers/application_controller/performance.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

Method process_chart_click has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def process_chart_click(chart_click_data, data_row, report, ts, bc_model)
    request_displayed, unavailability_reason =
      if chart_click_data.model == "Current" && chart_click_data.type == "Hourly"
        chart_current_hourly(ts)
      elsif chart_click_data.model == "Current" && chart_click_data.type == "Daily"
Severity: Minor
Found in app/controllers/application_controller/performance.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

Avoid more than 3 levels of block nesting.
Open

          menu_opts = parent ? {} : {:menu => chart[:menu], :zoom_url => zoom_url}

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.

Avoid more than 3 levels of block nesting.
Open

            menu_opts = parent ? {} : {:menu => chart[:menu], :zoom_url => zoom_url}

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.

Avoid more than 3 levels of block nesting.
Open

            menu_opts = parent ? {} : {:menu => chart[:menu], :zoom_url => zoom_url}

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.

Avoid more than 3 levels of block nesting.
Open

            menu_opts = parent ? {} : {:menu => chart[:menu], :zoom_url => zoom_url}

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.

Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant.
Open

        next if col.include?("_reserve") && %w[Host Storage].include?(@sb[:options][:model])

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    render :update do |page|
      page << javascript_prologue
      page << if @parent_chart_data
                'ManageIQ.charts.chartData = ' + {
                  "candu"  => @chart_data,
Severity: Major
Found in app/controllers/application_controller/performance.rb and 1 other location - About 1 hr to fix
app/controllers/application_controller/performance.rb on lines 430..446

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 62.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    render :update do |page|
      page << javascript_prologue
      page << if @parent_chart_data
                'ManageIQ.charts.chartData = ' + {
                  "candu"  => @chart_data,
Severity: Major
Found in app/controllers/application_controller/performance.rb and 1 other location - About 1 hr to fix
app/controllers/application_controller/performance.rb on lines 460..476

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 62.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Wrap expressions with varying precedence with parentheses to avoid ambiguity.
Open

        page << 'ManageIQ.charts.chartData = ' + {"candu" => @chart_data}.to_json + ';'

Looks for expressions containing multiple binary operators where precedence is ambiguous due to lack of parentheses. For example, in 1 + 2 * 3, the multiplication will happen before the addition, but lexically it appears that the addition will happen first.

The cop does not consider unary operators (ie. !a or -b) or comparison operators (ie. a =~ b) because those are not ambiguous.

NOTE: Ranges are handled by Lint/AmbiguousRange.

Example:

# bad
a + b * c
a || b && c
a ** b + c

# good (different precedence)
a + (b * c)
a || (b && c)
(a ** b) + c

# good (same precedence)
a + b + c
a * b / c % d

Prefer using YAML.safe_load over YAML.load.
Open

    MiqReport.new(YAML.load(File.read("#{CHARTS_REPORTS_FOLDER}/#{chart_rpt}.yaml")))

Checks for the use of YAML class methods which have potential security issues leading to remote code execution when loading from an untrusted source.

NOTE: Ruby 3.1+ (Psych 4) uses Psych.load as Psych.safe_load by default.

Safety:

The behavior of the code might change depending on what was in the YAML payload, since YAML.safe_load is more restrictive.

Example:

# bad
YAML.load("--- !ruby/object:Foo {}") # Psych 3 is unsafe by default

# good
YAML.safe_load("--- !ruby/object:Foo {}", [Foo])                    # Ruby 2.5  (Psych 3)
YAML.safe_load("--- !ruby/object:Foo {}", permitted_classes: [Foo]) # Ruby 3.0- (Psych 3)
YAML.load("--- !ruby/object:Foo {}", permitted_classes: [Foo])      # Ruby 3.1+ (Psych 4)
YAML.dump(foo)

Shadowing outer local variable - chart.
Open

        chart_layout.each_with_index do |chart, idx|

Checks for the use of local variable names from an outer scope in block arguments or block-local variables. This mirrors the warning given by ruby -cw prior to Ruby 2.6: "shadowing outer local variable - foo".

NOTE: Shadowing of variables in block passed to Ractor.new is allowed because Ractor should not access outer variables. eg. following style is encouraged:

```ruby
worker_id, pipe = env
Ractor.new(worker_id, pipe) do |worker_id, pipe|
end
```

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end

Shadowing outer local variable - chart.
Open

        chart_layout.each_with_index do |chart, idx|

Checks for the use of local variable names from an outer scope in block arguments or block-local variables. This mirrors the warning given by ruby -cw prior to Ruby 2.6: "shadowing outer local variable - foo".

NOTE: Shadowing of variables in block passed to Ractor.new is allowed because Ractor should not access outer variables. eg. following style is encouraged:

```ruby
worker_id, pipe = env
Ractor.new(worker_id, pipe) do |worker_id, pipe|
end
```

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end

Self-assignment detected.
Open

    @charts = @charts

Checks for self-assignments.

Example:

# bad
foo = foo
foo, bar = foo, bar
Foo = Foo

# good
foo = bar
foo, bar = bar, foo
Foo = Bar

Self-assignment detected.
Open

    @chart_data = @chart_data

Checks for self-assignments.

Example:

# bad
foo = foo
foo, bar = foo, bar
Foo = Foo

# good
foo = bar
foo, bar = bar, foo
Foo = Bar

There are no issues that match your filters.

Category
Status