hooopo/second_level_cache

View on GitHub

Showing 11 of 11 total issues

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

        def find_target
          return super unless klass.second_level_cache_enabled?
          return super if klass.default_scopes.present? || reflection.scope
          # TODO: implement cache with has_one scope

Severity: Minor
Found in lib/second_level_cache/active_record/has_one_association.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 records_for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

            def records_for(ids, &block)
              return super unless klass.second_level_cache_enabled?
              return super unless reflection.is_a?(::ActiveRecord::Reflection::BelongsToReflection)
              return super if klass.default_scopes.present? || reflection.scope
              return super if association_key_name.to_s != klass.primary_key
Severity: Minor
Found in lib/second_level_cache/active_record/preloader/legacy.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 load_records_for_keys has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

            def load_records_for_keys(keys, &block)
              ids = keys.to_a

              return super unless klass.second_level_cache_enabled?
              return super unless reflection.is_a?(::ActiveRecord::Reflection::BelongsToReflection)
Severity: Minor
Found in lib/second_level_cache/active_record/preloader/association.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 find_target has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

        def find_target
          return super unless klass.second_level_cache_enabled?
          return super if klass.default_scopes.present? || reflection.scope
          return super if reflection.active_record_primary_key.to_s != klass.primary_key

Severity: Minor
Found in lib/second_level_cache/active_record/belongs_to_association.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 order_values_can_cache? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def order_values_can_cache?
          return true if order_values.empty?
          return false unless order_values.one?
          return true if order_values.first == klass.primary_key
          return false unless order_values.first.is_a?(::Arel::Nodes::Ordering)
Severity: Minor
Found in lib/second_level_cache/active_record/finder_methods.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 first has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def first(limit = nil)
        return super if limit.to_i > 1
        return super unless cachable?
        # only have primary_key condition in where
        if where_values_hash.length == 1 && where_values_hash.key?(primary_key)
Severity: Minor
Found in lib/second_level_cache/active_record/finder_methods.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 nil unless record
Severity: Major
Found in lib/second_level_cache/active_record/belongs_to_association.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

                  return SecondLevelCache::RecordRelation.new(record_marshals) if missed_ids.empty?
    Severity: Major
    Found in lib/second_level_cache/active_record/preloader/legacy.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                    return SecondLevelCache::RecordRelation.new(record_marshals) if missed_ids.empty?
      Severity: Major
      Found in lib/second_level_cache/active_record/preloader/association.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                  return true if order_values.first.expr == klass.primary_key
        Severity: Major
        Found in lib/second_level_cache/active_record/finder_methods.rb - About 30 mins to fix

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

                def fetch_by_uniq_keys(where_values)
                  cache_key = cache_uniq_key(where_values)
                  obj_id = SecondLevelCache.cache_store.read(cache_key)
          
                  if obj_id
          Severity: Minor
          Found in lib/second_level_cache/active_record/fetch_by_uniq_key.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