File ops_rbac.rb
has 1180 lines of code (exceeds 400 allowed). Consider refactoring. Open
module OpsController::OpsRbac
extend ActiveSupport::Concern
TAG_DB_TO_NAME = {
'MiqGroup' => 'group',
- Create a ticketCreate a ticket
Method rbac_group_get_form_vars
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
def rbac_group_get_form_vars
if %w[up down].include?(params[:button])
move_cols_up if params[:button] == "up"
move_cols_down if params[:button] == "down"
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 rbac_field_changed
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
def rbac_field_changed(rec_type)
id = params[:id].split('__').first || 'new' # Get the record id
id = id unless %w[new seq].include?(id)
return unless load_edit("rbac_#{rec_type}_edit__#{id}", "replace_cell__explorer")
- 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 rbac_edit_save_or_add
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
def rbac_edit_save_or_add(what, rbac_suffix = what)
key = what.to_sym
id = params[:id] || "new"
add_pressed = params[:button] == "add"
- 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 rbac_user_delete
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def rbac_user_delete
assert_privileges("rbac_user_delete")
users = []
if params[:id] # showing a list
if params[:id].nil? || !User.exists?(:id => params[: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
Cyclomatic complexity for rbac_edit_save_or_add is too high. [25/11] Open
def rbac_edit_save_or_add(what, rbac_suffix = what)
key = what.to_sym
id = params[:id] || "new"
add_pressed = params[:button] == "add"
- 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 rbac_edit_reset is too high. [19/11] Open
def rbac_edit_reset(operation, what, klass)
key = what.to_sym
if operation != "new"
record = find_record_with_rbac(klass, checked_or_params)
if %i[group role].include?(key) && record && record.read_only && operation != 'copy'
- 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 rbac_group_get_form_vars is too high. [19/11] Open
def rbac_group_get_form_vars
if %w[up down].include?(params[:button])
move_cols_up if params[:button] == "up"
move_cols_down if params[:button] == "down"
else
- 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 rbac_edit_reset
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def rbac_edit_reset(operation, what, klass)
key = what.to_sym
if operation != "new"
record = find_record_with_rbac(klass, checked_or_params)
if %i[group role].include?(key) && record && record.read_only && operation != 'copy'
- 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 rbac_group_right_tree is too high. [18/11] Open
def rbac_group_right_tree(selected_nodes)
case @sb[:active_rbac_group_tab]
when 'rbac_customer_tags'
cats = Classification.categories.select do |c|
c.show || !%w[folder_path_blue folder_path_yellow].include?(c.name) && !(c.read_only? || c.entries.empty?)
- 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 rbac_field_changed is too high. [18/11] Open
def rbac_field_changed(rec_type)
id = params[:id].split('__').first || 'new' # Get the record id
id = id unless %w[new seq].include?(id)
return unless load_edit("rbac_#{rec_type}_edit__#{id}", "replace_cell__explorer")
- 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 rbac_group_set_form_vars
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_group_set_form_vars
@assigned_filters = []
@group = @record
@edit = {
:new => {
- Create a ticketCreate a ticket
Method rbac_group_get_form_vars
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_group_get_form_vars
if %w[up down].include?(params[:button])
move_cols_up if params[:button] == "up"
move_cols_down if params[:button] == "down"
else
- Create a ticketCreate a ticket
Method rbac_group_user_lookup
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def rbac_group_user_lookup
assert_privileges(params[:id] == "new" ? "rbac_group_add" : "rbac_group_edit")
rbac_group_user_lookup_field_changed
- 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 rbac_group_right_tree
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_group_right_tree(selected_nodes)
case @sb[:active_rbac_group_tab]
when 'rbac_customer_tags'
cats = Classification.categories.select do |c|
c.show || !%w[folder_path_blue folder_path_yellow].include?(c.name) && !(c.read_only? || c.entries.empty?)
- Create a ticketCreate a ticket
Cyclomatic complexity for rbac_group_set_form_vars is too high. [13/11] Open
def rbac_group_set_form_vars
@assigned_filters = []
@group = @record
@edit = {
: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 rbac_user_delete is too high. [13/11] Open
def rbac_user_delete
assert_privileges("rbac_user_delete")
users = []
if params[:id] # showing a list
if params[:id].nil? || !User.exists?(:id => params[: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 rbac_edit_reset
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_edit_reset(operation, what, klass)
key = what.to_sym
if operation != "new"
record = find_record_with_rbac(klass, checked_or_params)
if %i[group role].include?(key) && record && record.read_only && operation != 'copy'
- Create a ticketCreate a ticket
Method rbac_edit_save_or_add
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_edit_save_or_add(what, rbac_suffix = what)
key = what.to_sym
id = params[:id] || "new"
add_pressed = params[:button] == "add"
- Create a ticketCreate a ticket
Method rbac_group_seq_edit
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_group_seq_edit
assert_privileges("rbac_group_seq_edit")
case params[:button]
when "cancel"
@edit = nil
- Create a ticketCreate a ticket
Method rbac_user_delete
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_user_delete
assert_privileges("rbac_user_delete")
users = []
if params[:id] # showing a list
if params[:id].nil? || !User.exists?(:id => params[:id])
- Create a ticketCreate a ticket
Method rbac_edit_tags_reset
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def rbac_edit_tags_reset(tagging)
@object_ids = find_records_with_rbac(tagging.constantize, checked_or_params).ids
if params[:button] == "reset"
id = params[:id] if params[:id]
return unless load_edit("#{session[:tag_db]}_edit_tags__#{id}", "replace_cell__explorer")
- 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 rbac_group_set_form_vars
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def rbac_group_set_form_vars
@assigned_filters = []
@group = @record
@edit = {
: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
Method rbac_group_seq_edit
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def rbac_group_seq_edit
assert_privileges("rbac_group_seq_edit")
case params[:button]
when "cancel"
@edit = nil
- 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 rbac_get_info
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_get_info
node, id = x_node.split("-")
case node
when "xx"
case id
- Create a ticketCreate a ticket
Method rbac_group_user_lookup
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_group_user_lookup
assert_privileges(params[:id] == "new" ? "rbac_group_add" : "rbac_group_edit")
rbac_group_user_lookup_field_changed
- Create a ticketCreate a ticket
Method rbac_user_set_form_vars
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def rbac_user_set_form_vars
copy = @sb[:typ] == "copy"
# save a shadow copy of the record if record is being copied
@user = copy ? @record.dup : @record
@user.miq_groups = @record.miq_groups if copy
- 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 rbac_field_changed
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rbac_field_changed(rec_type)
id = params[:id].split('__').first || 'new' # Get the record id
id = id unless %w[new seq].include?(id)
return unless load_edit("rbac_#{rec_type}_edit__#{id}", "replace_cell__explorer")
- Create a ticketCreate a ticket
Method rbac_group_delete
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def rbac_group_delete
assert_privileges("rbac_group_delete")
groups = []
if params[:id].nil? # showing a list
ids = find_checked_items.collect { |r| r.to_s.split("-").last }
- 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 move_cols_down
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def move_cols_down
return unless load_edit("rbac_group_edit__seq", "replace_cell__explorer")
if params[:seq_fields].blank? || params[:seq_fields][0] == ""
add_flash(_("No fields were selected to move down"), :error)
- 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 rbac_role_delete
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def rbac_role_delete
assert_privileges("rbac_role_delete")
roles = []
if params[:id].nil? # showing a role list
ids = find_checked_items.collect { |r| r.to_s.split("-").last }
- 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 rbac_group_set_filters
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def rbac_group_set_filters(group)
group.entitlement ||= Entitlement.new
if @edit[:new][:use_filter_expression]
group.entitlement.set_managed_filters(nil) if group.entitlement.get_managed_filters.present?
group.entitlement.filter_expression = @edit[:new][:filter_expression]["???"] ? nil : MiqExpression.new(@edit[:new][:filter_expression])
- 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 rbac_group_right_tree
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def rbac_group_right_tree(selected_nodes)
case @sb[:active_rbac_group_tab]
when 'rbac_customer_tags'
cats = Classification.categories.select do |c|
c.show || !%w[folder_path_blue folder_path_yellow].include?(c.name) && !(c.read_only? || c.entries.empty?)
- 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 move_cols_up
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def move_cols_up
return unless load_edit("rbac_group_edit__seq", "replace_cell__explorer")
if params[:seq_fields].blank? || params[:seq_fields][0] == ""
add_flash(_("No fields were selected to move up"), :error)
- 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 rbac_build_list
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def rbac_build_list(rec_type)
@lastaction = "rbac_#{rec_type}s_list"
@force_no_grid_xml = true
if params[:ppsetting] # User selected new per page value
@items_per_page = params[:ppsetting].to_i # Set the new per page value
- 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 rbac_role_set_record_vars
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def rbac_role_set_record_vars(role)
role.name = @edit[:new][:name]
role.settings ||= {}
role.settings[:restrictions] ||= {}
if @edit[:new][:vm_restriction] == :none
- 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 rbac_tenant_delete
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def rbac_tenant_delete
assert_privileges("rbac_tenant_delete")
tenants = []
if !params[:id] # showing a tenants list
tenants = Tenant.where(:id => find_checked_items).reject do |t|
- 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 build_rbac_feature_tree
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def build_rbac_feature_tree
@role = @sb[:typ] == "copy" ? @record.dup : @record if @role.nil? # if on edit screen use @record
@role.miq_product_features = @record.miq_product_features if @sb[:typ] == "copy"
# The edit/noedit tree should have a different name due to a collision between RJS and Redux
TreeBuilderOpsRbacFeatures.new(@edit.present? ? "features_tree" : "features_tree_noedit", @sb, true, :role => @role, :editable => @edit.present?)
- 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 rbac_role_get_form_vars
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def rbac_role_get_form_vars
@edit[:new][:name] = params[:name] if params[:name]
@edit[:new][:vm_restriction] = params[:vm_restriction].to_sym if params[:vm_restriction]
@edit[:new][:service_template_restriction] = params[:service_template_restriction].to_sym if params[:service_template_restriction]
- 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 rbac_tags_edit
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def rbac_tags_edit
assert_privileges("rbac_tenant_tags_edit")
case params[:button]
when "cancel"
- 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 rbac_group_filter_expression_vars
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def rbac_group_filter_expression_vars(field_expression, field_expression_table)
@edit[:new][field_expression] = if @group&.entitlement && @group.entitlement[field_expression].kind_of?(MiqExpression)
@group.entitlement[field_expression].exp
else
@edit[:new][field_expression] = nil
- 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 rbac_edit_cancel
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def rbac_edit_cancel(what)
key = what.to_sym
id = params[:id] || "new"
return unless load_edit("rbac_#{what}_edit__#{id}", "replace_cell__explorer")
- 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 rbac_group_get_details
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def rbac_group_get_details(id)
@record = @group = MiqGroup.find_by(:id => id)
@belongsto = {}
@filters = {}
@filter_expression = []
- 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 rbac_role_set_form_vars
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def rbac_role_set_form_vars
@edit = {}
@edit[:role_id] = @record.id if @sb[:typ] != "copy"
@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
Method rbac_user_validate?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def rbac_user_validate?
valid = true
if @edit[:new][:password] != @edit[:new][:verify]
add_flash(_("Password/Verify Password do not match"), :error)
valid = false
- 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 immutable Array literals in loops. It is better to extract it into a local variable or a constant. Open
c.show || !%w[folder_path_blue folder_path_yellow].include?(c.name) && !(c.read_only? || c.entries.empty?)
- Create a ticketCreate a ticket
- Exclude checks
Similar blocks of code found in 3 locations. Consider refactoring. Open
if !consecutive
add_flash(_("Select only one or consecutive fields to move down"), :error)
else
if last_idx < @edit[:new][:ldap_groups_list].length - 1
insert_idx = last_idx + 1 # Insert before the element after the last one
- 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 70.
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
if !consecutive
add_flash(_("Select only one or consecutive fields to move up"), :error)
else
if first_idx.positive?
@edit[:new][:ldap_groups_list][first_idx..last_idx].reverse_each do |field|
- 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 46.
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
id = params[:id] if params[:id]
return unless load_edit("#{session[:tag_db]}_edit_tags__#{id}", "replace_cell__explorer")
@object_ids = @edit[:object_ids]
session[:tag_db] = @tagging = @edit[:tagging]
- 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 32.
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
c.show || !%w[folder_path_blue folder_path_yellow].include?(c.name) && !(c.read_only? || c.entries.empty?)
- 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
Self-assignment detected. Open
id = id unless %w[new seq].include?(id)
- 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