mongoid/mongoid

View on GitHub

Showing 92 of 92 total issues

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

      def matches?(conditions)
        conditions.each do |condition|
          res = true
          condition.keys.each do |k|
            key = k
Severity: Minor
Found in lib/mongoid/matchable/or.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 each has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def each
        if system_collection? || !QueryCache.enabled?
          super
        else
          key = cache_key
Severity: Minor
Found in lib/mongoid/query_cache.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 add_atomic_changes has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

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

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

          def mongoize_for(operator, klass, key, value)
            field = klass.fields[key.to_s]
            if field
              val = field.mongoize(value)
              if Mongoid::Persistable::LIST_OPERATIONS.include?(operator) && field.resizable?
    Severity: Minor
    Found in lib/mongoid/extensions/hash.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

    Avoid deeply nested control flow statements.
    Open

                          relation.with(options).save if changed_for_autosave?(relation)
    Severity: Major
    Found in lib/mongoid/relations/auto_save.rb - About 45 mins to fix

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

                def purge
                  unless __metadata.destructive?
                    nullify
                  else
                    after_remove_error = nil
        Severity: Minor
        Found in lib/mongoid/relations/referenced/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 reference has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def reference(metadata, type = Object)
                  polymorph(metadata).cascade(metadata)
                  if metadata.relation.stores_foreign_key?
                    key = metadata.foreign_key
                    field(
        Severity: Minor
        Found in lib/mongoid/relations/macros.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 remove_not_in has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def remove_not_in(ids)
                  removed = criteria.not_in(_id: ids)
                  if __metadata.destructive?
                    removed.delete_all
                  else
        Severity: Minor
        Found in lib/mongoid/relations/referenced/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 delete has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def delete(document)
                  doc = (_loaded.delete(document._id) || _added.delete(document._id))
                  unless doc
                    if _unloaded && _unloaded.where(_id: document._id).exists?
                      yield(document) if block_given?
        Severity: Minor
        Found in lib/mongoid/relations/targets/enumerable.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 inspect_fields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def inspect_fields
              fields.map do |name, field|
                unless name == "_id"
                  as = field.options[:as]
                  "#{name}#{as ? "(#{as})" : nil}: #{@attributes[name].inspect}"
        Severity: Minor
        Found in lib/mongoid/inspectable.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 add_to_set has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def add_to_set(adds)
                prepare_atomic_operation do |ops|
                  process_atomic_operations(adds) do |field, value|
                    existing = send(field) || (attributes[field] ||= [])
                    values = [ value ].flatten(1)
        Severity: Minor
        Found in lib/mongoid/persistable/pushable.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 remove_indexes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def remove_indexes
                indexed_database_names.each do |database|
                  collection = with(read: { mode: :primary }, database: database).collection
                  begin
                    collection.indexes.each do |spec|
        Severity: Minor
        Found in lib/mongoid/indexable.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 validate_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def validate_name(klass, name, options)
                  [name, "#{name}?".to_sym, "#{name}=".to_sym].each do |n|
                    if Mongoid.destructive_fields.include?(n)
                      raise Errors::InvalidField.new(klass, n)
                    end
        Severity: Minor
        Found in lib/mongoid/fields/validators/macro.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 matcher has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def matcher(document, key, value)
                if value.is_a?(Hash)
                  matcher = MATCHERS[value.keys.first]
                  if matcher
                    matcher.new(extract_attribute(document, key))
        Severity: Minor
        Found in lib/mongoid/matchable.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 create_indexes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def create_indexes(models = ::Mongoid.models)
                models.each do |model|
                  next if model.index_specifications.empty?
                  if !model.embedded? || model.cyclic?
                    model.create_indexes
        Severity: Minor
        Found in lib/mongoid/tasks/database.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 validate_each has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def validate_each(document, attribute, value)
                begin
                  document.begin_validate
                  valid = Array.wrap(value).collect do |doc|
                    if doc.nil? || doc.flagged_for_destroy?
        Severity: Minor
        Found in lib/mongoid/validatable/associated.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 process_attributes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

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

            def initialize(attrs = nil)
              _building do
                @new_record = true
                @attributes ||= {}
                with(self.class.persistence_options)
        Severity: Minor
        Found in lib/mongoid/document.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 validate_attribute_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_attribute_value(access, value)
              return unless fields[access] && value
              validatable_types = [ Hash, Array ]
              if validatable_types.include? fields[access].type
                unless value.is_a? fields[access].type
        Severity: Minor
        Found in lib/mongoid/attributes.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