mongoid/mongoid

View on GitHub

Showing 86 of 92 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/relations/referenced/many_to_many.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_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 write_attribute has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def write_attribute(name, value)
      access = database_field_name(name.to_s)
      if attribute_writable?(access)
        _assigning do
          validate_attribute_value(access, 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 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 bind_one has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

          def bind_one
            binding do
              check_inverses!(target)
              bind_foreign_key(base, record_id(target))
              bind_polymorphic_inverse_type(base, target.class.name)
Severity: Minor
Found in lib/mongoid/relations/bindings/referenced/in.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 process_attributes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

          def process_attributes(parent, attrs)
            return if reject?(parent, attrs)
            if id = attrs.extract_id
              first = existing.first
              converted = first ? convert_id(first.class, id) : id
Severity: Minor
Found in lib/mongoid/relations/builders/nested_attributes/many.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(meta)
        if changes.has_key?(meta.foreign_key)
          old, new = changes[meta.foreign_key]
          adds, subs = new - (old || []), (old || []) - new

Severity: Minor
Found in lib/mongoid/relations/synchronization.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 as_document has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def as_document
      return attributes if frozen?
      embedded_relations.each_pair do |name, meta|
        without_autobuild do
          relation, stored = send(name), meta.store_as
Severity: Minor
Found in lib/mongoid/document.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 __consolidate__ has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def __consolidate__(klass)
        consolidated = {}
        each_pair do |key, value|
          if key =~ /\$/
            value.each_pair do |_key, _value|
Severity: Minor
Found in lib/mongoid/extensions/hash.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 a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

        def nullify
          target.each do |doc|
            execute_callback :before_remove, doc
          end
          unless __metadata.forced_nil_inverse?
Severity: Minor
Found in lib/mongoid/relations/referenced/many_to_many.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 validate_each has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def validate_each(document, attribute, value)
        field = document.fields[document.database_field_name(attribute)]
        if field.try(:localized?) && !value.blank?
          value.each_pair do |_locale, _value|
            document.errors.add(
Severity: Minor
Found in lib/mongoid/validatable/presence.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 pre_process_batch_remove has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

        def pre_process_batch_remove(docs, method)
          docs.map do |doc|
            self.path = doc.atomic_path unless path
            execute_callback :before_remove, doc
            unless _assigning?
Severity: Minor
Found in lib/mongoid/relations/embedded/batchable.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 matches? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def matches?(selector)
      selector.each_pair do |key, value|
        if value.is_a?(Hash)
          value.each do |item|
            return false unless matcher(self, key, Hash[*item]).matches?(Hash[*item])
Severity: Minor
Found in lib/mongoid/matchable.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 get_relation has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def get_relation(name, metadata, object, reload = false)
        if !reload && (value = ivar(name)) != false
          value
        else
          _building do
Severity: Minor
Found in lib/mongoid/relations/accessors.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 batch_replace has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

        def batch_replace(docs)
          if docs.blank?
            if _assigning? && !empty?
              base.add_atomic_unset(first)
            end
Severity: Minor
Found in lib/mongoid/relations/embedded/batchable.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 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 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 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 setters has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def setters
            mods = {}
            changes.each_pair do |name, changes|
              if changes
                old, new = 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 create_field_getter has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def create_field_getter(name, meth, field)
              generated_methods.module_eval do
                re_define_method(meth) do
                  raw = read_attribute(name)
                  if lazy_settable?(field, raw)
      Severity: Minor
      Found in lib/mongoid/fields.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

      Severity
      Category
      Status
      Source
      Language