hopsoft/universalid

View on GitHub

Showing 13 of 13 total issues

Method packable_attributes has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    def packable_attributes
      hash = if id_only?
        record.attributes.slice record.class.primary_key
      else
        record.attributes.select { |name, _| prepack_options.keep_key? name }.tap do |attrs|
Severity: Minor
Found in lib/universalid/extensions/active_record/base_packer.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 assign_descendants has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

      def assign_descendants(record, attributes)
        descendants = attributes[UniversalID::Extensions::ActiveRecordBasePacker::DESCENDANTS_KEY] || {}
        descendants.each do |name, list|
          next unless record.respond_to?(name) && record.respond_to?(:"#{name}=")

Severity: Minor
Found in lib/universalid/extensions/active_record/base_unpacker.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

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

    def id_only?
      return false if record.new_record?

      # explicit exclusion of primary key
      return false if prepack_options.reject_key?(record.class.primary_key)
Severity: Minor
Found in lib/universalid/extensions/active_record/base_packer.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 next_type_id has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def next_type_id(order:)
      range = 0..127

      case order
      when :asc
Severity: Minor
Found in lib/universalid/message_pack_factory.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 create_instance has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def create_instance(class_name, attributes)
        klass = Object.const_get(class_name) if Object.const_defined?(class_name)
        return nil unless klass

        record = if attributes[klass.primary_key]
Severity: Minor
Found in lib/universalid/extensions/active_record/base_unpacker.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 has_many_descendant_instances_by_association_name has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def has_many_descendant_instances_by_association_name
      has_many_associations.each_with_object({}) do |association, memo|
        relation = record.public_send(association.name)

        descendants = Set.new
Severity: Minor
Found in lib/universalid/extensions/active_record/base_packer.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 add_descendants! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def add_descendants!(hash)
      hash[DESCENDANTS_KEY] ||= {}

      has_many_descendant_instances_by_association_name.each do |name, relation|
        descendants = relation.each_with_object([]) do |descendant, memo|
Severity: Minor
Found in lib/universalid/extensions/active_record/base_packer.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 prepack has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def prepack(options)
      options.prevent_self_reference! self

      copy = each_with_object({}) do |(key, val), memo|
        next unless options.keep_keypair?(key, val)
Severity: Minor
Found in lib/universalid/refinements/hash_refinement.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 reject_keys! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def reject_keys!(hash)
      hash.delete record.class.primary_key unless prepack_options.includes[record.class.primary_key]
      foreign_key_column_names.each { |key| hash.delete(key) unless prepack_options.includes[key] }
    end
Severity: Minor
Found in lib/universalid/extensions/active_record/base_packer.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 too many return statements within this method.
Open

      return false if prepack_database_options.include_changes? && attribute_names.any? { |attr| record.changes[attr] }
Severity: Major
Found in lib/universalid/extensions/active_record/base_packer.rb - About 30 mins to fix

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

        def prepack(object, options = {})
          options = UniversalID::PrepackOptions.new(options) unless options.is_a?(UniversalID::PrepackOptions)
          object.instance_variable_set(:@_uid_prepack_options, options) unless object.frozen?
    
          return object unless object.respond_to?(:prepack)
    Severity: Minor
    Found in lib/universalid/prepacker.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize(universal_id)
          @uid = case universal_id
          when URI::UID then universal_id
          when String then URI::UID.match?(universal_id) ?
            URI::UID.parse(universal_id) :
    Severity: Minor
    Found in lib/universalid/extensions/global_id/global_id_model.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 register has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def register(type:, id: nil, recreate_pool: true, **options)
          options[:recursive] = true unless options.key?(:recursive)
          register_type(id || next_type_id(order: :desc), type, options)
          create_msgpack_pool if recreate_pool
        end
    Severity: Minor
    Found in lib/universalid/message_pack_factory.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