ManageIQ/manageiq-automation_engine

View on GitHub
lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb

Summary

Maintainability
C
1 day
Test Coverage
A
90%

Method initialize has a Cognitive Complexity of 55 (exceeds 11 allowed). Consider refactoring.
Open

    def initialize(workspace, namespace, klass, instance, object_name = nil)
      Benchmark.current_realtime[:object_count] += 1

      @workspace        = workspace
      @namespace        = namespace
Severity: Minor
Found in lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.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

Cyclomatic complexity for initialize is too high. [30/11]
Open

    def initialize(workspace, namespace, klass, instance, object_name = nil)
      Benchmark.current_realtime[:object_count] += 1

      @workspace        = workspace
      @namespace        = namespace

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

    def process_collect_hash(expr, rels, result)
      lh       = result[1].strip unless result[1].nil?
      contents = result[2].strip

      hash = {}
Severity: Minor
Found in lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.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 convert_value_based_on_datatype is too high. [16/11]
Open

    def self.convert_value_based_on_datatype(value, datatype)
      return value if value.blank? || datatype.nil?

      # Basic Types
      return convert_boolean_value(value)                    if datatype == 'boolean'

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

    def process_collect_hash(expr, rels, result)
      lh       = result[1].strip unless result[1].nil?
      contents = result[2].strip

      hash = {}

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

    def array_value(array, method)
      return array if array.nil? || array.compact.empty?

      case method
      when 'rsort'                  then array.sort.reverse

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

    def attribute_value_to_xml(value, xml)
      case value.class.to_s
      when 'MiqAePassword'            then xml.Password(OPAQUE_PASSWORD)
      when 'String'                   then xml.String(value)
      when 'Fixnum'                   then xml.Fixnum(value)

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

    def process_collect_array(_expr, rels, result)
      lh       = result[1].strip unless result[1].nil?
      contents = result[2].strip
      method   = result[3].strip.downcase unless result[3].nil?

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

    def uri2value(uri, required = false)
      scheme, _userinfo, _host, _port, _registry, path, _opaque, _query, fragment = MiqAeUri.split(uri)

      if scheme == 'miqaedb'
        ns, klass, instance, attribute_name = MiqAePath.split(path, :has_attribute_name => true)
Severity: Minor
Found in lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb - About 55 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 convert_value_based_on_datatype has a Cognitive Complexity of 15 (exceeds 11 allowed). Consider refactoring.
Open

    def self.convert_value_based_on_datatype(value, datatype)
      return value if value.blank? || datatype.nil?

      # Basic Types
      return convert_boolean_value(value)                    if datatype == 'boolean'
Severity: Minor
Found in lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb - About 55 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 invoke_method has a Cognitive Complexity of 12 (exceeds 11 allowed). Consider refactoring.
Open

    def invoke_method(namespace, klass, method_name, args)
      aem = nil

      # No class means an instance method
      aem = @instance_methods[method_name.downcase] if klass.nil?
Severity: Minor
Found in lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.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

Use filter_map instead.
Open

      objects_str.split("\x1F").collect do |element|
        if element.include?(CLASS_SEPARATOR)
          klass, str_value = element.split(CLASS_SEPARATOR)
          MiqAeObject.convert_value_based_on_datatype(str_value.strip, klass.strip)
        else

Use filter_map instead.
Open

      @fields_ordered.collect do |fname|
        @fields[fname] if message.nil? || self.class.message_matches?(message_parse(@fields[fname]['message']), message)
      end.compact

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

        elsif ["\"", "\'"].include?(left[0, 1])

The use of eval is a serious security risk.
Open

          assertion_result = eval(assertion)

Checks for the use of Kernel#eval and Binding#eval.

Example:

# bad

eval(something)
binding.eval(something)

There are no issues that match your filters.

Category
Status