Method action_field_changed
has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring. Open
def action_field_changed
return unless load_edit("miq_action_edit__#{params[:id]}")
@action = @edit[:action_id] ? MiqAction.find(@edit[:action_id]) : MiqAction.new
- 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 action_field_changed is too high. [30/11] Open
def action_field_changed
return unless load_edit("miq_action_edit__#{params[:id]}")
@action = @edit[:action_id] ? MiqAction.find(@edit[:action_id]) : MiqAction.new
- 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 action_valid_record? is too high. [29/11] Open
def action_valid_record?(rec)
edit = @edit[:new]
options = edit[:options]
add_flash(_("Description is required"), :error) if edit[:description].blank?
add_flash(_("Action Type must be selected"), :error) if edit[:action_type].blank?
- 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 action_valid_record?
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
def action_valid_record?(rec)
edit = @edit[:new]
options = edit[:options]
add_flash(_("Description is required"), :error) if edit[:description].blank?
add_flash(_("Action Type must be selected"), :error) if edit[:action_type].blank?
- 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 action_build_edit_screen is too high. [21/11] Open
def action_build_edit_screen
@edit = {}
@edit[:new] = {}
@edit[:current] = {}
- 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 action_build_edit_screen
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def action_build_edit_screen
@edit = {}
@edit[:new] = {}
@edit[:current] = {}
- 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
Class MiqActionController
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class MiqActionController < ApplicationController
before_action :check_privileges
before_action :get_session_data
after_action :cleanup_action
after_action :set_session_data
- Create a ticketCreate a ticket
Method action_field_changed
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
def action_field_changed
return unless load_edit("miq_action_edit__#{params[:id]}")
@action = @edit[:action_id] ? MiqAction.find(@edit[:action_id]) : MiqAction.new
- Create a ticketCreate a ticket
Cyclomatic complexity for action_set_record_vars is too high. [12/11] Open
def action_set_record_vars(action)
action.description = @edit[:new][:description]
action.action_type = @edit[:new][:action_type]
@edit[:new][:options][:ae_hash] = {}
@edit[:new][:attrs]&.each do |pair|
- 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 action_build_edit_screen
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
def action_build_edit_screen
@edit = {}
@edit[:new] = {}
@edit[:current] = {}
- Create a ticketCreate a ticket
Method miq_action_edit
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def miq_action_edit
assert_privileges(params[:pressed]) if params[:pressed]
# Load @edit/vars for other buttons
id = params[:id] || "new"
return unless load_edit("miq_action_edit__#{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 action_valid_record?
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def action_valid_record?(rec)
edit = @edit[:new]
options = edit[:options]
add_flash(_("Description is required"), :error) if edit[:description].blank?
add_flash(_("Action Type must be selected"), :error) if edit[:action_type].blank?
- Create a ticketCreate a ticket
Method action_set_record_vars
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def action_set_record_vars(action)
action.description = @edit[:new][:description]
action.action_type = @edit[:new][:action_type]
@edit[:new][:options][:ae_hash] = {}
@edit[:new][:attrs]&.each do |pair|
- 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 action_handle_selection_buttons
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def action_handle_selection_buttons(members,
members_chosen = :members_chosen,
choices = :choices,
choices_chosen = :choices_chosen)
if params[:button].ends_with?("_left")
- 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 action_handle_selection_buttons
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def action_handle_selection_buttons(members,
members_chosen = :members_chosen,
choices = :choices,
choices_chosen = :choices_chosen)
if params[:button].ends_with?("_left")
- Create a ticketCreate a ticket
Method action_build_snmp_variables
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def action_build_snmp_variables
@edit[:new][:options][:snmp_version] = "v1" if @edit[:new][:action_type] == "snmp_trap" && @edit[:new][:options][:snmp_version].blank?
@edit[:snmp_var_types] = MiqSnmp.available_types
@edit[:new][:options][:variables] ||= []
10.times do |i|
- 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 miq_action_reset_or_set
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def miq_action_reset_or_set
assert_privileges('miq_action_edit') if params[:button] == "reset"
@in_a_form = true
@action = params[:id] ? MiqAction.find(params[:id]) : MiqAction.new # Get existing or new 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
10.times do |i|
@edit[:new][:options][:variables][i] ||= {}
@edit[:new][:options][:variables][i][:oid] ||= ""
@edit[:new][:options][:variables][i][:var_type] ||= "<None>"
@edit[:new][:options][:variables][i][:value] ||= ""
- 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 55.
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
Similar blocks of code found in 3 locations. Consider refactoring. Open
ApplicationController::AE_MAX_RESOLUTION_FIELDS.times do |i|
f = ("attribute_" + (i + 1).to_s)
v = ("value_" + (i + 1).to_s)
@edit[:new][:attrs][i][0] = params[f] if params[f.to_sym]
@edit[:new][:attrs][i][1] = params[v] if params[v.to_sym]
- 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 54.
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
Unnecessary symbol conversion; use :ae_hash
instead. Open
@edit[:new][:options].delete("ae_hash".to_sym) if @edit[:new][:options][:ae_hash].empty?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for uses of literal strings converted to a symbol where a literal symbol could be used instead.
There are two possible styles for this cop.
strict
(default) will register an offense for any incorrect usage.
consistent
additionally requires hashes to use the same style for
every symbol key (ie. if any symbol key needs to be quoted it requires
all keys to be quoted).
Example:
# bad
'string'.to_sym
:symbol.to_sym
'underscored_string'.to_sym
:'underscored_symbol'
'hyphenated-string'.to_sym
# good
:string
:symbol
:underscored_string
:underscored_symbol
:'hyphenated-string'
Example: EnforcedStyle: strict (default)
# bad
{
'a': 1,
"b": 2,
'c-d': 3
}
# good (don't quote keys that don't require quoting)
{
a: 1,
b: 2,
'c-d': 3
}
Example: EnforcedStyle: consistent
# bad
{
a: 1,
'b-c': 2
}
# good (quote all keys if any need quoting)
{
'a': 1,
'b-c': 2
}
# good (no quoting required)
{
a: 1,
b: 2
}