mongodb/mongoid

View on GitHub

Showing 236 of 236 total issues

Method one_matches? has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      module_function def one_matches?(exists, value, condition)
        case condition
        when 1
          # Double
          Float === value
Severity: Minor
Found in lib/mongoid/matcher/type.rb - About 1 hr to fix

    Method matches? has 49 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          module_function def matches?(exists, value, condition)
            if condition.is_a?(Hash)
              condition.all? do |k, cond_v|
                k = k.to_s
                if k.start_with?('$')
    Severity: Minor
    Found in lib/mongoid/matcher/field_expression.rb - About 1 hr to fix

      Method for_child has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def for_child(document)
            if document.is_a?(Class)
              return self if document == (@object.is_a?(Class) ? @object : @object.class)
            elsif document.is_a?(Mongoid::Document)
              return self if document.class == (@object.is_a?(Class) ? @object : @object.class)
      Severity: Minor
      Found in lib/mongoid/persistence_context.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 pre_process_batch_insert has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

              def pre_process_batch_insert(docs)
                docs.map do |doc|
                  next unless doc
                  append(doc)
                  if persistable? && !_assigning?
      Severity: Minor
      Found in lib/mongoid/association/embedded/batchable.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 properties_for_relations has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

            def properties_for_relations(model, visited)
              model.relations.each_with_object({}) do |(name, relation), props|
                next if visited.include?(relation.relation_class)
                next unless relation.is_a?(Association::Embedded::EmbedsOne)
                next unless relation.relation_class.encrypted?
      Severity: Minor
      Found in lib/mongoid/config/encryption.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 define_callbacks! has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def self.define_callbacks!(association)
                name = association.name
                cache_column = association.counter_cache_column_name.to_sym
      
                association.inverse_class.tap do |klass|
      Severity: Minor
      Found in lib/mongoid/association/referenced/counter_cache.rb - About 1 hr to fix

        Method shard_collections has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def shard_collections(models = ::Mongoid.models)
                models.map do |model|
                  next if model.shard_config.nil?
        
                  if model.embedded? && !model.cyclic?
        Severity: Minor
        Found in lib/mongoid/tasks/database.rb - About 1 hr to fix

          Method bit has a Cognitive Complexity of 14 (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 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 standard_dependencies has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          def standard_dependencies
            gem 'rake'
          
            group :development do
              gem 'yard', '>= 0.9.35'
          Severity: Minor
          Found in gemfiles/standard.rb - About 1 hr to fix

            Method mongoize_foreign_key has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def mongoize_foreign_key(object)
                    if type == Array || type == Set
                      object = object.to_a if type == Set || object.is_a?(Set)
            
                      if object.resizable?
            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 keys_by_type_from_docs has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                      def keys_by_type_from_docs
                        inverse_type_field = @association.inverse_type
            
                        @docs.each_with_object({}) do |doc, keys_by_type|
                          next unless doc.respond_to?(inverse_type_field) && doc.respond_to?(group_by_key)
            Severity: Minor
            Found in lib/mongoid/association/referenced/belongs_to/eager.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 clone_with_hash has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.clone_with_hash(klass, attrs)
                  dynamic_attrs = {}
                  _attribute_names = klass.attribute_names
                  attrs.reject! do |attr_name, value|
                    unless _attribute_names.include?(attr_name)
            Severity: Minor
            Found in lib/mongoid/copyable.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 matches? has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  module_function def matches?(exists, value, condition, original_operator)
                    case condition
                    when Range
                      # Since $ne invokes $eq, the exception message needs to handle
                      # both operators.
            Severity: Minor
            Found in lib/mongoid/matcher/eq_impl.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 encryption_schema_map has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def encryption_schema_map(default_database, models = ::Mongoid.models)
                    visited = Set.new
                    models.each_with_object({}) do |model, map|
                      next if visited.include?(model)
                      visited << model
            Severity: Minor
            Found in lib/mongoid/config/encryption.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 extract_includes_list has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def extract_includes_list(_parent_class, parent, *relations_list)
                    relations_list.flatten.each do |relation_object|
                      if relation_object.is_a?(Hash)
                        relation_object.each do |relation, _includes|
                          association = _parent_class.reflect_on_association(relation)
            Severity: Minor
            Found in lib/mongoid/criteria/includable.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 prepare_insert has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                  def prepare_insert(options = {})
                    raise Errors::ReadonlyDocument.new(self.class) if readonly? && !Mongoid.legacy_readonly
                    return self if performing_validations?(options) &&
                      invalid?(options[:context] || :create)
                    ensure_client_compatibility!
            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 matches? has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                  module_function def matches?(document, expr)
                    if expr.nil?
                      raise Errors::InvalidQuery, "Nil condition in expression context"
                    end
                    unless Hash === expr
            Severity: Minor
            Found in lib/mongoid/matcher/expression.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 and has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                    def and(*criteria)
                      _mongoid_flatten_arrays(criteria).inject(self.clone) do |c, new_s|
                        if new_s.is_a?(Selectable)
                          new_s = new_s.selector
                        end
            Severity: Minor
            Found in lib/mongoid/criteria/queryable/selectable.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 accepts_nested_attributes_for has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                    def accepts_nested_attributes_for(*args)
                      options = args.extract_options!.dup
                      options[:autosave] = true if options[:autosave].nil?
            
                      options[:reject_if] = REJECT_ALL_BLANK_PROC if options[:reject_if] == :all_blank
            Severity: Minor
            Found in lib/mongoid/attributes/nested.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 _mongoid_filter_selected_fields has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                  def _mongoid_filter_selected_fields(assoc_key)
                    return nil unless __selected_fields
            
                    # If the list of fields was specified using #without instead of #only
                    # and the provided list does not include the association, any of its
            Severity: Minor
            Found in lib/mongoid/association/accessors.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

            Severity
            Category
            Status
            Source
            Language