lib/active_model_cachers/active_record/attr_model.rb
Method query_association
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
Open
def query_association(binding, id)
return binding.association(@column).load_target if binding.is_a?(::ActiveRecord::Base)
id = @reflect.active_record.where(id: id).limit(1).pluck(foreign_key).first if foreign_key != 'id'
case
when collection? ; return id ? @reflect.klass.where(@reflect.foreign_key => id).to_a : []
- 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 foreign_key
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def foreign_key(reverse: false)
return @foreign_key if @foreign_key
return if not association?
# key may be symbol if specify foreign_key in association options
return @reflect.chain.last.foreign_key.to_s if reverse and join_table
- 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"