activerecord/lib/active_record/autosave_association.rb

Summary

Maintainability
D
2 days
Test Coverage

Method save_collection_association has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

      def save_collection_association(reflection)
        if association = association_instance_get(reflection.name)
          autosave = reflection.options[:autosave]

          # By saving the instance variable in a local variable,
Severity: Minor
Found in activerecord/lib/active_record/autosave_association.rb - About 6 hrs 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 save_has_one_association has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

      def save_has_one_association(reflection)
        association = association_instance_get(reflection.name)
        record      = association && association.load_target

        if record && !record.destroyed?
Severity: Minor
Found in activerecord/lib/active_record/autosave_association.rb - About 3 hrs 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 save_belongs_to_association has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

      def save_belongs_to_association(reflection)
        association = association_instance_get(reflection.name)
        return unless association && association.loaded? && !association.stale_target?

        record = association.load_target
Severity: Minor
Found in activerecord/lib/active_record/autosave_association.rb - About 3 hrs 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

File autosave_association.rb has 280 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ActiveRecord
  # = Active Record Autosave Association
  #
  # AutosaveAssociation is a module that takes care of automatically saving
  # associated records when their parent is saved. In addition to saving, it
Severity: Minor
Found in activerecord/lib/active_record/autosave_association.rb - About 2 hrs to fix

    Method save_collection_association has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def save_collection_association(reflection)
            if association = association_instance_get(reflection.name)
              autosave = reflection.options[:autosave]
    
              # By saving the instance variable in a local variable,
    Severity: Minor
    Found in activerecord/lib/active_record/autosave_association.rb - About 1 hr to fix

      Method compute_primary_key has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def compute_primary_key(reflection, record)
              if primary_key_options = reflection.options[:primary_key]
                primary_key_options
              elsif reflection.options[:query_constraints] && (query_constraints = record.class.query_constraints_list)
                query_constraints
      Severity: Minor
      Found in activerecord/lib/active_record/autosave_association.rb - About 55 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

      Avoid deeply nested control flow statements.
      Open

                        record[foreign_key] = association_id unless record[foreign_key] == association_id
      Severity: Major
      Found in activerecord/lib/active_record/autosave_association.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                          if reflection.validate?
                            errors.add(reflection.name) unless association_saved
                            saved = association_saved
                          end
        Severity: Major
        Found in activerecord/lib/active_record/autosave_association.rb - About 45 mins to fix

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

                def association_valid?(reflection, record, index = nil)
                  return true if record.destroyed? || (reflection.options[:autosave] && record.marked_for_destruction?)
          
                  context = validation_context if custom_validation_context?
          
          
          Severity: Minor
          Found in activerecord/lib/active_record/autosave_association.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 add_autosave_association_callbacks has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                  def add_autosave_association_callbacks(reflection)
                    save_method = :"autosave_associated_records_for_#{reflection.name}"
          
                    if reflection.collection?
                      around_save :around_save_collection_association
          Severity: Minor
          Found in activerecord/lib/active_record/autosave_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

          There are no issues that match your filters.

          Category
          Status