Class RecordCache
has 27 methods (exceeds 20 allowed). Consider refactoring. Open
class RecordCache
attr_accessor :scope
attr_accessor :exclude_types
attr_accessor :user_ids
attr_accessor :current_user_id
File record_cache.rb
has 268 lines of code (exceeds 250 allowed). Consider refactoring. Open
class RecordCache
attr_accessor :scope
attr_accessor :exclude_types
attr_accessor :user_ids
attr_accessor :current_user_id
Method for_collection
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.for_collection(collection, user_id, exclude_types = [])
obj = self.new
obj.exclude_types = exclude_types
obj.current_user_id = user_id
return obj unless item = collection.to_a.first
Method add_events_complete
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def add_events_complete(collection)
ids = {discussion: [], comment: [], group: [], poll: []}.with_indifferent_access
Event.includes(:eventable).where(id: collection.map(&:id)).each do |e|
- 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 add_events
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_events(collection)
return [] if exclude_types.include?('event')
scope[:events_by_id] ||= {}
scope[:events_by_kind_and_eventable_id] ||= {}
- 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 add_stances
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_stances(collection)
return [] if exclude_types.include?('stance')
scope[:stances_by_id] ||= {}
scope[:my_stances_by_poll_id] ||= {}
collection.each do |stance|
- 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"