mongodb/mongoid

View on GitHub

Showing 236 of 236 total issues

Similar blocks of code found in 4 locations. Consider refactoring.
Open

  module Matcher

    # In-memory matcher for $lt expression.
    #
    # @see https://www.mongodb.com/docs/manual/reference/operator/query/lt/
Severity: Minor
Found in lib/mongoid/matcher/lt.rb and 3 other locations - About 25 mins to fix
lib/mongoid/matcher/gt.rb on lines 3..27
lib/mongoid/matcher/gte.rb on lines 3..27
lib/mongoid/matcher/lte.rb on lines 3..27

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 31.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method unbind_one has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

          def unbind_one
            binding do
              inverse = _association.inverse(_target)
              bind_foreign_key(_base, nil)
              bind_polymorphic_inverse_type(_base, nil)
Severity: Minor
Found in lib/mongoid/association/referenced/belongs_to/binding.rb - About 25 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 demongoize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def demongoize(object)
          return if object.nil?
          if object.is_a?(String)
            object = begin
              object.__mongoize_time__
Severity: Minor
Found in lib/mongoid/extensions/date.rb - About 25 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 set_max has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def set_max(fields)
        prepare_atomic_operation do |ops|
          process_atomic_operations(fields) do |field, value|
            current_value = attributes[field]
            if value > current_value
Severity: Minor
Found in lib/mongoid/persistable/maxable.rb - About 25 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 criterion has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def criterion(document, attribute, value)
        field = document.database_field_name(attribute)

        if value && localized?(document, field)
          conditions = (value || {}).inject([]) { |acc, (k,v)| acc << { "#{field}.#{k}" => filter(v) }}
Severity: Minor
Found in lib/mongoid/validatable/uniqueness.rb - About 25 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 saved_change_to_attribute? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def saved_change_to_attribute?(attr, from: Utils::PLACEHOLDER, to: Utils::PLACEHOLDER)
      changes = saved_change_to_attribute(attr)
      return false unless changes.is_a?(Array)

      return true if Utils.placeholder?(from) && Utils.placeholder?(to)
Severity: Minor
Found in lib/mongoid/changeable.rb - About 25 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 concat has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

          def concat(documents)
            docs, inserts = [], []
            documents.each do |doc|
              next unless doc

Severity: Minor
Found in lib/mongoid/association/referenced/has_many/proxy.rb - About 25 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 bind_one has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

          def bind_one
            binding do
              check_polymorphic_inverses!(_target)
              _base._association = _association.inverse_association(_target) unless _base._association
              _base.parentize(_target)
Severity: Minor
Found in lib/mongoid/association/embedded/embedded_in/binding.rb - About 25 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 reload_relations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def reload_relations
      relations.each_pair do |name, meta|
        if instance_variable_defined?("@_#{name}")
          if _parent.nil? || instance_variable_get("@_#{name}") != _parent
            remove_instance_variable("@_#{name}")
Severity: Minor
Found in lib/mongoid/association.rb - About 25 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 in has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def in(condition)
          if condition.nil?
            raise Errors::CriteriaArgumentRequired, :in
          end

Severity: Minor
Found in lib/mongoid/criteria/queryable/selectable.rb - About 25 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 retrieve_and_validate_type has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def retrieve_and_validate_type(name, type)
        result = TYPE_MAPPINGS[type] || unmapped_type(type)
        raise Errors::InvalidFieldType.new(self, name, type) if !result.is_a?(Class)

        if unsupported_type?(result)
Severity: Minor
Found in lib/mongoid/fields.rb - About 25 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 clear_target_for_nullify has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

          def clear_target_for_nullify
            after_remove_error = nil
            many_to_many = _target.clear do |doc|
              unbind_one(doc)
              doc.changed_attributes.delete(inverse_foreign_key) unless _association.forced_nil_inverse?
Severity: Minor
Found in lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb - About 25 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 6 (exceeds 5 allowed). Consider refactoring.
Open

      def remove_indexes(models = ::Mongoid.models)
        models.each do |model|
          next if model.embedded?
          begin
            model.remove_indexes
Severity: Minor
Found in lib/mongoid/tasks/database.rb - About 25 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 wait_for_search_indexes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def wait_for_search_indexes(models)
        logger.info('MONGOID: Waiting for search indexes to be created')
        logger.info('MONGOID: Press ctrl-c to skip the wait and let the indexes be created in the background')

        models.each do |model, names|
Severity: Minor
Found in lib/mongoid/tasks/database.rb - About 25 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 text_search has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def text_search(terms, opts = nil)
          if terms.nil?
            raise Errors::CriteriaArgumentRequired, :terms
          end

Severity: Minor
Found in lib/mongoid/criteria/queryable/selectable.rb - About 25 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 build has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

          def build(base, object, _type = nil, selected_fields = nil)
            if object.is_a?(Hash)
              if _loading? && base.persisted?
                Factory.execute_from_db(klass, object, nil, selected_fields, execute_callbacks: false)
              else
Severity: Minor
Found in lib/mongoid/association/embedded/embeds_one/buildable.rb - About 25 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_fk__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def __mongoize_fk__(association, object)
          if object.resizable?
            object.blank? ? object : association.convert_to_foreign_key(object)
          else
            object.blank? ? [] : association.convert_to_foreign_key(Array(object))
Severity: Minor
Found in lib/mongoid/extensions/array.rb - About 25 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 apply_default has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def apply_default(name)
      unless attributes.key?(name)
        if field = fields[name]
          default = field.eval_default(self)
          unless default.nil? || field.lazy?
Severity: Minor
Found in lib/mongoid/fields.rb - About 25 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! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def create!(attributes = nil, type = nil, &block)
        if attributes.is_a?(::Array)
          attributes.map { |attrs| create!(attrs, type, &block) }
        else
          doc = build(attributes, type, &block)
Severity: Minor
Found in lib/mongoid/association/many.rb - About 25 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 set_min has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def set_min(fields)
        prepare_atomic_operation do |ops|
          process_atomic_operations(fields) do |field, value|
            current_value = attributes[field]
            if value < current_value
Severity: Minor
Found in lib/mongoid/persistable/minable.rb - About 25 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