mongodb/mongoid

View on GitHub
lib/mongoid/association/accessors.rb

Summary

Maintainability
B
4 hrs
Test Coverage

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

Method define_setter! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def self.define_setter!(association)
        name = association.name
        association.inverse_class.tap do |klass|
          klass.re_define_method("#{name}=") do |object|
            without_autobuild do
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

Method get_relation has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def get_relation(name, association, object, reload = false)
        field_name = database_field_name(name)

        # As per the comments under MONGOID-5034, I've decided to only raise on
        # embedded associations for a missing attribute. Rails does not raise
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

Method _mongoid_filter_selected_fields has 27 lines of code (exceeds 25 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

    There are no issues that match your filters.

    Category
    Status