Method get_all_reps
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def get_all_reps(nodeid = nil)
# set nodeid from @sb, incase sort was pressed
nodeid = x_active_tree == :reports_tree ? x_node.split('-').last : x_node.split('-').last.split('_')[0] if nodeid.nil?
@sb[:miq_report_id] = nodeid
@record = @miq_report = MiqReport.for_user(current_user).find(@sb[:miq_report_id])
- 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 menu_repname_update
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def menu_repname_update(old_name, new_name)
# @param old_name [String] old name for the report
# @param new_name [String, Nil] new name for the report. nil if it was deleted
all_roles = MiqGroup.non_tenant_groups_in_my_region
- 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 get_all_reps is too high. [14/11] Open
def get_all_reps(nodeid = nil)
# set nodeid from @sb, incase sort was pressed
nodeid = x_active_tree == :reports_tree ? x_node.split('-').last : x_node.split('-').last.split('_')[0] if nodeid.nil?
@sb[:miq_report_id] = nodeid
@record = @miq_report = MiqReport.for_user(current_user).find(@sb[:miq_report_id])
- 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 show_preview
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def show_preview
assert_privileges(session.fetch_path(:edit, :rpt_id) ? "miq_report_edit" : "miq_report_new")
unless params[:task_id] # First time thru, kick off the report generate task
@rpt = create_report_object # Build a report object from the latest edit fields
- Create a ticketCreate a ticket
Method show_preview
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def show_preview
assert_privileges(session.fetch_path(:edit, :rpt_id) ? "miq_report_edit" : "miq_report_new")
unless params[:task_id] # First time thru, kick off the report generate task
@rpt = create_report_object # Build a report object from the latest edit fields
- 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 get_all_reps
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_all_reps(nodeid = nil)
# set nodeid from @sb, incase sort was pressed
nodeid = x_active_tree == :reports_tree ? x_node.split('-').last : x_node.split('-').last.split('_')[0] if nodeid.nil?
@sb[:miq_report_id] = nodeid
@record = @miq_report = MiqReport.for_user(current_user).find(@sb[:miq_report_id])
- Create a ticketCreate a ticket
Method miq_report_delete
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def miq_report_delete
assert_privileges("miq_report_delete")
rpt = MiqReport.for_user(current_user).find(params[:id])
if rpt.miq_widgets.exists?
- 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 friendly_model_name
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def friendly_model_name(model)
# First part is a model name
tables = model.split(".")
retname = ""
# The rest are table names
- 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"