ManageIQ/inventory_refresh

View on GitHub

Showing 87 of 87 total issues

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

        def init_flags(complete, create_only, check_changed,
                       update_only, use_ar_object, targeted,
                       assert_graph_integrity)
Severity: Major
Found in lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb - About 50 mins to fix

Method traverse_dependecies has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def traverse_dependecies(traversed_nodes, starting_node, current_node, edges, dependencies, escalation)
Severity: Minor
Found in lib/inventory_refresh/graph.rb - About 45 mins to fix

Method get_schema_recursive has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

          def get_schema_recursive(attribute_names, arel_table, data, schema, path, total_level)
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/index/type/local_db.rb - About 45 mins to fix

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

        def assert_relation_keys(data, ref)
          named_ref(ref).each do |key|
            # Skip if the key is not a foreign key
            next unless association_to_foreign_key_mapping[key]
            # Skip if data on key are nil or InventoryObject or InventoryObjectLazy
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/index/proxy.rb - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

    def allowed?(inventory_collection_scope, key)
      foreign_to_association = inventory_collection_scope.foreign_key_to_association_mapping[key] ||
                               inventory_collection_scope.foreign_type_to_association_mapping[key]

      return false if inventory_collection_scope.attributes_blacklist.present? &&
Severity: Minor
Found in lib/inventory_refresh/inventory_object.rb - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method assign_only_newest has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def assign_only_newest(full_row_version_attr, partial_row_version_attr, attributes, data, k, v)
Severity: Minor
Found in lib/inventory_refresh/inventory_object.rb - About 45 mins to fix

Method add_collection has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def add_collection(collection_name, builder_class = inventory_collection_builder, extra_properties = {}, settings = {}, &block)
Severity: Minor
Found in lib/inventory_refresh/persister.rb - About 35 mins to fix

Method insert_query_on_conflict_behavior has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

      def insert_query_on_conflict_behavior(all_attribute_keys, on_conflict, mode, ignore_cols, column_name)
Severity: Minor
Found in lib/inventory_refresh/save_collection/saver/sql_helper_upsert.rb - About 35 mins to fix

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

      def assert_referential_integrity(hash)
        inventory_collection.fixed_foreign_keys.each do |x|
          next unless hash[x].nil?

          subject = "#{hash} of #{inventory_collection} because of missing foreign key #{x} for "\
Severity: Minor
Found in lib/inventory_refresh/save_collection/saver/base.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

      def data_to_hash(data, depth = 0)
        raise "Nested lazy_relation of #{inventory_collection} is too deep, left processing: #{data}" if depth > 20

        data.transform_values do |value|
          if inventory_object_lazy?(value) || inventory_object?(value)
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/serialization.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

          def find(reference)
            # Use the cached index only data_collection_finalized?, meaning no new reference can occur
            if data_collection_finalized? && all_references_loaded? && index
              return index[reference.stringified_reference]
            else
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/index/type/local_db.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

          def db_relation(rails_friendly_includes_schema, all_values = nil, projection = nil)
            relation = if !parent.nil? && !association.nil?
                         parent.send(association)
                       elsif !arel.nil?
                         arel
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/index/type/local_db.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

      def build_edges(inventory_collections)
        edges            = []
        transitive_edges = []
        fixed_edges = []
        inventory_collections.each do |inventory_collection|
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/graph.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

    def to_graphviz(layers: nil)
      node_names = friendly_unique_node_names
      s = []

      s << "digraph {"
Severity: Minor
Found in lib/inventory_refresh/graph.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

          def get_schema_recursive(attribute_names, arel_table, data, schema, path, total_level)
            raise "Nested too deep" if total_level > 100

            attribute_names.each do |key|
              new_path = path + [key]
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/index/type/local_db.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

    def skeletal_precreate!
      # We can do skeletal pre-create only for strategies using unique indexes. Since this can build records out of
      # the given :arel scope, we will always attempt to create the recod, so we need unique index to avoid duplication
      # of records.
      return unless parallel_safe?
Severity: Minor
Found in lib/inventory_refresh/inventory_object_lazy.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

        def init_flags(complete, create_only, check_changed,
                       update_only, use_ar_object, targeted,
                       assert_graph_integrity)

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

Avoid too many return statements within this method.
Open

      return if keys.any? { |x| full_reference[x].blank? }
Severity: Major
Found in lib/inventory_refresh/inventory_object_lazy.rb - About 30 mins to fix

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

        def lazy_find(manager_uuid = nil, opts = {}, ref: primary_index_ref, key: nil, default: nil, transform_nested_lazy_finds: false, **manager_uuid_hash)

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

      def scan_inventory_object_attribute!(key, value)
        return unless loadable?(value)

        value_inventory_collection = value.inventory_collection

Severity: Minor
Found in lib/inventory_refresh/inventory_collection/scanner.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

Severity
Category
Status
Source
Language