ManageIQ/manageiq-ui-classic

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

Summary

Maintainability
F
2 wks
Test Coverage
F
36%

Method prov_get_form_vars has a Cognitive Complexity of 118 (exceeds 5 allowed). Consider refactoring.
Open

  def prov_get_form_vars
    if params[:ids_checked] # User checked/unchecked a tree node
      ids = params[:ids_checked]
      # for some reason if tree is not expanded clicking on radiobuttons this.getAllChecked() sends up extra blanks
      @edit.store_path(:new, tag_symbol_for_workflow, ids.select(&:present?).collect(&:to_i))
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 2 days 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

File miq_request_methods.rb has 953 lines of code (exceeds 400 allowed). Consider refactoring.
Open

module ApplicationController::MiqRequestMethods
  extend ActiveSupport::Concern
  include RequestInfoHelper
  included do
    helper_method :dialog_partial_for_workflow
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 1 day to fix

Method workflow_instance_from_vars has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

  def workflow_instance_from_vars(req)
    options         = {}
    pre_prov_values = nil
    if %w[miq_template service_template vm].include?(@edit[:org_controller])
      if params[:prov_type] && !req # only do this new requests
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 1 day 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 prov_set_form_vars has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
Open

  def prov_set_form_vars(req = nil)
    @edit ||= {}
    session[:prov_options]      = @options = nil  # Clearing out options that were set on show screen
    @edit[:req_id]              = req.try(:id)    # Save existing request record id, if passed in
    @edit[:key]                 = "prov_edit__#{@edit[:req_id] || "new"}"
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 1 day 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 build_grid has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
Open

  def build_grid
    case @edit[:wf]
    when MiqProvisionConfiguredSystemWorkflow
      build_dialog_page_miq_provision_configured_system_workflow
    when MiqProvisionVirtWorkflow
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 7 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 prov_field_changed has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

  def prov_field_changed
    assert_privileges("miq_request_edit")

    if params[:tab_id]
      @edit = session[:edit]
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 6 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 prov_get_form_vars is too high. [49/11]
Open

  def prov_get_form_vars
    if params[:ids_checked] # User checked/unchecked a tree node
      ids = params[:ids_checked]
      # for some reason if tree is not expanded clicking on radiobuttons this.getAllChecked() sends up extra blanks
      @edit.store_path(:new, tag_symbol_for_workflow, ids.select(&:present?).collect(&:to_i))

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

  def prov_set_form_vars(req = nil)
    @edit ||= {}
    session[:prov_options]      = @options = nil  # Clearing out options that were set on show screen
    @edit[:req_id]              = req.try(:id)    # Save existing request record id, if passed in
    @edit[:key]                 = "prov_edit__#{@edit[:req_id] || "new"}"

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

  def prov_set_show_vars
    @showtype = "main"
    @options = @miq_request.get_options # Get the provision options from the request record
    @options[:org_controller] = "vm"
    if @options[:schedule_time]
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 4 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 prov_get_form_vars has 115 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def prov_get_form_vars
    if params[:ids_checked] # User checked/unchecked a tree node
      ids = params[:ids_checked]
      # for some reason if tree is not expanded clicking on radiobuttons this.getAllChecked() sends up extra blanks
      @edit.store_path(:new, tag_symbol_for_workflow, ids.select(&:present?).collect(&:to_i))
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 4 hrs to fix

