activerecord/lib/active_record/relation/finder_methods.rb

Summary

Maintainability
C
1 day
Test Coverage

File finder_methods.rb has 329 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "active_support/core_ext/string/filters"

module ActiveRecord
  module FinderMethods
    ONE_AS_ONE = "1 AS one"
Severity: Minor
Found in activerecord/lib/active_record/relation/finder_methods.rb - About 3 hrs to fix

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

          def find_nth_with_limit(index, limit)
            if loaded?
              records[index, limit] || []
            else
              relation = ordered_relation
    Severity: Minor
    Found in activerecord/lib/active_record/relation/finder_methods.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 find_some has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def find_some(ids)
            return find_some_ordered(ids) unless order_values.present?
    
            relation = where(primary_key => ids)
            relation = relation.select(table[primary_key]) unless select_values.empty?
    Severity: Minor
    Found in activerecord/lib/active_record/relation/finder_methods.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 find_with_ids has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def find_with_ids(*ids)
            raise UnknownPrimaryKey.new(@klass) if primary_key.nil?
    
            expects_array = if klass.composite_primary_key?
              ids.first.first.is_a?(Array)
    Severity: Minor
    Found in activerecord/lib/active_record/relation/finder_methods.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 construct_relation_for_exists has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def construct_relation_for_exists(conditions)
            conditions = sanitize_forbidden_attributes(conditions)
    
            if distinct_value && offset_value
              relation = except(:order).limit!(1)
    Severity: Minor
    Found in activerecord/lib/active_record/relation/finder_methods.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 raise_record_not_found_exception! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def raise_record_not_found_exception!(ids = nil, result_size = nil, expected_size = nil, key = primary_key, not_found_ids = nil) # :nodoc:
          conditions = " [#{arel.where_sql(klass)}]" unless where_clause.empty?
    
          name = @klass.name
    
    
    Severity: Minor
    Found in activerecord/lib/active_record/relation/finder_methods.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 include? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def include?(record)
          # The existing implementation relies on receiving an Active Record instance as the input parameter named record.
          # Any non-Active Record object passed to this implementation is guaranteed to return `false`.
          return false unless record.is_a?(klass)
    
    
    Severity: Minor
    Found in activerecord/lib/active_record/relation/finder_methods.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 raise_record_not_found_exception! has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def raise_record_not_found_exception!(ids = nil, result_size = nil, expected_size = nil, key = primary_key, not_found_ids = nil) # :nodoc:
    Severity: Minor
    Found in activerecord/lib/active_record/relation/finder_methods.rb - About 35 mins to fix

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

            def find_nth_from_last(index)
              if loaded?
                records[-index]
              else
                relation = ordered_relation
      Severity: Minor
      Found in activerecord/lib/active_record/relation/finder_methods.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 exists? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def exists?(conditions = :none)
            return false if @none
      
            if Base === conditions
              raise ArgumentError, <<-MSG.squish
      Severity: Minor
      Found in activerecord/lib/active_record/relation/finder_methods.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

      There are no issues that match your filters.

      Category
      Status