mongodb/mongoid

View on GitHub

Showing 197 of 236 total issues

Class Mongo has 62 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Mongo
      extend Forwardable
      include Enumerable
      include Aggregable::Mongo
      include Atomic
Severity: Major
Found in lib/mongoid/contextual/mongo.rb - About 1 day to fix

    Method _mongoid_expand_keys has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
    Open

            private def _mongoid_expand_keys(expr)
              unless expr.is_a?(Hash)
                raise ArgumentError, 'Argument must be a Hash'
              end
    
    
    Severity: Minor
    Found in lib/mongoid/criteria/queryable/mergeable.rb - About 1 day 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

    Class Memory has 51 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Memory
          include Enumerable
          include Aggregable::Memory
          include Association::EagerLoadable
          include Queryable
    Severity: Major
    Found in lib/mongoid/contextual/memory.rb - About 7 hrs to fix

      Method define_callbacks! has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
      Open

              def self.define_callbacks!(association)
                name = association.name
                cache_column = association.counter_cache_column_name.to_sym
      
                association.inverse_class.tap do |klass|
      Severity: Minor
      Found in lib/mongoid/association/referenced/counter_cache.rb - About 7 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 matches? has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
      Open

            module_function def matches?(exists, value, condition)
              if condition.is_a?(Hash)
                condition.all? do |k, cond_v|
                  k = k.to_s
                  if k.start_with?('$')
      Severity: Minor
      Found in lib/mongoid/matcher/field_expression.rb - About 6 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

      File mongo.rb has 409 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'mongoid/atomic_update_preparer'
      require "mongoid/contextual/mongo/documents_loader"
      require "mongoid/contextual/atomic"
      require "mongoid/contextual/aggregable/mongo"
      require "mongoid/contextual/command"
      Severity: Minor
      Found in lib/mongoid/contextual/mongo.rb - About 5 hrs to fix

        File selectable.rb has 403 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        module Mongoid
          class Criteria
            module Queryable
        
              # An queryable selectable is selectable, in that it has the ability to select
        Severity: Minor
        Found in lib/mongoid/criteria/queryable/selectable.rb - About 5 hrs to fix

          File fields.rb has 372 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require "mongoid/fields/standard"
          require "mongoid/fields/encrypted"
          require "mongoid/fields/foreign_key"
          require "mongoid/fields/localized"
          require "mongoid/fields/validators"
          Severity: Minor
          Found in lib/mongoid/fields.rb - About 4 hrs to fix

            Method shard_collections has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
            Open

                  def shard_collections(models = ::Mongoid.models)
                    models.map do |model|
                      next if model.shard_config.nil?
            
                      if model.embedded? && !model.cyclic?
            Severity: Minor
            Found in lib/mongoid/tasks/database.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 extract_attribute has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
            Open

                module_function def extract_attribute(document, key)
                  if document.respond_to?(:as_attributes, true)
                    # If a document has hash fields, as_attributes would keep those fields
                    # as Hash instances which do not offer indifferent access.
                    # Convert to BSON::Document to get indifferent access on hash fields.
            Severity: Minor
            Found in lib/mongoid/matcher.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

            Class Criteria has 33 methods (exceeds 20 allowed). Consider refactoring.
            Open

              class Criteria
                module Queryable
            
                  # An queryable selectable is selectable, in that it has the ability to select
                  # document from the database. The selectable module brings all functionality
            Severity: Minor
            Found in lib/mongoid/criteria/queryable/selectable.rb - About 4 hrs to fix

              Class Criteria has 33 methods (exceeds 20 allowed). Consider refactoring.
              Open

                class Criteria
                  include Enumerable
              
                  # @api private
                  alias :_enumerable_find :find
              Severity: Minor
              Found in lib/mongoid/criteria.rb - About 4 hrs to fix

                Class Proxy has 30 methods (exceeds 20 allowed). Consider refactoring.
                Open

                        class Proxy < Association::Many
                          extend Forwardable
                
                          # class-level methods for HasMany::Proxy
                          module ClassMethods
                Severity: Minor
                Found in lib/mongoid/association/referenced/has_many/proxy.rb - About 3 hrs to fix

                  Class Enumerable has 30 methods (exceeds 20 allowed). Consider refactoring.
                  Open

                          class Enumerable
                            extend Forwardable
                            include ::Enumerable
                  
                            # The three main instance variables are collections of documents.
                  Severity: Minor
                  Found in lib/mongoid/association/referenced/has_many/enumerable.rb - About 3 hrs to fix

                    Method set has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def set(setters)
                            prepare_atomic_operation do |ops|
                              process_atomic_operations(setters) do |field, value|
                    
                                field_seq = field.to_s.split('.')
                    Severity: Minor
                    Found in lib/mongoid/persistable/settable.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

                    Class None has 28 methods (exceeds 20 allowed). Consider refactoring.
                    Open

                        class None
                          include Enumerable
                          include Aggregable::None
                          include Queryable
                    
                    
                    Severity: Minor
                    Found in lib/mongoid/contextual/none.rb - About 3 hrs to fix

                      File profile.rb has 304 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      require "perftools"
                      require "mongoid"
                      require "./perf/models"
                      
                      Mongoid.connect_to("mongoid_perf_test")
                      Severity: Minor
                      Found in perf/profile.rb - About 3 hrs to fix

                        Method traverse_association_tree has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                        Open

                              def traverse_association_tree(key, fields, associations, aliased_associations)
                                klass = nil
                                field = nil
                                key.split('.').each_with_index do |meth, i|
                                  fs = i == 0 ? fields : klass&.fields
                        Severity: Minor
                        Found in lib/mongoid/fields.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 retrieve_value_at_path has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                        Open

                              def retrieve_value_at_path(document, field_path)
                                return if field_path.blank? || !document
                                segment, remaining = field_path.to_s.split('.', 2)
                        
                                curr = if document.is_a?(Document)
                        Severity: Minor
                        Found in lib/mongoid/contextual/memory.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

                        File memory.rb has 293 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        require "mongoid/contextual/aggregable/memory"
                        require "mongoid/association/eager_loadable"
                        
                        module Mongoid
                          module Contextual
                        Severity: Minor
                        Found in lib/mongoid/contextual/memory.rb - About 3 hrs to fix
                          Severity
                          Category
                          Status
                          Source
                          Language