Method chart_chooser
has a Cognitive Complexity of 84 (exceeds 5 allowed). Consider refactoring. Open
def chart_chooser
assert_privileges('utilization')
unless params[:task_id] # Only do this first time thru
@sb[:options][:chart_date] = params[:miq_date_1] if params[:miq_date_1]
@sb[:options][:chart_date] = params[:miq_date_2] if params[:miq_date_2]
- 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_node_info
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
def get_node_info(treenodeid, refresh = nil)
treenodeid = valid_active_node(treenodeid)
get_nodetype_and_record(treenodeid)
@right_cell_text = if @record.kind_of?(MiqEnterprise)
_('Enterprise')
- 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 chart_chooser is too high. [33/11] Open
def chart_chooser
assert_privileges('utilization')
unless params[:task_id] # Only do this first time thru
@sb[:options][:chart_date] = params[:miq_date_1] if params[:miq_date_1]
@sb[:options][:chart_date] = params[:miq_date_2] if params[:miq_date_2]
- 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 get_node_info is too high. [26/11] Open
def get_node_info(treenodeid, refresh = nil)
treenodeid = valid_active_node(treenodeid)
get_nodetype_and_record(treenodeid)
@right_cell_text = if @record.kind_of?(MiqEnterprise)
_('Enterprise')
- 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 get_node_info
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_node_info(treenodeid, refresh = nil)
treenodeid = valid_active_node(treenodeid)
get_nodetype_and_record(treenodeid)
@right_cell_text = if @record.kind_of?(MiqEnterprise)
_('Enterprise')
- Create a ticketCreate a ticket
Method chart_chooser
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def chart_chooser
assert_privileges('utilization')
unless params[:task_id] # Only do this first time thru
@sb[:options][:chart_date] = params[:miq_date_1] if params[:miq_date_1]
@sb[:options][:chart_date] = params[:miq_date_2] if params[:miq_date_2]
- Create a ticketCreate a ticket
Method replace_right_cell
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def replace_right_cell(_nodetype)
# Get the tags for this node for the Classification pulldown
@sb[:tags] = nil unless params[:miq_date_1] || params[:miq_date_2] # Clear tags unless just changing date
unless @nodetype == "h" || @nodetype == "s" || params[:miq_date_1] || params[:miq_date_2] # Get the tags for the pulldown, unless host, storage, or just changing the date
if @sb[:options][:chart_date]
- Create a ticketCreate a ticket
Avoid more than 3 levels of block nesting. Open
@sb[:options][:time_profile] = params[:details_time_profile].blank? ? nil : params[:details_time_profile].to_i if params.key?(:details_time_profile)
- 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
@sb[:options][:time_profile] = params[:summ_time_profile].blank? ? nil : params[:summ_time_profile].to_i if params.key?(:summ_time_profile)
- 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
@sb[:options][:time_profile] = params[:report_time_profile].blank? ? nil : params[:report_time_profile].to_i if params.key?(:report_time_profile)
- 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.