mongodb/mongoid

View on GitHub

Showing 236 of 236 total issues

Class HasAndBelongsToMany has 26 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 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 HasMany has 24 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 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

        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

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

              def write_attribute(name, value)
                validate_writable_field_name!(name.to_s)
          
                field_name = database_field_name(name)
          
          
          Severity: Minor
          Found in lib/mongoid/attributes.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

          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 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 extract_value has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

                def extract_value(attrs, field_name)
                  i = 1
                  num_meths = field_name.count('.') + 1
                  curr = attrs.dup
          
          
          Severity: Minor
          Found in lib/mongoid/contextual/mongo.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

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

                        def evolve(object)
                          __evolve__(object) do |obj|
                            return if obj.nil?
                            case obj
                            when ::BigDecimal
            Severity: Minor
            Found in lib/mongoid/criteria/queryable/extensions/big_decimal.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 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 define_autosave! has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

                    def self.define_autosave!(association)
                      association.inverse_class.tap do |klass|
                        save_method = :"autosave_documents_for_#{association.name}"
                        klass.send(:define_method, save_method) do
                          if before_callback_halted?
            Severity: Minor
            Found in lib/mongoid/association/referenced/auto_save.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 validate_association has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

                  def validate_association(document, attribute)
                    # grab the proxy from the instance variable directly; we don't want
                    # any loading logic to run; we just want to see if it's already
                    # been loaded.
                    proxy = document.ivar(attribute)
            Severity: Minor
            Found in lib/mongoid/validatable/associated.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 BelongsTo has 21 methods (exceeds 20 allowed). Consider refactoring.
            Open

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

              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 cleanse_localized_field_names has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
              Open

                    def cleanse_localized_field_names(name)
                      name = database_field_name(name.to_s)
              
                      klass = self
                      [].tap do |res|
              Severity: Minor
              Found in lib/mongoid/fields.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 add_logical_operator_expression has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
              Open

                      def add_logical_operator_expression(operator, op_expr)
                        unless operator.is_a?(String)
                          raise ArgumentError, "Operator must be a string: #{operator}"
                        end
              
              
              Severity: Minor
              Found in lib/mongoid/criteria/queryable/storable.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 _mongoid_expand_keys has 52 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      private def _mongoid_expand_keys(expr)
                        unless expr.is_a?(Hash)
                          raise ArgumentError, 'Argument must be a Hash'
                        end
              
              
              Severity: Major
              Found in lib/mongoid/criteria/queryable/mergeable.rb - About 2 hrs to fix
                Severity
                Category
                Status
                Source
                Language