activerecord/lib/active_record/relation/calculations.rb

Summary

Maintainability
F
3 days
Test Coverage

File calculations.rb has 386 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "active_support/core_ext/enumerable"

module ActiveRecord
  # = Active Record \Calculations
  module Calculations
Severity: Minor
Found in activerecord/lib/active_record/relation/calculations.rb - About 5 hrs to fix

    Method calculate has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        def calculate(operation, column_name)
          operation = operation.to_s.downcase
    
          if @none
            case operation
    Severity: Minor
    Found in activerecord/lib/active_record/relation/calculations.rb - About 4 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 execute_grouped_calculation has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

          def execute_grouped_calculation(operation, column_name, distinct) # :nodoc:
            group_fields = group_values
            group_fields = group_fields.uniq if group_fields.size > 1
    
            if group_fields.size == 1 && group_fields.first.respond_to?(:to_sym)
    Severity: Minor
    Found in activerecord/lib/active_record/relation/calculations.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 execute_grouped_calculation has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def execute_grouped_calculation(operation, column_name, distinct) # :nodoc:
            group_fields = group_values
            group_fields = group_fields.uniq if group_fields.size > 1
    
            if group_fields.size == 1 && group_fields.first.respond_to?(:to_sym)
    Severity: Major
    Found in activerecord/lib/active_record/relation/calculations.rb - About 2 hrs to fix

      Method perform_calculation has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

            def perform_calculation(operation, column_name)
              operation = operation.to_s.downcase
      
              # If #count is used with #distinct (i.e. `relation.distinct.count`) it is
              # considered distinct.
      Severity: Minor
      Found in activerecord/lib/active_record/relation/calculations.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 pluck has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def pluck(*column_names)
            if @none
              if @async
                return Promise::Complete.new([])
              else
      Severity: Minor
      Found in activerecord/lib/active_record/relation/calculations.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 execute_simple_calculation has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

            def execute_simple_calculation(operation, column_name, distinct) # :nodoc:
              if operation == "count" && (column_name == :all && distinct || has_limit_or_offset?)
                # Shortcut when limit is zero.
                return 0 if limit_value == 0
      
      
      Severity: Minor
      Found in activerecord/lib/active_record/relation/calculations.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 pluck has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def pluck(*column_names)
            if @none
              if @async
                return Promise::Complete.new([])
              else
      Severity: Minor
      Found in activerecord/lib/active_record/relation/calculations.rb - About 1 hr to fix

        Method ids has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def ids
              primary_key_array = Array(primary_key)
        
              if loaded?
                result = records.map do |record|
        Severity: Minor
        Found in activerecord/lib/active_record/relation/calculations.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 execute_simple_calculation has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def execute_simple_calculation(operation, column_name, distinct) # :nodoc:
                if operation == "count" && (column_name == :all && distinct || has_limit_or_offset?)
                  # Shortcut when limit is zero.
                  return 0 if limit_value == 0
        
        
        Severity: Minor
        Found in activerecord/lib/active_record/relation/calculations.rb - About 1 hr to fix

          Method ids has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def ids
                primary_key_array = Array(primary_key)
          
                if loaded?
                  result = records.map do |record|
          Severity: Minor
          Found in activerecord/lib/active_record/relation/calculations.rb - About 1 hr to fix

            There are no issues that match your filters.

            Category
            Status