ManageIQ/manageiq-ui-classic

View on GitHub
app/controllers/application_controller/ci_processing.rb

Summary

Maintainability
F
4 days
Test Coverage
C
74%

File ci_processing.rb has 775 lines of code (exceeds 400 allowed). Consider refactoring.
Open

module ApplicationController::CiProcessing
  extend ActiveSupport::Concern

  included do
    include Mixins::Actions::VmActions::Ownership
Severity: Major
Found in app/controllers/application_controller/ci_processing.rb - About 1 day to fix

Cyclomatic complexity for process_vm_buttons is too high. [39/11]
Open

  def process_vm_buttons(pfx)
    case params[:pressed]
    when "#{pfx}_policy_sim"                then polsimvms
    when "#{pfx}_compare"                   then comparemiq
    when "#{pfx}_scan"                      then scanvms

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 edit_record has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def edit_record
    assert_privileges(params[:pressed])
    obj = find_checked_items
    db = params[:db] if params[:db]

Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 2 hrs to fix

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_elements has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  def process_elements(elements, klass, task, display_name = nil, order_field = nil)
    order_field ||= %w[name description title].find { |field| klass.column_names.include?(field) }

    order_by = order_field == "ems_id" ? order_field : klass.arel_table[order_field].lower

Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 2 hrs to fix

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_objects has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  def process_objects(objs, task, display_name = nil)
    klass = record_class
    klass_str = klass.to_s

    assert_rbac(klass, objs)
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 2 hrs to fix

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_show_list has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

  def process_show_list(options = {})
    session["#{self.class.session_key_prefix}_display".to_sym] = nil
    @display = nil
    @lastaction = "show_list"
    @gtl_url = "/show_list"
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 2 hrs to fix

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 edit_record is too high. [16/11]
Open

  def edit_record
    assert_privileges(params[:pressed])
    obj = find_checked_items
    db = params[:db] if params[:db]

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 process_storage has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def process_storage(storages, task, _ = nil)
    storages, _storages_out_region = filter_ids_in_region(storages, _("Datastore"))
    return if storages.empty?

    if task == "destroy"
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

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 process_show_list is too high. [13/11]
Open

  def process_show_list(options = {})
    session["#{self.class.session_key_prefix}_display".to_sym] = nil
    @display = nil
    @lastaction = "show_list"
    @gtl_url = "/show_list"

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 delete_elements has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  def delete_elements(model_class, destroy_method, model_name = nil)
    model_name ||= model_class.table_name
    elements = find_records_with_rbac(model_class, checked_or_params)
    send(destroy_method, elements.ids, 'destroy')
    if params[:miq_grid_checks].present? || @lastaction == "show_list" || (@lastaction == "show" && @layout != model_name.singularize) # showing a list
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

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_vm_buttons has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def process_vm_buttons(pfx)
    case params[:pressed]
    when "#{pfx}_policy_sim"                then polsimvms
    when "#{pfx}_compare"                   then comparemiq
    when "#{pfx}_scan"                      then scanvms
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

Method deletestorages has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  def deletestorages
    assert_privileges("storage_delete")
    storages = find_records_with_rbac(Storage, checked_or_params)
    unless records_support_feature?(storages, 'delete')
      add_flash(_("Only storage without VMs and Hosts can be removed"), :error)
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

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_storage has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def process_storage(storages, task, _ = nil)
    storages, _storages_out_region = filter_ids_in_region(storages, _("Datastore"))
    return if storages.empty?

    if task == "destroy"
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

Method process_objects has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def process_objects(objs, task, display_name = nil)
    klass = record_class
    klass_str = klass.to_s

    assert_rbac(klass, objs)
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

Method process_elements has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def process_elements(elements, klass, task, display_name = nil, order_field = nil)
    order_field ||= %w[name description title].find { |field| klass.column_names.include?(field) }

    order_by = order_field == "ems_id" ? order_field : klass.arel_table[order_field].lower

Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

Method process_resourcepools has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def process_resourcepools(rps, task)
    rps, _rps_out_region = filter_ids_in_region(rps, "Resource Pool")
    return if rps.empty?

    if task == "destroy"
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

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_clusters has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def process_clusters(clusters, task, _ = nil)
    clusters, _clusters_out_region = filter_ids_in_region(clusters, _("Cluster"))
    return if clusters.empty?

    if task == "destroy"
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

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 edit_record has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def edit_record
    assert_privileges(params[:pressed])
    obj = find_checked_items
    db = params[:db] if params[:db]

Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 1 hr to fix

Method process_managers has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def process_managers(managers, task)
    controller_class = request.parameters[:controller]
    provider_class = case controller_class
                     when 'ems_automation' then ManageIQ::Providers::AutomationManager
                     when 'ems_configuration'  then ManageIQ::Providers::ConfigurationManager
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 45 mins to fix

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_elements has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def process_elements(elements, klass, task, display_name = nil, order_field = nil)
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 35 mins to fix

Method cloud_object_store_button_operation has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def cloud_object_store_button_operation(klass, task)
    display_name = _(task.capitalize)
    method = "#{klass.name.underscore.to_sym}_#{task}"
    task = method unless task == 'delete'
    items = find_records_with_rbac(klass, checked_or_params)
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 35 mins to fix

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 screen_redirection has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def screen_redirection(options)
    if options[:redirect].present?
      javascript_redirect(:controller => options[:redirect][:controller],
                          :action     => options[:redirect][:action])
      return
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 25 mins to fix

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_record has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def get_record(db)
    if db == "host"
      @host = @record = identify_record(params[:id], Host)
    elsif db == "miq_template"
      @miq_template = @record = identify_record(params[:id], MiqTemplate)
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 25 mins to fix

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_element_destroy has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def process_element_destroy(element, klass, name)
    return unless element.respond_to?(:destroy)

    audit = {:event        => "#{klass.name.downcase}_record_delete",
             :message      => "[#{name}] Record deleted",
Severity: Minor
Found in app/controllers/application_controller/ci_processing.rb - About 25 mins to fix

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

There are no issues that match your filters.

Category
Status