loomio/loomio

View on GitHub
app/services/record_cache.rb

Summary

Maintainability
C
1 day
Test Coverage

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
Severity: Minor
Found in app/services/record_cache.rb - About 3 hrs to fix

    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
    Severity: Minor
    Found in app/services/record_cache.rb - About 2 hrs to fix

      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
      Severity: Major
      Found in app/services/record_cache.rb - About 2 hrs to fix

        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|
        Severity: Minor
        Found in app/services/record_cache.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 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] ||= {}
        
        
        Severity: Minor
        Found in app/services/record_cache.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 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|
        Severity: Minor
        Found in app/services/record_cache.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