mongodb/mongoid

View on GitHub

Showing 236 of 236 total issues

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

    def _mongoid_run_child_before_callbacks(kind, children: [], callback_list: [])
      children.each do |child|
        chain = child.__callbacks[child_callback_type(kind, child)]
        env = ActiveSupport::Callbacks::Filters::Environment.new(child, false, nil)
        next_sequence = compile_callbacks(chain)
Severity: Minor
Found in lib/mongoid/interceptable.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 properties_for_fields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def properties_for_fields(model)
        model.fields.each_with_object({}) do |(name, field), props|
          next unless field.is_a?(Mongoid::Fields::Encrypted)

          props[name] = {
Severity: Minor
Found in lib/mongoid/config/encryption.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 documents_for_iteration has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def documents_for_iteration
        if @documents_loader
          if @documents_loader.started?
            @documents_loader.value!
          else
Severity: Minor
Found in lib/mongoid/contextual/mongo.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

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

  module Matcher

    # In-memory matcher for $or expression.
    #
    # @see https://www.mongodb.com/docs/manual/reference/operator/query/or/
Severity: Minor
Found in lib/mongoid/matcher/or.rb and 1 other location - About 40 mins to fix
lib/mongoid/matcher/and.rb on lines 3..30

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 38.

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

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

  module Matcher

    # In-memory matcher for $and expression.
    #
    # @see https://www.mongodb.com/docs/manual/reference/operator/query/and/
Severity: Minor
Found in lib/mongoid/matcher/and.rb and 1 other location - About 40 mins to fix
lib/mongoid/matcher/or.rb on lines 3..30

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 38.

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

Consider simplifying this complex logical expression.
Open

                if v.is_a?(Hash) &&
                  v.length == 1 &&
                  (new_k = v.keys.first).start_with?('$') &&
                  (existing_kv = c.selector[k]).is_a?(Hash) &&
                  !existing_kv.key?(new_k) &&
Severity: Major
Found in lib/mongoid/criteria/queryable/selectable.rb - About 40 mins to fix

    Method add_key has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

                def add_key(name, strategy, operator, additional = nil, &block)
    Severity: Minor
    Found in lib/mongoid/criteria/queryable/extensions/symbol.rb - About 35 mins to fix

      Method key has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              def key(name, strategy, operator, additional = nil, &block)
      Severity: Minor
      Found in lib/mongoid/criteria/queryable/macroable.rb - About 35 mins to fix

        Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                def initialize(name, strategy, operator, expanded = nil, &block)
        Severity: Minor
        Found in lib/mongoid/criteria/queryable/key.rb - About 35 mins to fix

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

          module Mongoid
            class Criteria
              module Queryable
                module Extensions
          
          
          Severity: Minor
          Found in lib/mongoid/criteria/queryable/extensions/time.rb and 1 other location - About 35 mins to fix
          lib/mongoid/criteria/queryable/extensions/time_with_zone.rb on lines 4..53

          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 36.

          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

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

          module Mongoid
            class Criteria
              module Queryable
                module Extensions
          
          
          Severity: Minor
          Found in lib/mongoid/criteria/queryable/extensions/time_with_zone.rb and 1 other location - About 35 mins to fix
          lib/mongoid/criteria/queryable/extensions/time.rb on lines 4..52

          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 36.

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

                def build_auto_encryption_options(opts, database)
                  return nil unless opts[:auto_encryption_options]
          
                  opts[:auto_encryption_options].dup.tap do |auto_encryption_options|
                    if auto_encryption_options.key?(:schema_map)
          Severity: Minor
          Found in lib/mongoid/clients/factory.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 define_relation_touch_method has a Cognitive Complexity of 7 (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 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 inverse_foreign_key has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                  def inverse_foreign_key
                    if @options.key?(:inverse_foreign_key)
                      @options[:inverse_foreign_key]
                    elsif @options.key?(:inverse_of)
                      inverse_of ? "#{inverse_of.to_s.singularize}#{FOREIGN_KEY_SUFFIX}" : nil
          Severity: Minor
          Found in lib/mongoid/association/referenced/has_and_belongs_to_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 selection has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                  def selection(criterion = nil)
                    clone.tap do |query|
                      if criterion
                        criterion.each_pair do |field, value|
                          yield(query.selector, field.is_a?(Key) ? field : field.to_s, value)
          Severity: Minor
          Found in lib/mongoid/criteria/queryable/selectable.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 substitute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                    def substitute(replacement)
                      return self if replacement == self
          
                      if _assigning?
                        _base.add_atomic_unset(_target) unless replacement
          Severity: Minor
          Found in lib/mongoid/association/embedded/embeds_one/proxy.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 check_for_id_violation! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                  def check_for_id_violation!
                    # look for the basic criteria of an update (see #update?)
                    return unless existing&.persisted? && !destroyable?
          
                    # if the id is either absent, or if it equals the existing record's
          Severity: Minor
          Found in lib/mongoid/association/nested/one.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 << has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                    def <<(*args)
                      docs = args.flatten
                      return concat(docs) if docs.size > 1
          
                      if (doc = docs.first)
          Severity: Minor
          Found in lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.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 expr_query has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                  def expr_query(criterion)
                    if criterion.nil?
                      raise ArgumentError, 'Criterion cannot be nil here'
                    end
                    unless Hash === criterion
          Severity: Minor
          Found in lib/mongoid/criteria/queryable/selectable.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 append_document has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                    def append_document(doc, ids, docs, inserts)
                      return unless doc
          
                      append(doc)
          
          
          Severity: Minor
          Found in lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.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