mongodb/mongoid

View on GitHub

Showing 197 of 236 total issues

Method add_atomic_changes has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

      def add_atomic_changes(document, name, key, mods, new, old)
Severity: Minor
Found in lib/mongoid/fields/standard.rb - About 45 mins to fix

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

          def evolve(object)
            if object_id_field? || object.is_a?(Document)
              if association.polymorphic?
                association.convert_to_foreign_key(object)
              elsif object.is_a?(Document) && object.respond_to?(association.primary_key)
    Severity: Minor
    Found in lib/mongoid/fields/foreign_key.rb - About 45 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 one_matches? has a Cognitive Complexity of 8 (exceeds 5 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 45 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 preload has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def preload(associations, docs)
            assoc_map = associations.group_by(&:inverse_class_name)
            docs_map = {}
            queue = [ klass.to_s ]
    
    
    Severity: Minor
    Found in lib/mongoid/association/eager_loadable.rb - About 45 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 process_attributes has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def process_attributes(attrs = nil)
            attrs ||= {}
            unless attrs.empty?
              attrs = sanitize_for_mass_assignment(attrs)
              attrs.each_pair do |key, value|
    Severity: Minor
    Found in lib/mongoid/attributes/processing.rb - About 45 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 setters has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def setters
          mods = {}
          changes.each_pair do |name, changes|
            next unless changes
    
    
    Severity: Minor
    Found in lib/mongoid/changeable.rb - About 45 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 prepare_ids_for_find has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def prepare_ids_for_find(args)
            args.flat_map do |arg|
              case arg
              when Array, Set
                prepare_ids_for_find(arg)
    Severity: Minor
    Found in lib/mongoid/criteria/findable.rb - About 45 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 _mongoid_run_child_before_callbacks has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _mongoid_run_child_before_callbacks(kind, children: [], callback_list: [])
          children.each do |child|
            chain = child.__callbacks[child_callback_type(kind, child)]
            env = ActiveSupport::Callbacks::Filters::Environment.new(child, false, nil)
            next_sequence = compile_callbacks(chain)
    Severity: Minor
    Found in lib/mongoid/interceptable.rb - About 45 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 properties_for_fields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def properties_for_fields(model)
            model.fields.each_with_object({}) do |(name, field), props|
              next unless field.is_a?(Mongoid::Fields::Encrypted)
    
              props[name] = {
    Severity: Minor
    Found in lib/mongoid/config/encryption.rb - About 45 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 documents_for_iteration has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def documents_for_iteration
            if @documents_loader
              if @documents_loader.started?
                @documents_loader.value!
              else
    Severity: Minor
    Found in lib/mongoid/contextual/mongo.rb - About 45 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

    Consider simplifying this complex logical expression.
    Open

                    if v.is_a?(Hash) &&
                      v.length == 1 &&
                      (new_k = v.keys.first).start_with?('$') &&
                      (existing_kv = c.selector[k]).is_a?(Hash) &&
                      !existing_kv.key?(new_k) &&
    Severity: Major
    Found in lib/mongoid/criteria/queryable/selectable.rb - About 40 mins to fix

      Method add_key has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

                  def add_key(name, strategy, operator, additional = nil, &block)
      Severity: Minor
      Found in lib/mongoid/criteria/queryable/extensions/symbol.rb - About 35 mins to fix

        Method key has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                def key(name, strategy, operator, additional = nil, &block)
        Severity: Minor
        Found in lib/mongoid/criteria/queryable/macroable.rb - About 35 mins to fix

          Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  def initialize(name, strategy, operator, expanded = nil, &block)
          Severity: Minor
          Found in lib/mongoid/criteria/queryable/key.rb - About 35 mins to fix

            Method build_auto_encryption_options has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def build_auto_encryption_options(opts, database)
                    return nil unless opts[:auto_encryption_options]
            
                    opts[:auto_encryption_options].dup.tap do |auto_encryption_options|
                      if auto_encryption_options.key?(:schema_map)
            Severity: Minor
            Found in lib/mongoid/clients/factory.rb - About 35 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 define_relation_touch_method has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def define_relation_touch_method(name, association)
                  relation_classes = if association.polymorphic?
                                       association.send(:inverse_association_classes)
                                     else
                                       [ association.relation_class ]
            Severity: Minor
            Found in lib/mongoid/touchable.rb - About 35 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 inverse_foreign_key has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                    def inverse_foreign_key
                      if @options.key?(:inverse_foreign_key)
                        @options[:inverse_foreign_key]
                      elsif @options.key?(:inverse_of)
                        inverse_of ? "#{inverse_of.to_s.singularize}#{FOREIGN_KEY_SUFFIX}" : nil
            Severity: Minor
            Found in lib/mongoid/association/referenced/has_and_belongs_to_many.rb - About 35 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 selection has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                    def selection(criterion = nil)
                      clone.tap do |query|
                        if criterion
                          criterion.each_pair do |field, value|
                            yield(query.selector, field.is_a?(Key) ? field : field.to_s, value)
            Severity: Minor
            Found in lib/mongoid/criteria/queryable/selectable.rb - About 35 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 substitute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

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

                    def check_for_id_violation!
                      # look for the basic criteria of an update (see #update?)
                      return unless existing&.persisted? && !destroyable?
            
                      # if the id is either absent, or if it equals the existing record's
            Severity: Minor
            Found in lib/mongoid/association/nested/one.rb - About 35 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

            Severity
            Category
            Status
            Source
            Language