mongodb/mongoid

View on GitHub

Showing 154 of 191 total issues

Method concat has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

          def concat(documents)
            ids, docs, inserts = {}, [], []
            documents.each do |doc|
              next unless doc
              append(doc)
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 bit has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

      def bit(operations)
        prepare_atomic_operation do |ops|
          process_atomic_operations(operations) do |field, values|
            value = attributes[field]
            values.each do |op, val|
Severity: Minor
Found in lib/mongoid/persistable/logical.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 _mongoid_expand_keys has 40 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: Minor
Found in lib/mongoid/criteria/queryable/mergeable.rb - About 1 hr to fix

    Method keys_by_type_from_docs has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

              def keys_by_type_from_docs
                inverse_type_field = @association.inverse_type
    
                @docs.each_with_object({}) do |doc, keys_by_type|
                  next unless doc.respond_to?(inverse_type_field) && doc.respond_to?(group_by_key)
    Severity: Minor
    Found in lib/mongoid/association/referenced/belongs_to/eager.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 add_logical_operator_expression has a Cognitive Complexity of 13 (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 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 first has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

          def first(opts = {})
            return documents.first if cached? && cache_loaded?
            try_cache(:first) do
              if sort = view.sort || ({ _id: 1 } unless opts[:id_sort] == :none)
                if raw_doc = view.sort(sort).limit(1).first
    Severity: Minor
    Found in lib/mongoid/contextual/mongo.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 extract_includes_list has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

          def extract_includes_list(_parent_class, *relations_list)
            relations_list.flatten.each do |relation_object|
              if relation_object.is_a?(Hash)
                relation_object.each do |relation, _includes|
                  association = _parent_class.reflect_on_association(relation)
    Severity: Minor
    Found in lib/mongoid/criteria/includable.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_relation_touch_method has a Cognitive Complexity of 12 (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 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 and has a Cognitive Complexity of 12 (exceeds 5 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

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

            def accepts_nested_attributes_for(*args)
              options = args.extract_options!.dup
              options[:autosave] = true if options[:autosave].nil?
    
              options[:reject_if] = REJECT_ALL_BLANK_PROC if options[:reject_if] == :all_blank
    Severity: Minor
    Found in lib/mongoid/attributes/nested.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 35 lines of code (exceeds 25 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

      Method add_atomic_changes has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_atomic_changes(document, name, key, mods, new_elements, old_elements)
              old = (old_elements || [])
              new = (new_elements || [])
              if new.length > old.length
                if new.first(old.length) == old
      Severity: Minor
      Found in lib/mongoid/fields/foreign_key.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 create! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

              def create!(attributes = nil, &block)
                _creating do
                  if attributes.is_a?(::Array)
                    attributes.map { |attrs| create!(attrs, &block) }
                  else
      Severity: Minor
      Found in lib/mongoid/persistable/creatable.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_setter! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.define_setter!(association)
              name = association.name
              association.inverse_class.tap do |klass|
                klass.re_define_method("#{name}=") do |object|
                  without_autobuild do
      Severity: Minor
      Found in lib/mongoid/association/accessors.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 write_attribute has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def write_attribute(name, value)
            field_name = database_field_name(name)
            if attribute_writable?(field_name)
              _assigning do
                validate_attribute_value(field_name, value)
      Severity: Minor
      Found in lib/mongoid/attributes.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 each has 30 lines of code (exceeds 25 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 1 hr to fix

        Method any_of has 28 lines of code (exceeds 25 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

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

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

                      def bind_one
                        binding do
                          check_polymorphic_inverses!(_target)
                          bind_foreign_key(_base, record_id(_target))
                          bind_polymorphic_inverse_type(_base, _target.class.name)
            Severity: Minor
            Found in lib/mongoid/association/referenced/belongs_to/binding.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 _mongoid_filter_selected_fields has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                  def _mongoid_filter_selected_fields(assoc_key)
                    return nil unless __selected_fields
            
                    projecting_assoc = false
            
            
            Severity: Minor
            Found in lib/mongoid/association/accessors.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

            Severity
            Category
            Status
            Source
            Language