activerecord/lib/active_record/relation/predicate_builder.rb

Summary

Maintainability
C
1 day
Test Coverage

Method expand_from_hash has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

      def expand_from_hash(attributes, &block)
        return ["1=0"] if attributes.empty?

        attributes.flat_map do |key, value|
          if key.is_a?(Array)
Severity: Minor
Found in activerecord/lib/active_record/relation/predicate_builder.rb - About 7 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 expand_from_hash has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def expand_from_hash(attributes, &block)
        return ["1=0"] if attributes.empty?

        attributes.flat_map do |key, value|
          if key.is_a?(Array)
Severity: Minor
Found in activerecord/lib/active_record/relation/predicate_builder.rb - About 1 hr to fix

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

          def convert_dot_notation_to_hash(attributes)
            attributes.each_with_object({}) do |(key, value), converted|
              if value.is_a?(Hash)
                if (existing = converted[key])
                  existing.merge!(value)
    Severity: Minor
    Found in activerecord/lib/active_record/relation/predicate_builder.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

    Avoid deeply nested control flow statements.
    Open

                    object.respond_to?(aggr_attr) ? object.public_send(aggr_attr) : object
    Severity: Major
    Found in activerecord/lib/active_record/relation/predicate_builder.rb - About 45 mins to fix

      There are no issues that match your filters.

      Category
      Status