hooopo/second_level_cache

View on GitHub
lib/second_level_cache/active_record/finder_methods.rb

Summary

Maintainability
A
1 hr
Test Coverage

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

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

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

    There are no issues that match your filters.

    Category
    Status