mongodb/mongoid

View on GitHub

Showing 197 of 236 total issues

Method mongoize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def mongoize(object)
          return if object.blank?
          if Mongoid.map_big_decimal_to_decimal128
            if object.is_a?(BSON::Decimal128)
              object
Severity: Minor
Found in lib/mongoid/extensions/big_decimal.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 all has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def all(*criteria)
          if criteria.empty?
            return clone.tap do |query|
              query.reset_strategies!
            end
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 demongoize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def demongoize(object)
          return if object.nil?
          if object.is_a?(Hash)
            hash = object.slice('min', 'max', 'exclude_end', :min, :max, :exclude_end)
            unless hash.blank?
Severity: Minor
Found in lib/mongoid/extensions/range.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 merge! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def merge!(other)
          other.each_pair do |key, value|
            if value.is_a?(Hash) && self[key.to_s].is_a?(Hash)
              value = self[key.to_s].merge(value) do |_key, old_val, new_val|
                case _key.to_s
Severity: Minor
Found in lib/mongoid/criteria/queryable/selector.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 update_inverse_keys has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def update_inverse_keys(association)
          if previous_changes.has_key?(association.foreign_key)
            old, new = previous_changes[association.foreign_key]
            adds, subs = new - (old || []), (old || []) - new

Severity: Minor
Found in lib/mongoid/association/referenced/syncable.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 matches? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def matches?(exists, value, condition)
        case value
        when BSON::Binary
          value = value.data.split('').map { |n| '%02x' % n.ord }.join.to_i(16)
        end
Severity: Minor
Found in lib/mongoid/matcher/bits.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 evolve_range has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def evolve_range(key, serializer, value)
          v = value.__evolve_range__(serializer: serializer)
          assocs = []
          Fields.traverse_association_tree(key, serializers, associations, aliased_associations) do |meth, obj, is_field|
            assocs.push([meth, obj, is_field])
Severity: Minor
Found in lib/mongoid/criteria/queryable/selector.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 metadata_for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def metadata_for(model)
        metadata = {}.tap do |metadata|
          if (key_id = key_id_for(model.encrypt_metadata[:key_id], model.encrypt_metadata[:key_name_field]))
            metadata['keyId'] = key_id
          end
Severity: Minor
Found in lib/mongoid/config/encryption.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 batch_remove has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def batch_remove(docs, method = :delete)
          # If the _id is nil, we cannot use $pull and delete by searching for
          # the id. Therefore we have to use pullAll with the documents'
          # attributes.
          removals = pre_process_batch_remove(docs, method)
Severity: Minor
Found in lib/mongoid/association/embedded/batchable.rb - About 1 hr to fix

    Method matches? has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def matches?(exists, value, condition)
            case value
            when BSON::Binary
              value = value.data.split('').map { |n| '%02x' % n.ord }.join.to_i(16)
            end
    Severity: Minor
    Found in lib/mongoid/matcher/bits.rb - About 1 hr to fix

      Method set has 27 lines of code (exceeds 25 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 1 hr to fix

        Method _mongoid_filter_selected_fields has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def _mongoid_filter_selected_fields(assoc_key)
                return nil unless __selected_fields
        
                # If the list of fields was specified using #without instead of #only
                # and the provided list does not include the association, any of its
        Severity: Minor
        Found in lib/mongoid/association/accessors.rb - About 1 hr to fix

          Method not has 27 lines of code (exceeds 25 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 1 hr to fix

            Method extract_value has 27 lines of code (exceeds 25 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 1 hr to fix

              Method add_logical_operator_expression has 27 lines of code (exceeds 25 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 1 hr to fix

                Method attribute_or_path_allowed? has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def attribute_or_path_allowed?(name)
                        # Special handling for _id.
                        if name == '_id'
                          result = unless id_projection_value.nil?
                            value_inclusionary?(id_projection_value)
                Severity: Minor
                Found in lib/mongoid/attributes/projector.rb - About 1 hr to fix

                  Method matches? has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        module_function def matches?(exists, value, condition, original_operator)
                          case condition
                          when Range
                            # Since $ne invokes $eq, the exception message needs to handle
                            # both operators.
                  Severity: Minor
                  Found in lib/mongoid/matcher/eq_impl.rb - About 1 hr to fix

                    Method and has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            def and(*criteria)
                              _mongoid_flatten_arrays(criteria).inject(self.clone) do |c, new_s|
                                if new_s.is_a?(Selectable)
                                  new_s = new_s.selector
                                end
                    Severity: Minor
                    Found in lib/mongoid/criteria/queryable/selectable.rb - About 1 hr to fix

                      Method bind_one has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                                def bind_one(doc)
                                  binding do
                                    inverse_keys = try_method(doc, _association.inverse_foreign_key) unless doc.frozen?
                                    if inverse_keys
                                      record_id = inverse_record_id(doc)
                      Severity: Minor
                      Found in lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb - About 55 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 attribute_or_path_allowed? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def attribute_or_path_allowed?(name)
                              # Special handling for _id.
                              if name == '_id'
                                result = unless id_projection_value.nil?
                                  value_inclusionary?(id_projection_value)
                      Severity: Minor
                      Found in lib/mongoid/attributes/projector.rb - About 55 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