Method prov_edit has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def prov_edit
    assert_privileges("miq_request_edit")
    if params[:button] == "cancel"
      req = MiqRequest.find(session[:edit][:req_id]) if session[:edit] && session[:edit][:req_id]
      flash_to_session(
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 3 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 workflow_instance_from_vars is too high. [26/11]
Open

  def workflow_instance_from_vars(req)
    options         = {}
    pre_prov_values = nil
    if %w[miq_template service_template vm].include?(@edit[:org_controller])
      if params[:prov_type] && !req # only do this new requests

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

  def build_grid
    case @edit[:wf]
    when MiqProvisionConfiguredSystemWorkflow
      build_dialog_page_miq_provision_configured_system_workflow
    when MiqProvisionVirtWorkflow

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

  def prov_field_changed
    assert_privileges("miq_request_edit")

    if params[:tab_id]
      @edit = session[:edit]

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

  def pre_prov
    assert_privileges("miq_request_edit")
    if params[:button] == "cancel"
      flash_to_session(_("Add of new %{type} Request was cancelled by the user") % {:type => session[:edit][:prov_type]})
      @explorer = session[:edit][:explorer] || false
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 3 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 prov_req_submit has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

  def prov_req_submit
    id = session[:edit][:req_id] || "new"
    return unless load_edit("prov_edit__#{id}", "show_list")

    @edit[:new][:schedule_time] = @edit[:new][:schedule_time].in_time_zone("Etc/UTC") if @edit[:new][:schedule_time]
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 3 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 prov_set_form_vars has 81 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def prov_set_form_vars(req = nil)
    @edit ||= {}
    session[:prov_options]      = @options = nil  # Clearing out options that were set on show screen
    @edit[:req_id]              = req.try(:id)    # Save existing request record id, if passed in
    @edit[:key]                 = "prov_edit__#{@edit[:req_id] || "new"}"
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 3 hrs to fix

Method prov_field_changed has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def prov_field_changed
    assert_privileges("miq_request_edit")

    if params[:tab_id]
      @edit = session[:edit]
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 2 hrs to fix

Cyclomatic complexity for prov_set_show_vars is too high. [18/11]
Open

  def prov_set_show_vars
    @showtype = "main"
    @options = @miq_request.get_options # Get the provision options from the request record
    @options[:org_controller] = "vm"
    if @options[:schedule_time]

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

  def pre_prov
    assert_privileges("miq_request_edit")
    if params[:button] == "cancel"
      flash_to_session(_("Add of new %{type} Request was cancelled by the user") % {:type => session[:edit][:prov_type]})
      @explorer = session[:edit][:explorer] || false
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 2 hrs to fix

Method workflow_instance_from_vars has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def workflow_instance_from_vars(req)
    options         = {}
    pre_prov_values = nil
    if %w[miq_template service_template vm].include?(@edit[:org_controller])
      if params[:prov_type] && !req # only do this new requests
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 2 hrs to fix

Cyclomatic complexity for prov_edit is too high. [17/11]
Open

  def prov_edit
    assert_privileges("miq_request_edit")
    if params[:button] == "cancel"
      req = MiqRequest.find(session[:edit][:req_id]) if session[:edit] && session[:edit][:req_id]
      flash_to_session(

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

  def prov_req_submit
    id = session[:edit][:req_id] || "new"
    return unless load_edit("prov_edit__#{id}", "show_list")

    @edit[:new][:schedule_time] = @edit[:new][:schedule_time].in_time_zone("Etc/UTC") if @edit[:new][:schedule_time]

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

  def build_grid
    case @edit[:wf]
    when MiqProvisionConfiguredSystemWorkflow
      build_dialog_page_miq_provision_configured_system_workflow
    when MiqProvisionVirtWorkflow
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 1 hr to fix

Method prov_edit has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def prov_edit
    assert_privileges("miq_request_edit")
    if params[:button] == "cancel"
      req = MiqRequest.find(session[:edit][:req_id]) if session[:edit] && session[:edit][:req_id]
      flash_to_session(
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 1 hr to fix

Method prov_set_show_vars has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def prov_set_show_vars
    @showtype = "main"
    @options = @miq_request.get_options # Get the provision options from the request record
    @options[:org_controller] = "vm"
    if @options[:schedule_time]
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 1 hr to fix

Method prov_req_submit has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def prov_req_submit
    id = session[:edit][:req_id] || "new"
    return unless load_edit("prov_edit__#{id}", "show_list")

    @edit[:new][:schedule_time] = @edit[:new][:schedule_time].in_time_zone("Etc/UTC") if @edit[:new][:schedule_time]
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 1 hr to fix

Cyclomatic complexity for pre_prov is too high. [12/11]
Open

  def pre_prov
    assert_privileges("miq_request_edit")
    if params[:button] == "cancel"
      flash_to_session(_("Add of new %{type} Request was cancelled by the user") % {:type => session[:edit][:prov_type]})
      @explorer = session[:edit][:explorer] || false

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

  def build_tags_for_provisioning(wf, vm_tags, _edit_mode)
    # for some reason @tags is set in wf, and it is changed by map bellow which causes bugs
    wf.instance_variable_set(:@tags, nil)
    tags = wf.allowed_tags.map do |cat|
      {
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 1 hr to fix

Method _build_whatever_grid has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def _build_whatever_grid(what, list, headers, sort_order, sort_by, integer_fields = [], state = @edit)
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 50 mins to fix

Avoid deeply nested control flow statements.
Open

              elsif params[key] == "__DS__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [] # Save [value, description]
              elsif v.id.to_i == val.to_i
                if @edit[:new][f.to_sym].include?(val)
                  @edit[:new][f.to_sym].delete_if { |x| x == val }
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

              if params[key] == "__HOST__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

      elsif @edit[:new][:current_tab_key] == :purpose
        build_tags_for_provisioning(@edit[:wf], @edit[:new][:vm_tags], true)
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                if params[key] == "__DS__NONE__" # Added this to deselect datastore in grid
                  @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
                elsif v.id.to_i == val.to_i
                  @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
                end
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

        if @edit[:wf].supports_customization_template?
          build_template_grid(@edit[:wf].send("allowed_customization_templates"), @edit[:template_sortdir], @edit[:template_sortcol])
        else
          build_vc_grid(@edit[:wf].get_field(:sysprep_custom_spec, :customize)[:values], @edit[:vc_sortdir], @edit[:vc_sortcol])
        end
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

        @sb[:vm_os] = VmOrTemplate.find(@edit.fetch_path(:new, :src_vm_id, 0)).platform if @edit.fetch_path(:new, :src_vm_id, 0)
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if params[key] == ""
              @edit[:new][f.to_sym] = [nil]
            else
              @edit[:new][f.to_sym] = []
              params[key].split(",").each { |v| @edit[:new][f.to_sym].push(v) }
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            elsif evm_object_class == :Vm
              if params[key] == "__VM__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
Severity: Major
Found in app/controllers/application_controller/miq_request_methods.rb - About 45 mins to fix

Avoid parameter lists longer than 5 parameters. [7/5]
Open

  def _build_whatever_grid(what, list, headers, sort_order, sort_by, integer_fields = [], state = @edit)

Checks for methods with too many parameters.

The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count, as they add less complexity than positional or optional parameters.

Any number of arguments for initialize method inside a block of Struct.new and Data.define like this is always allowed:

Struct.new(:one, :two, :three, :four, :five, keyword_init: true) do
  def initialize(one:, two:, three:, four:, five:)
  end
end

This is because checking the number of arguments of the initialize method does not make sense.

NOTE: Explicit block argument &block is not counted to prevent erroneous change that is avoided by making block argument implicit.

Example: Max: 3

# good
def foo(a, b, c = 1)
end

Example: Max: 2

# bad
def foo(a, b, c = 1)
end

Example: CountKeywordArgs: true (default)

# counts keyword args towards the maximum

# bad (assuming Max is 3)
def foo(a, b, c, d: 1)
end

# good (assuming Max is 3)
def foo(a, b, c: 1)
end

Example: CountKeywordArgs: false

# don't count keyword args towards the maximum

# good (assuming Max is 3)
def foo(a, b, c, d: 1)
end

This cop also checks for the maximum number of optional parameters. This can be configured using the MaxOptionalParameters config option.

Example: MaxOptionalParameters: 3 (default)

# good
def foo(a = 1, b = 2, c = 3)
end

Example: MaxOptionalParameters: 2

# bad
def foo(a = 1, b = 2, c = 3)
end

Method build_vm_grid has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def build_vm_grid(vms, sort_order = nil, sort_by = nil, filter_by = nil)
    sort_by ||= "name"
    sort_order ||= "ASC"
    filter_by ||= ->(_) { true }

Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.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 set_pre_prov_vars has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def set_pre_prov_vars
    @layout = "miq_request_vm"
    @edit = {}
    @edit[:explorer] = @explorer
    @edit[:vm_sortdir] ||= "ASC"
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.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

Avoid more than 3 levels of block nesting.
Open

          svm = VmOrTemplate.where(:id => @options[:src_vm_id][0]).first if @options[:src_vm_id] && @options[:src_vm_id][0]

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

              if params[key] == "__HOST__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end

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

          if @edit[:wf].supports_pxe?
            build_pxe_img_grid(@edit[:wf].send("allowed_images"), @edit[:pxe_img_sortdir], @edit[:pxe_img_sortcol])
            build_host_grid(@edit[:wf].send("allowed_hosts"), @edit[:host_sortdir], @edit[:host_sortcol])
            build_template_grid(@edit[:wf].send("allowed_customization_templates"), @edit[:template_sortdir], @edit[:template_sortcol])
          elsif @edit[:wf].supports_iso?

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

              if %w[miq_template service_template vm].include?(@edit[:org_controller])
                if params[key] == "__DS__NONE__" # Added this to deselect datastore in grid
                  @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
                elsif v.id.to_i == val.to_i
                  @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]

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

            if @edit[:org_controller] == "service_template"
              options[:service_template_request] = true
              ManageIQ::Providers::Vmware::InfraManager::ProvisionWorkflow
            else
              options[:src_vm_id]    = @edit[:prov_id]

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

              if params[key] == "__VM__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end

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[:vm_os] = svm.platform if svm

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

            if params[key] == ""
              @edit[:new][f.to_sym] = [nil]
            else
              @edit[:new][f.to_sym] = []
              params[key].split(",").each { |v| @edit[:new][f.to_sym].push(v.to_i) }

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

              if params[key] == "__TEMPLATE__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end

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

            if params[key] == ""
              @edit[:new][f.to_sym] = [nil]
            else
              @edit[:new][f.to_sym] = []
              params[key].split(",").each { |v| @edit[:new][f.to_sym].push(v) }

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

              if params[key] == "__PXE_IMG__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id == val
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end

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

              if params[key] == "__ISO_IMG__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id == val
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end

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

              if params[key] == "__VC__NONE__" # Added this to deselect custom_spec in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end

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.

Use :allowed_images instead of "allowed_images".
Open

            build_pxe_img_grid(@edit[:wf].send("allowed_images"), @edit[:pxe_img_sortdir], @edit[:pxe_img_sortcol])

Use :allowed_hosts instead of "allowed_hosts".
Open

            build_host_grid(@edit[:wf].send("allowed_hosts"), @edit[:host_sortdir], @edit[:host_sortcol])

Use :allowed_customization_templates instead of "allowed_customization_templates".
Open

            build_template_grid(@edit[:wf].send("allowed_customization_templates"), @edit[:template_sortdir], @edit[:template_sortcol])

Use :allowed_customization_specs instead of "allowed_customization_specs".
Open

            build_vc_grid(@edit[:wf].send("allowed_customization_specs"), @edit[:vc_sortdir], @edit[:vc_sortcol])

Use :allowed_iso_images instead of "allowed_iso_images".
Open

          build_iso_img_grid(@edit[:wf].send("allowed_iso_images"), @edit[:iso_img_sortdir], @edit[:iso_img_sortcol])

Use :allowed_hosts instead of "allowed_hosts".
Open

          build_host_grid(@edit[:wf].send("allowed_hosts"), @edit[:host_sortdir], @edit[:host_sortcol])

Use :allowed_iso_images instead of "allowed_iso_images".
Open

          build_iso_img_grid(@edit[:wf].send("allowed_iso_images"), @edit[:iso_img_sortdir], @edit[:iso_img_sortcol])

Use :allowed_templates instead of "allowed_templates".
Open

          build_vm_grid(@edit[:wf].send("allowed_templates"), @edit[:vm_sortdir], @edit[:vm_sortcol], build_template_filter)

Use :allowed_iso_images instead of "allowed_iso_images".
Open

            build_iso_img_grid(@edit[:wf].send("allowed_iso_images"), @edit[:iso_img_sortdir], @edit[:iso_img_sortcol])

Use :allowed_images instead of "allowed_images".
Open

          build_pxe_img_grid(@edit[:wf].send("allowed_images"), @edit[:pxe_img_sortdir], @edit[:pxe_img_sortcol])

Use :allowed_hosts instead of "allowed_hosts".
Open

        build_host_grid(@edit[:wf].send("allowed_hosts"), @edit[:host_sortdir], @edit[:host_sortcol])

Use :allowed_customization_templates instead of "allowed_customization_templates".
Open

          build_template_grid(@edit[:wf].send("allowed_customization_templates"), @edit[:template_sortdir], @edit[:template_sortcol])

Use :allowed_storages instead of "allowed_storages".
Open

        build_ds_grid(@edit[:wf].send("allowed_storages"), @edit[:ds_sortdir], @edit[:ds_sortcol])

Use :allowed_customization_templates instead of "allowed_customization_templates".
Open

          build_template_grid(@edit[:wf].send("allowed_customization_templates"), @edit[:template_sortdir], @edit[:template_sortcol])

Use :allowed_images instead of "allowed_images".
Open

          build_pxe_img_grid(@edit[:wf].send("allowed_images"), @edit[:pxe_img_sortdir], @edit[:pxe_img_sortcol])

Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant.
Open

              if %w[miq_template service_template vm].include?(@edit[:org_controller])

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        build_host_grid(@edit[:wf].get_field(:placement_host_name, :environment)[:values], @edit[:host_sortdir], @edit[:host_sortcol]) if @edit[:wf].get_field(:placement_host_name, :environment).present?
        build_ds_grid(@edit[:wf].get_field(:placement_ds_name, :environment)[:values], @edit[:ds_sortdir], @edit[:ds_sortcol]) if @edit[:wf].get_field(:placement_ds_name, :environment).present?
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 1 other location - About 50 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 548..549

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 47.

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

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        build_host_grid(@edit[:wf].get_field(:placement_host_name, :environment)[:values], @edit[:host_sortdir], @edit[:host_sortcol]) if @edit[:wf].get_field(:placement_host_name, :environment).present?
        build_ds_grid(@edit[:wf].get_field(:placement_ds_name, :environment)[:values], @edit[:ds_sortdir], @edit[:ds_sortcol]) if @edit[:wf].get_field(:placement_ds_name, :environment).present?
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 1 other location - About 50 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 532..533

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 47.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  def build_template_grid(templates, sort_order = nil, sort_by = nil)
    sort_by ||= "name"
    sort_order ||= "DESC"

    headers = {
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 1 other location - About 25 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 434..446

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 36.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  def build_vc_grid(vcs, sort_order = nil, sort_by = nil)
    sort_by ||= "name"
    sort_order ||= "DESC"

    headers = {
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 1 other location - About 25 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 449..461

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 36.

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

Further Reading

Similar blocks of code found in 5 locations. Consider refactoring.
Open

              if params[key] == "__VM__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 4 other locations - About 20 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 757..761
app/controllers/application_controller/miq_request_methods.rb on lines 772..776
app/controllers/application_controller/miq_request_methods.rb on lines 796..800
app/controllers/application_controller/miq_request_methods.rb on lines 802..806

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

Further Reading

Similar blocks of code found in 5 locations. Consider refactoring.
Open

                if params[key] == "__DS__NONE__" # Added this to deselect datastore in grid
                  @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
                elsif v.id.to_i == val.to_i
                  @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
                end
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 4 other locations - About 20 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 772..776
app/controllers/application_controller/miq_request_methods.rb on lines 778..782
app/controllers/application_controller/miq_request_methods.rb on lines 796..800
app/controllers/application_controller/miq_request_methods.rb on lines 802..806

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

Further Reading

Similar blocks of code found in 5 locations. Consider refactoring.
Open

              if params[key] == "__TEMPLATE__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 4 other locations - About 20 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 757..761
app/controllers/application_controller/miq_request_methods.rb on lines 772..776
app/controllers/application_controller/miq_request_methods.rb on lines 778..782
app/controllers/application_controller/miq_request_methods.rb on lines 802..806

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

Further Reading

Similar blocks of code found in 5 locations. Consider refactoring.
Open

              if params[key] == "__HOST__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 4 other locations - About 20 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 757..761
app/controllers/application_controller/miq_request_methods.rb on lines 778..782
app/controllers/application_controller/miq_request_methods.rb on lines 796..800
app/controllers/application_controller/miq_request_methods.rb on lines 802..806

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

Further Reading

Similar blocks of code found in 5 locations. Consider refactoring.
Open

              if params[key] == "__VC__NONE__" # Added this to deselect custom_spec in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id.to_i == val.to_i
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 4 other locations - About 20 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 757..761
app/controllers/application_controller/miq_request_methods.rb on lines 772..776
app/controllers/application_controller/miq_request_methods.rb on lines 778..782
app/controllers/application_controller/miq_request_methods.rb on lines 796..800

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

              if params[key] == "__PXE_IMG__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id == val
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 1 other location - About 15 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 790..794

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 30.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

              if params[key] == "__ISO_IMG__NONE__" # Added this to deselect datastore in grid
                @edit[:new][f.to_sym] = [nil, nil] # Save [value, description]
              elsif v.id == val
                @edit[:new][f.to_sym] = [val, v.name] # Save [value, description]
              end
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb and 1 other location - About 15 mins to fix
app/controllers/application_controller/miq_request_methods.rb on lines 784..788

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 30.

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

Further Reading

Avoid elsif branches without a body.
Open

        elsif @edit[:wf].kind_of?(VmMigrateWorkflow)
        else
          @edit[:template_sortdir] ||= "ASC"
          @edit[:template_sortcol] ||= "name"
          build_pxe_img_grid(@edit[:wf].send("allowed_images"), @edit[:pxe_img_sortdir], @edit[:pxe_img_sortcol])

Checks for the presence of if, elsif and unless branches without a body.

NOTE: empty else branches are handled by Style/EmptyElse.

Safety:

Autocorrection for this cop is not safe. The conditions for empty branches that the autocorrection removes may have side effects, or the logic in subsequent branches may change due to the removal of a previous condition.

Example:

# bad
if condition
end

# bad
unless condition
end

# bad
if condition
  do_something
elsif other_condition
end

# good
if condition
  do_something
end

# good
unless condition
  do_something
end

# good
if condition
  do_something
elsif other_condition
  do_something_else
end

Example: AllowComments: true (default)

# good
if condition
  do_something
elsif other_condition
  # noop
end

Example: AllowComments: false

# bad
if condition
  do_something
elsif other_condition
  # noop
end

Prefer using YAML.safe_load over YAML.load.
Open

      @view = MiqReport.new(YAML.load(File.read(path_to_report)))

Checks for the use of YAML class methods which have potential security issues leading to remote code execution when loading from an untrusted source.

NOTE: Ruby 3.1+ (Psych 4) uses Psych.load as Psych.safe_load by default.

Safety:

The behavior of the code might change depending on what was in the YAML payload, since YAML.safe_load is more restrictive.

Example:

# bad
YAML.load("--- !ruby/object:Foo {}") # Psych 3 is unsafe by default

# good
YAML.safe_load("--- !ruby/object:Foo {}", [Foo])                    # Ruby 2.5  (Psych 3)
YAML.safe_load("--- !ruby/object:Foo {}", permitted_classes: [Foo]) # Ruby 3.0- (Psych 3)
YAML.load("--- !ruby/object:Foo {}", permitted_classes: [Foo])      # Ruby 3.1+ (Psych 4)
YAML.dump(foo)

There are no issues that match your filters.

Category
Status