ManageIQ/inventory_refresh

View on GitHub

Showing 87 of 87 total issues

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

        def assert_index(manager_uuid, ref)
          # TODO(lsmola) do we need some production logging too? Maybe the refresh log level could drive this
          # Let' do this really slick development and test env, but disable for production, since the checks are pretty
          # slow.
          return unless inventory_collection.assert_graph_integrity
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/index/proxy.rb - About 1 hr to fix

Cognitive Complexity

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

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

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

Further reading

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

      def save!(association)
        attributes_index        = {}
        inventory_objects_index = {}
        inventory_collection.each do |inventory_object|
          attributes = inventory_object.attributes(inventory_collection)

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

    def assign_only_newest(full_row_version_attr, partial_row_version_attr, attributes, data, k, v)
      # If timestamps are in play, we will set only attributes that are newer
      specific_attr_timestamp = attributes[partial_row_version_attr].try(:[], k)
      specific_data_timestamp = data[partial_row_version_attr].try(:[], k)

Severity: Minor
Found in lib/inventory_refresh/inventory_object.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 initialize has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def initialize(inventory_collection)
        @inventory_collection = inventory_collection
        # TODO(lsmola) do I need to reload every time? Also it should be enough to clear the associations.
        inventory_collection.parent&.reload
        @association = inventory_collection.db_collection_for_comparison
Severity: Minor
Found in lib/inventory_refresh/save_collection/saver/base.rb - About 1 hr to fix

Method assign_attributes has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def assign_attributes(attributes)
      attributes.each do |k, v|
        # We don't want timestamps or resource versions to be overwritten here, since those are driving the conditions
        next if %i[resource_timestamps resource_timestamps_max resource_timestamp].include?(k)
        next if %i[resource_counters resource_counters_max resource_counter].include?(k)
Severity: Minor
Found in lib/inventory_refresh/inventory_object.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 save! has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def save!(association)
        attributes_index        = {}
        inventory_objects_index = {}
        inventory_collection.each do |inventory_object|
          attributes = inventory_object.attributes(inventory_collection)
Severity: Minor
Found in lib/inventory_refresh/save_collection/saver/base.rb - About 1 hr to fix

Method save! has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def save!(association)
        attributes_index        = {}
        inventory_objects_index = {}
        all_attribute_keys      = Set.new + inventory_collection.batch_extra_attributes

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

    def friendly_unique_node_names
      node_names = {}
      # Try to use shorter .name method that InventoryCollection has.
      nodes.group_by { |n| n.respond_to?(:name) ? n.name.to_s : n.to_s }.each do |base_name, ns|
        ns.each_with_index do |n, i|
Severity: Minor
Found in lib/inventory_refresh/graph.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 convert_to_dag! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def convert_to_dag!(nodes, feedback_edge_set)
        new_nodes = []
        inventory_collection_transformations = {}
        nodes.each do |inventory_collection|
          feedback_dependencies = feedback_edge_set.select { |e| e.second == inventory_collection }.map(&:first)
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/graph.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 map_ids_to_inventory_objects has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def map_ids_to_inventory_objects(indexed_inventory_objects, all_attribute_keys, hashes, result, on_conflict:)
        if on_conflict == :do_nothing
          # TODO(lsmola) is the comment below still accurate? We will update some partial rows, the actual skeletal
          # precreate will still do nothing.
          # For ON CONFLICT DO NOTHING, we need to always fetch the records plus the attribute_references. This path

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

    def initialize(properties = {})
      init_basic_properties(properties[:association],
                            properties[:model_class],
                            properties[:name],
                            properties[:parent])
Severity: Minor
Found in lib/inventory_refresh/inventory_collection.rb - About 1 hr to fix

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

      def self.allowed_properties
        %i[
          all_manager_uuids
          arel
          association
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/builder.rb - About 1 hr to fix

Method init_flags has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

        def init_flags(complete, create_only, check_changed,
                       update_only, use_ar_object, targeted,
                       assert_graph_integrity)
          @complete               = complete.nil? ? true : complete
          @create_only            = create_only.nil? ? false : create_only

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

      def batch_iterator(association)
        if pure_sql_records_fetching
          # Building fast iterator doing pure SQL query and therefore avoiding redundant creation of AR objects. The
          # iterator responds to find_in_batches, so it acts like the AR relation. For targeted refresh, the association
          # can already be ApplicationRecordIterator, so we will skip that.

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

    def attributes_with_keys(inventory_collection_scope = nil, all_attribute_keys = [], inventory_object = nil)
      # We should explicitly pass a scope, since the inventory_object can be mapped to more InventoryCollections with
      # different blacklist and whitelist. The generic code always passes a scope.
      inventory_collection_scope ||= inventory_collection

Severity: Minor
Found in lib/inventory_refresh/inventory_object.rb - About 1 hr to fix

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

        def lazy_find(manager_uuid = nil, opts = {}, ref: primary_index_ref, key: nil, default: nil, transform_nested_lazy_finds: false, **manager_uuid_hash)
          # TODO(lsmola) also, it should be enough to have only 1 find method, everything can be lazy, until we try to
          # access the data

          ref                         = opts[:ref] if opts.key?(:ref)
Severity: Minor
Found in lib/inventory_refresh/inventory_collection/index/proxy.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 initialize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(inventory_collection)
        @inventory_collection = inventory_collection
        # TODO(lsmola) do I need to reload every time? Also it should be enough to clear the associations.
        inventory_collection.parent&.reload
        @association = inventory_collection.db_collection_for_comparison
Severity: Minor
Found in lib/inventory_refresh/save_collection/saver/base.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 transform_nested_secondary_indexes! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def transform_nested_secondary_indexes!(depth = 0)
      raise "Nested references are too deep!" if depth > 20

      keys.each do |x|
        attr = full_reference[x]
Severity: Minor
Found in lib/inventory_refresh/inventory_object_lazy.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 attributes has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def attributes(inventory_collection_scope = nil)
      # We should explicitly pass a scope, since the inventory_object can be mapped to more InventoryCollections with
      # different blacklist and whitelist. The generic code always passes a scope.
      inventory_collection_scope ||= inventory_collection

Severity: Minor
Found in lib/inventory_refresh/inventory_object.rb - About 1 hr to fix

Method traverse_dependecies has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def traverse_dependecies(traversed_nodes, starting_node, current_node, edges, dependencies, escalation)
      dependencies.each do |node_edge|
        node = node_edge.first
        traversed_nodes << node
        if traversed_nodes.include?(starting_node)
Severity: Minor
Found in lib/inventory_refresh/graph.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

Severity
Category
Status
Source
Language