activerecord-hackery/ransack

View on GitHub
lib/ransack/nodes/condition.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Condition has 37 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Condition < Node
      i18n_word :attribute, :predicate, :combinator, :value
      i18n_alias a: :attribute, p: :predicate,
                 m: :combinator, v: :value

Severity: Minor
Found in lib/ransack/nodes/condition.rb - About 4 hrs to fix

    File condition.rb has 289 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Ransack
      module Nodes
        class Condition < Node
          i18n_word :attribute, :predicate, :combinator, :value
          i18n_alias a: :attribute, p: :predicate,
    Severity: Minor
    Found in lib/ransack/nodes/condition.rb - About 2 hrs to fix

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

                def extract_values_for_condition(key, context = nil)
                  str = key.dup
                  name = Predicate.detect_and_strip_from_string!(str)
                  predicate = Predicate.named(name)
      
      
      Severity: Minor
      Found in lib/ransack/nodes/condition.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

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

            def arel_predicate
              predicate = attributes.map { |attribute|
                association = attribute.parent
                if negative? && attribute.associated_collection?
                  query = context.build_correlated_subquery(association)
      Severity: Minor
      Found in lib/ransack/nodes/condition.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

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

              def extract(context, key, values)
                attributes, predicate, combinator =
                  extract_values_for_condition(key, context)
      
                if attributes.size > 0 && predicate
      Severity: Minor
      Found in lib/ransack/nodes/condition.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 build_attribute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def build_attribute(name = nil, ransacker_args = [])
              Attribute.new(@context, name, ransacker_args).tap do |attribute|
                @context.bind(attribute, attribute.name)
                self.attributes << attribute if name.nil? || attribute.valid?
                if predicate && !negative?
      Severity: Minor
      Found in lib/ransack/nodes/condition.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 attr_value_for_attribute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def attr_value_for_attribute(attr)
              return attr.attr if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
      
              predicate.case_insensitive ? attr.attr.lower : attr.attr
            rescue
      Severity: Minor
      Found in lib/ransack/nodes/condition.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