File reflection.rb
has 845 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "active_support/core_ext/string/filters"
module ActiveRecord
# = Active Record Reflection
module Reflection # :nodoc:
Class AssociationReflection
has 43 methods (exceeds 20 allowed). Consider refactoring. Open
class AssociationReflection < MacroReflection # :nodoc:
def compute_class(name)
if polymorphic?
raise ArgumentError, "Polymorphic associations do not support computing the class."
end
Class AbstractReflection
has 27 methods (exceeds 20 allowed). Consider refactoring. Open
class AbstractReflection # :nodoc:
def initialize
@class_name = nil
@counter_cache_column = nil
@inverse_of = nil
Class ThroughReflection
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
class ThroughReflection < AbstractReflection # :nodoc:
delegate :foreign_key, :foreign_type, :association_foreign_key, :join_id_for, :type,
:active_record_primary_key, :join_foreign_key, to: :source_reflection
def initialize(delegate_reflection)
Method automatic_inverse_of
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def automatic_inverse_of
if can_find_inverse_of_automatically?(self)
inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_record.name.demodulize).to_sym
begin
- Read upRead up
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 check_validity!
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def check_validity!
if through_reflection.nil?
raise HasManyThroughAssociationNotFoundError.new(active_record, self)
end
- Read upRead up
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 derive_fk_query_constraints
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def derive_fk_query_constraints(foreign_key)
primary_query_constraints = active_record.query_constraints_list
owner_pk = active_record.primary_key
if primary_query_constraints.size > 2
Method compute_class
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def compute_class(name)
if polymorphic?
raise ArgumentError, "Polymorphic associations do not support computing the class."
end
- Read upRead up
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 check_validity!
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def check_validity!
if through_reflection.nil?
raise HasManyThroughAssociationNotFoundError.new(active_record, self)
end
Method inverse_which_updates_counter_cache
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def inverse_which_updates_counter_cache
unless @inverse_which_updates_counter_cache_defined
if counter_cache_column
inverse_candidates = inverse_of ? [inverse_of] : klass.reflect_on_all_associations(:belongs_to)
@inverse_which_updates_counter_cache = inverse_candidates.find do |inverse|
- Read upRead up
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 automatic_inverse_of
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def automatic_inverse_of
if can_find_inverse_of_automatically?(self)
inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_record.name.demodulize).to_sym
begin
Method check_validity!
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def check_validity!
check_validity_of_inverse!
if !polymorphic? && (klass.composite_primary_key? || active_record.composite_primary_key?)
if (has_one? || collection?) && Array(active_record_primary_key).length != Array(foreign_key).length
- Read upRead up
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 association_primary_key
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def association_primary_key(klass = nil)
if primary_key = options[:primary_key]
@association_primary_key ||= if primary_key.is_a?(Array)
primary_key.map { |pk| pk.to_s.freeze }.freeze
else
- Read upRead up
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 create
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def create(macro, name, scope, options, ar)
Method derive_fk_query_constraints
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def derive_fk_query_constraints(foreign_key)
primary_query_constraints = active_record.query_constraints_list
owner_pk = active_record.primary_key
if primary_query_constraints.size > 2
- Read upRead up
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 check_validity_of_inverse!
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def check_validity_of_inverse!
if !polymorphic? && has_inverse?
if inverse_of.nil?
raise InverseOfAssociationNotFoundError.new(self)
end
- Read upRead up
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"