MaxLap/activerecord_where_assoc

View on GitHub
lib/active_record_where_assoc/core_logic.rb

Summary

Maintainability
F
3 days
Test Coverage

Method relations_on_one_association has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    def self.relations_on_one_association(record_class, association_name, given_conditions, options, last_assoc_block, nest_assocs_block)
      final_reflection = fetch_reflection(record_class, association_name)

      check_reflection_validity!(final_reflection)

Severity: Minor
Found in lib/active_record_where_assoc/core_logic.rb - About 4 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 classes_with_scope_for_reflection has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    def self.classes_with_scope_for_reflection(record_class, reflection, options)
      actual_source_reflection = user_defined_actual_source_reflection(reflection)

      if poly_belongs_to?(actual_source_reflection)
        on_poly_belongs_to = option_value(options, :poly_belongs_to)
Severity: Minor
Found in lib/active_record_where_assoc/core_logic.rb - About 4 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 core_logic.rb has 326 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_relative "active_record_compat"
require_relative "exceptions"

module ActiveRecordWhereAssoc
  module CoreLogic
Severity: Minor
Found in lib/active_record_where_assoc/core_logic.rb - About 3 hrs to fix

    Method classes_with_scope_for_reflection has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.classes_with_scope_for_reflection(record_class, reflection, options)
          actual_source_reflection = user_defined_actual_source_reflection(reflection)
    
          if poly_belongs_to?(actual_source_reflection)
            on_poly_belongs_to = option_value(options, :poly_belongs_to)
    Severity: Minor
    Found in lib/active_record_where_assoc/core_logic.rb - About 1 hr to fix

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

          def self.check_reflection_validity!(reflection)
            if ActiveRecordCompat.through_reflection?(reflection)
              # Copied from ActiveRecord
              if reflection.through_reflection.polymorphic?
                # Since deep_cover/builtin_takeover lacks some granularity,
      Severity: Minor
      Found in lib/active_record_where_assoc/core_logic.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 process_association_step_limits has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.process_association_step_limits(current_scope, reflection, relation_klass, options)
            if user_defined_actual_source_reflection(reflection).macro == :belongs_to || option_value(options, :ignore_limit)
              return current_scope.unscope(:limit, :offset, :order)
            end
      
      
      Severity: Minor
      Found in lib/active_record_where_assoc/core_logic.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 relations_on_one_association has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.relations_on_one_association(record_class, association_name, given_conditions, options, last_assoc_block, nest_assocs_block)
            final_reflection = fetch_reflection(record_class, association_name)
      
            check_reflection_validity!(final_reflection)
      
      
      Severity: Minor
      Found in lib/active_record_where_assoc/core_logic.rb - About 1 hr to fix

        Method sql_for_count_operator has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.sql_for_count_operator(left_operand, operator, right_sql)
              operator = case operator.to_s
                         when "=="
                           "="
                         when "!="
        Severity: Minor
        Found in lib/active_record_where_assoc/core_logic.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 initial_scopes_from_reflection has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def self.initial_scopes_from_reflection(record_class, reflection_chain, assoc_scopes, options)
              reflection = reflection_chain.first
              actual_source_reflection = user_defined_actual_source_reflection(reflection)
        
              on_poly_belongs_to = option_value(options, :poly_belongs_to) if poly_belongs_to?(actual_source_reflection)
        Severity: Minor
        Found in lib/active_record_where_assoc/core_logic.rb - About 1 hr to fix

          Method compare_assoc_count_sql has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def self.compare_assoc_count_sql(record_class, left_operand, operator, association_names, given_conditions, options, &block)
          Severity: Major
          Found in lib/active_record_where_assoc/core_logic.rb - About 50 mins to fix

            Method _relations_on_association_recurse has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def self._relations_on_association_recurse(record_class, association_names, given_conditions, options, last_assoc_block, nest_assocs_block)
            Severity: Minor
            Found in lib/active_record_where_assoc/core_logic.rb - About 45 mins to fix

              Method relations_on_association has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def self.relations_on_association(record_class, association_names, given_conditions, options, last_assoc_block, nest_assocs_block)
              Severity: Minor
              Found in lib/active_record_where_assoc/core_logic.rb - About 45 mins to fix

                Method relations_on_one_association has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def self.relations_on_one_association(record_class, association_name, given_conditions, options, last_assoc_block, nest_assocs_block)
                Severity: Minor
                Found in lib/active_record_where_assoc/core_logic.rb - About 45 mins to fix

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

                      def self.initial_scopes_from_reflection(record_class, reflection_chain, assoc_scopes, options)
                        reflection = reflection_chain.first
                        actual_source_reflection = user_defined_actual_source_reflection(reflection)
                  
                        on_poly_belongs_to = option_value(options, :poly_belongs_to) if poly_belongs_to?(actual_source_reflection)
                  Severity: Minor
                  Found in lib/active_record_where_assoc/core_logic.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 assoc_not_exists_sql has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def self.assoc_not_exists_sql(record_class, association_names, given_conditions, options, &block)
                  Severity: Minor
                  Found in lib/active_record_where_assoc/core_logic.rb - About 35 mins to fix

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

                        def self.only_assoc_count_sql(record_class, association_names, given_conditions, options, &block)
                    Severity: Minor
                    Found in lib/active_record_where_assoc/core_logic.rb - About 35 mins to fix

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

                          def self.assoc_exists_sql(record_class, association_names, given_conditions, options, &block)
                      Severity: Minor
                      Found in lib/active_record_where_assoc/core_logic.rb - About 35 mins to fix

                        Method wrapper_and_join_constraints has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def self.wrapper_and_join_constraints(record_class, reflection, options = {})
                              poly_belongs_to_klass = options[:poly_belongs_to_klass]
                              join_keys = ActiveRecordCompat.join_keys(reflection, poly_belongs_to_klass)
                        
                              key = join_keys.key
                        Severity: Minor
                        Found in lib/active_record_where_assoc/core_logic.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

                        Prefer single-quoted strings inside interpolations.
                        Open

                                "(#{sqls.join(" OR ")})" # Parens needed when embedding the sql in a `where`, because the OR could make things wrong

                        This cop checks that quotes inside the string interpolation match the configured preference.

                        Example: EnforcedStyle: single_quotes (default)

                        # bad
                        result = "Tests #{success ? "PASS" : "FAIL"}"
                        
                        # good
                        result = "Tests #{success ? 'PASS' : 'FAIL'}"

                        Example: EnforcedStyle: double_quotes

                        # bad
                        result = "Tests #{success ? 'PASS' : 'FAIL'}"
                        
                        # good
                        result = "Tests #{success ? "PASS" : "FAIL"}"

                        There are no issues that match your filters.

                        Category
                        Status