mongoid/mongoid

View on GitHub

Showing 86 of 92 total issues

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

      def __mongoize_time__
        return to_time if utc? && Mongoid.use_utc?
        if Mongoid.use_activesupport_time_zone?
          in_time_zone(::Time.zone).to_time
        else
Severity: Minor
Found in lib/mongoid/extensions/date_time.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

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

        def validate_name(klass, name, options)
          [name, "#{name}?".to_sym, "#{name}=".to_sym].each do |n|
            if Mongoid.destructive_fields.include?(n)
              raise Errors::InvalidField.new(klass, n)
            end
Severity: Minor
Found in lib/mongoid/fields/validators/macro.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 lookup_inverses has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def lookup_inverses(other)
        return [ inverse_of ] if inverse_of
        if other
          matches = []
          other.class.relations.values.each do |meta|
Severity: Minor
Found in lib/mongoid/relations/metadata.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(type = nil)
            return [] if object.blank?
            return object if object.first.is_a?(Document)
            docs = []
            object.each do |attrs|
Severity: Minor
Found in lib/mongoid/relations/builders/embedded/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 create_indexes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def create_indexes
        return unless index_specifications
        index_specifications.each do |spec|
          key, options = spec.key, spec.options
          if database = options[:database]
Severity: Minor
Found in lib/mongoid/indexable.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 extract_attribute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def extract_attribute(document, key)
        if (key_string = key.to_s) =~ /.+\..+/
          key_string.split('.').inject(document.as_document) do |_attribs, _key|
            if _attribs.is_a?(::Array)
              _attribs.map { |doc| doc.try(:[], _key) }
Severity: Minor
Found in lib/mongoid/matchable.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 cascadable_child? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def cascadable_child?(kind, child, metadata)
      return false if kind == :initialize || kind == :find
      return false if kind == :validate && metadata.validate?
      child.callback_executable?(kind) ? child.in_callback_state?(kind) : false
    end
Severity: Minor
Found in lib/mongoid/interceptable.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 unbind_one has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

          def unbind_one
            binding do
              inverse = metadata.inverse(target)
              bind_foreign_key(base, nil)
              bind_polymorphic_inverse_type(base, nil)
Severity: Minor
Found in lib/mongoid/relations/bindings/referenced/in.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 child_callback_type has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def child_callback_type(kind, child)
      if kind == :update
        return :create if child.new_record?
        return :destroy if child.flagged_for_destroy?
        kind
Severity: Minor
Found in lib/mongoid/interceptable.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/relations/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 validate_each has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def validate_each(document, attribute, value)
        with_query(document) do
          attrib, val = to_validate(document, attribute, value)
          return unless validation_required?(document, attrib)
          if document.embedded?
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 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/relations/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 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
            append(doc)
Severity: Minor
Found in lib/mongoid/relations/referenced/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 reload has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def reload
      reloaded = _reload
      if Mongoid.raise_not_found_error && reloaded.empty?
        raise Errors::DocumentNotFound.new(self.class, _id, _id)
      end
Severity: Minor
Found in lib/mongoid/reloadable.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__(constraint, object)
          if object.resizable?
            object.blank? ? object : constraint.convert(object)
          else
            object.blank? ? [] : constraint.convert(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 includes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def includes(*relations)
      relations.flatten.each do |name|
        metadata = klass.reflect_on_association(name)
        raise Errors::InvalidIncludes.new(klass, relations) unless metadata
        inclusions.push(metadata) unless inclusions.include?(metadata)
Severity: Minor
Found in lib/mongoid/criteria.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 instantiate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def instantiate(attrs = nil, selected_fields = nil)
        attributes = attrs || {}
        doc = allocate
        doc.__selected_fields = selected_fields
        doc.instance_variable_set(:@attributes, attributes)
Severity: Minor
Found in lib/mongoid/document.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

Severity
Category
Status
Source
Language