mongodb/mongoid

View on GitHub

Showing 154 of 191 total issues

Class Modifiers has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Modifiers < Hash

      # Add the atomic $addToSet modifiers to the hash.
      #
      # @example Add the $addToSet modifiers.
Severity: Minor
Found in lib/mongoid/atomic/modifiers.rb - About 2 hrs to fix

    Class HasMany has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

          class HasMany
            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_many.rb - About 2 hrs to fix

      Method undefined_indexes has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

            def undefined_indexes(models = ::Mongoid.models)
              undefined_by_model = {}
      
              models.each do |model|
                unless model.embedded?
      Severity: Minor
      Found in lib/mongoid/tasks/database.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 matches? has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

            module_function def matches?(document, expr)
              if expr.nil?
                raise Errors::InvalidQuery, "Nil condition in expression context"
              end
              unless Hash === expr
      Severity: Minor
      Found in lib/mongoid/matcher/expression.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 not has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

              def not(*criteria)
                if criteria.empty?
                  dup.tap { |query| query.negating = true }
                else
                  criteria.compact.inject(self.clone) do |c, new_s|
      Severity: Minor
      Found in lib/mongoid/criteria/queryable/selectable.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 process_localized_attributes has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def process_localized_attributes(klass, attrs)
            klass.localized_fields.keys.each do |name|
              if value = attrs.delete(name)
                attrs["#{name}_translations"] = value
              end
      Severity: Minor
      Found in lib/mongoid/copyable.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

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

        class Criteria
          module Queryable
      
            # The optional module includes all behavior that has to do with extra
            # options surrounding queries, like skip, limit, sorting, etc.
      Severity: Minor
      Found in lib/mongoid/criteria/queryable/optional.rb - About 2 hrs to fix

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

        require "mongoid/contextual/atomic"
        require "mongoid/contextual/aggregable/mongo"
        require "mongoid/contextual/command"
        require "mongoid/contextual/geo_near"
        require "mongoid/contextual/map_reduce"
        Severity: Minor
        Found in lib/mongoid/contextual/mongo.rb - About 2 hrs to fix

          Method matches? has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

                module_function def matches?(exists, value, condition)
                  unless Hash === condition
                    raise Errors::InvalidQuery, "$elemMatch requires a Hash operand: #{Errors::InvalidQuery.truncate_expr(condition)}"
                  end
                  if Array === value && !value.empty?
          Severity: Minor
          Found in lib/mongoid/matcher/elem_match.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 atomically has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              def atomically(join_context: nil)
                join_context = Mongoid.join_contexts if join_context.nil?
                call_depth = @atomic_depth ||= 0
                has_own_context = call_depth.zero? || !join_context
                @atomic_updates_to_execute_stack ||= []
          Severity: Minor
          Found in lib/mongoid/persistable.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 from_db has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              def from_db(klass, attributes = nil, criteria = nil, selected_fields = nil)
                if criteria
                  selected_fields ||= criteria.options[:fields]
                end
                type = (attributes || {})[klass.discriminator_key]
          Severity: Minor
          Found in lib/mongoid/factory.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 extract_attribute has 50 lines of code (exceeds 25 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 2 hrs to fix

            Method matches? has 50 lines of code (exceeds 25 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 2 hrs to fix

              Method one_matches? has 49 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    module_function def one_matches?(exists, value, condition)
                      case condition
                      when 1
                        # Double
                        Float === value
              Severity: Minor
              Found in lib/mongoid/matcher/type.rb - About 1 hr to fix

                Method substitute has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                          def substitute(replacement)
                            if replacement != self
                              if _assigning?
                                _base.add_atomic_unset(_target) unless replacement
                              else
                Severity: Minor
                Found in lib/mongoid/association/embedded/embeds_one/proxy.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 pre_process_batch_insert has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                        def pre_process_batch_insert(docs)
                          docs.map do |doc|
                            next unless doc
                            append(doc)
                            if persistable? && !_assigning?
                Severity: Minor
                Found in lib/mongoid/association/embedded/batchable.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 any_of has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                        def any_of(*criteria)
                          criteria = _mongoid_flatten_arrays(criteria)
                          case criteria.length
                          when 0
                            clone
                Severity: Minor
                Found in lib/mongoid/criteria/queryable/selectable.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 nullify has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                          def nullify(replacement = [])
                            _target.each do |doc|
                              execute_callback :before_remove, doc
                            end
                            unless _association.forced_nil_inverse?
                Severity: Minor
                Found in lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.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 define_callbacks! has 45 lines of code (exceeds 25 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 1 hr to fix

                  Method shard_collections has 45 lines of code (exceeds 25 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 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language