ManageIQ/manageiq-ui-classic

View on GitHub
app/controllers/mixins/actions/vm_actions/reconfigure.rb

Summary

Maintainability
D
2 days
Test Coverage
F
19%

Method build_reconfigure_hash has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

        def build_reconfigure_hash(reconfigure_ids)
          @req = nil
          @reconfig_values = {}
          if @request_id == 'new'
            @reconfig_values = get_reconfig_info(reconfigure_ids)
Severity: Minor
Found in app/controllers/mixins/actions/vm_actions/reconfigure.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

Method reconfigure_handle_submit_button has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

        def reconfigure_handle_submit_button
          options = {:src_ids => params[:objectIds]}
          if params[:cb_memory] == 'true' && role_allows?(:feature => 'vm_reconfigure_memory')
            options[:vm_memory] = params[:memory_type] == "MB" ? params[:memory] : params[:memory].to_i * 1024
          end
Severity: Minor
Found in app/controllers/mixins/actions/vm_actions/reconfigure.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 build_reconfigure_hash is too high. [20/11]
Open

        def build_reconfigure_hash(reconfigure_ids)
          @req = nil
          @reconfig_values = {}
          if @request_id == 'new'
            @reconfig_values = get_reconfig_info(reconfigure_ids)

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

        def build_reconfigure_hash(reconfigure_ids)
          @req = nil
          @reconfig_values = {}
          if @request_id == 'new'
            @reconfig_values = get_reconfig_info(reconfigure_ids)
Severity: Major
Found in app/controllers/mixins/actions/vm_actions/reconfigure.rb - About 2 hrs to fix

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

        def reconfigure_handle_submit_button
          options = {:src_ids => params[:objectIds]}
          if params[:cb_memory] == 'true' && role_allows?(:feature => 'vm_reconfigure_memory')
            options[:vm_memory] = params[:memory_type] == "MB" ? params[:memory] : params[:memory].to_i * 1024
          end

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Cyclomatic complexity for get_reconfig_info is too high. [14/11]
Open

        def get_reconfig_info(reconfigure_ids)
          @reconfigureitems = Vm.find(reconfigure_ids).sort_by(&:name)
          # set memory to nil if multiple items were selected with different mem_cpu values
          memory = @reconfigureitems.first.mem_cpu
          memory = nil unless @reconfigureitems.all? { |vm| vm.mem_cpu == memory }

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method get_reconfig_info has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

        def get_reconfig_info(reconfigure_ids)
          @reconfigureitems = Vm.find(reconfigure_ids).sort_by(&:name)
          # set memory to nil if multiple items were selected with different mem_cpu values
          memory = @reconfigureitems.first.mem_cpu
          memory = nil unless @reconfigureitems.all? { |vm| vm.mem_cpu == memory }
Severity: Minor
Found in app/controllers/mixins/actions/vm_actions/reconfigure.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 get_reconfig_info has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def get_reconfig_info(reconfigure_ids)
          @reconfigureitems = Vm.find(reconfigure_ids).sort_by(&:name)
          # set memory to nil if multiple items were selected with different mem_cpu values
          memory = @reconfigureitems.first.mem_cpu
          memory = nil unless @reconfigureitems.all? { |vm| vm.mem_cpu == memory }
Severity: Minor
Found in app/controllers/mixins/actions/vm_actions/reconfigure.rb - About 1 hr to fix

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

        def vm_reconfigure
          assert_privileges('vm_reconfigure_all', :any => true)

          # if coming in to edit from miq_request list view
          recs = checked_or_params
Severity: Minor
Found in app/controllers/mixins/actions/vm_actions/reconfigure.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 vm_reconfigure has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def vm_reconfigure
          assert_privileges('vm_reconfigure_all', :any => true)

          # if coming in to edit from miq_request list view
          recs = checked_or_params
Severity: Minor
Found in app/controllers/mixins/actions/vm_actions/reconfigure.rb - About 1 hr to fix

Method reconfigure_handle_submit_button has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def reconfigure_handle_submit_button
          options = {:src_ids => params[:objectIds]}
          if params[:cb_memory] == 'true' && role_allows?(:feature => 'vm_reconfigure_memory')
            options[:vm_memory] = params[:memory_type] == "MB" ? params[:memory] : params[:memory].to_i * 1024
          end
Severity: Minor
Found in app/controllers/mixins/actions/vm_actions/reconfigure.rb - About 1 hr to fix

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

        def reconfigure(reconfigure_ids = [])
          @sb[:explorer] = true if @explorer
          @request_id = nil
          @in_a_form = @reconfigure = true
          drop_breadcrumb(:name => _("Reconfigure"), :url => "/vm_common/reconfigure")
Severity: Minor
Found in app/controllers/mixins/actions/vm_actions/reconfigure.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

Avoid more than 3 levels of block nesting.
Open

                    if remdisk[:disk_name] == disk.filename
                      removing = 'remove'
                      delbacking = remdisk[:delete_backing]
                    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.

There are no issues that match your filters.

Category
Status