mongoid/mongoid

View on GitHub

Showing 92 of 92 total issues

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 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 bit has a Cognitive Complexity of 8 (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 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 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

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

              def validate_spec(klass, spec, options)
                raise Errors::InvalidIndex.new(klass, spec, options) if !spec.is_a?(::Hash)
                spec.each_pair do |name, value|
                  next if name == :options
                  unless VALID_TYPES.include?(value)
      Severity: Minor
      Found in lib/mongoid/indexable/validators/options.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 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

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

            def should_permit?(criteria)
              if criteria.respond_to?(:permitted?)
                return criteria.permitted?
              elsif criteria.respond_to?(:each)
                criteria.each do |criterion|
      Severity: Minor
      Found in lib/mongoid/criteria/permission.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 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 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 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 serialize_attribute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def serialize_attribute(attrs, name, names, options)
            if relations.key?(name)
              value = send(name)
              attrs[name] = value ? value.serializable_hash(options) : nil
            elsif names.include?(name) && !fields.key?(name)
      Severity: Minor
      Found in lib/mongoid/serializable.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