mongodb/mongoid

View on GitHub

Showing 191 of 191 total issues

Method define_callbacks! has a Cognitive Complexity of 47 (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 selectable.rb has 398 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

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

        class Mongo
          extend Forwardable
          include Enumerable
          include Aggregable::Mongo
          include Atomic
    Severity: Minor
    Found in lib/mongoid/contextual/mongo.rb - About 5 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 _mongoid_expand_keys has a Cognitive Complexity of 30 (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 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 Proxy has 34 methods (exceeds 20 allowed). Consider refactoring.
      Open

              class Proxy < Association::Many
                include Batchable
      
                # Appends a document or array of documents to the association. Will set
                # the parent and update the index in the process.
      Severity: Minor
      Found in lib/mongoid/association/embedded/embeds_many/proxy.rb - About 4 hrs to fix

        Class Criteria has 34 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

          Method extract_attribute has a Cognitive Complexity of 29 (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 32 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

            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 Proxy has 29 methods (exceeds 20 allowed). Consider refactoring.
            Open

                    class Proxy < Association::Many
                      extend Forwardable
            
                      def_delegator :criteria, :count
                      def_delegators :_target, :first, :in_memory, :last, :reset, :uniq
            Severity: Minor
            Found in lib/mongoid/association/referenced/has_many/proxy.rb - About 3 hrs to fix

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

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

                Class Enumerable has 29 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

                  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

                    File benchmark.rb has 285 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

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

                      Class HasAndBelongsToMany has 25 methods (exceeds 20 allowed). Consider refactoring.
                      Open

                            class HasAndBelongsToMany
                              include Relatable
                              include Buildable
                      
                              # The options available for this type of association, in addition to the
                      Severity: Minor
                      Found in lib/mongoid/association/referenced/has_and_belongs_to_many.rb - About 2 hrs to fix

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

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

                          Method each has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                          Open

                                def each
                                  if system_collection? || !QueryCache.enabled? || (respond_to?(:write?, true) && write?)
                                    super
                                  else
                                    @cursor = nil
                          Severity: Minor
                          Found in lib/mongoid/query_cache.rb - About 2 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 cascadable_children has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def cascadable_children(kind, children = Set.new)
                                embedded_relations.each_pair do |name, association|
                                  next unless association.cascading_callbacks?
                                  without_autobuild do
                                    delayed_pulls = delayed_atomic_pulls[name]
                          Severity: Minor
                          Found in lib/mongoid/interceptable.rb - About 2 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

                          Severity
                          Category
                          Status
                          Source
                          Language