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")
- Create a ticketCreate a ticket
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]
- Read upRead up
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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]
- Read upRead up
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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
- Create a ticketCreate a ticket
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]
- Create a ticketCreate a ticket
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]
- Read upRead up
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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]
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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]
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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]
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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"
- Read upRead up
- Create a ticketCreate a ticket
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
- Create a ticketCreate a ticket
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"
- Create a ticketCreate a ticket
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]
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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]
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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
- Create a ticketCreate a ticket
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
- Create a ticketCreate a ticket
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
- Create a ticketCreate a ticket
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
- Create a ticketCreate a ticket
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 = []
- Read upRead up
- Create a ticketCreate a ticket
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
- Create a ticketCreate a ticket
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
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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("/")
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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}
- Read upRead up
- Create a ticketCreate a ticket
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("/")
- Read upRead up
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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
- Read upRead up
- Create a ticketCreate a ticket
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)
- Create a ticketCreate a ticket
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)
- Create a ticketCreate a ticket
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)
- Create a ticketCreate a ticket
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)
- Create a ticketCreate a ticket
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)
- Create a ticketCreate a ticket
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")}"])
- Read upRead up
- Create a ticketCreate a ticket
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"
- Read upRead up
- Create a ticketCreate a ticket
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}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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])
- Create a ticketCreate a ticket
- Exclude checks
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,
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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,
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Wrap expressions with varying precedence with parentheses to avoid ambiguity. Open
page << 'ManageIQ.charts.chartData = ' + {"candu" => @chart_data}.to_json + ';'
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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")))
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for self-assignments.
Example:
# bad
foo = foo
foo, bar = foo, bar
Foo = Foo
# good
foo = bar
foo, bar = bar, foo
Foo = Bar