activerecord-hackery/ransack

View on GitHub
lib/ransack/adapters/active_record/context.rb

Summary

Maintainability
D
1 day
Test Coverage

Method evaluate has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

        def evaluate(search, opts = {})
          viz = Visitor.new
          relation = @object.where(viz.accept(search.base))

          if search.sorts.any?
Severity: Minor
Found in lib/ransack/adapters/active_record/context.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 context.rb has 264 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'ransack/context'
require 'polyamorous/polyamorous'

module Ransack
  module Adapters
Severity: Minor
Found in lib/ransack/adapters/active_record/context.rb - About 2 hrs to fix

    Class Context has 22 methods (exceeds 20 allowed). Consider refactoring.
    Open

          class Context < ::Ransack::Context
    
            def relation_for(object)
              object.all
            end
    Severity: Minor
    Found in lib/ransack/adapters/active_record/context.rb - About 2 hrs to fix

      Method extract_correlated_key has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

              def extract_correlated_key(join_root)
                case join_root
                when Arel::Nodes::OuterJoin
                  # one of join_root.right/join_root.left is expected to be Arel::Nodes::On
                  if join_root.right.is_a?(Arel::Nodes::On)
      Severity: Minor
      Found in lib/ransack/adapters/active_record/context.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 build_joins has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def build_joins(relation)
                buckets = relation.joins_values + relation.left_outer_joins_values
      
                buckets = buckets.group_by do |join|
                  case join
      Severity: Minor
      Found in lib/ransack/adapters/active_record/context.rb - About 1 hr to fix

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

                def attribute_method?(str, klass = @klass)
                  exists = false
                  if ransackable_attribute?(str, klass)
                    exists = true
                  elsif (segments = str.split(Constants::UNDERSCORE)).size > 1
        Severity: Minor
        Found in lib/ransack/adapters/active_record/context.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_parent_and_attribute_name has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

                def get_parent_and_attribute_name(str, parent = @base)
                  attr_name = nil
        
                  if ransackable_attribute?(str, klassify(parent))
                    attr_name = str
        Severity: Minor
        Found in lib/ransack/adapters/active_record/context.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 type_for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def type_for(attr)
                  return nil unless attr && attr.valid?
                  relation     = attr.arel_attribute.relation
                  name         = attr.arel_attribute.name.to_s
                  table        = relation.respond_to?(:table_name) ? relation.table_name : relation.name
        Severity: Minor
        Found in lib/ransack/adapters/active_record/context.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

        There are no issues that match your filters.

        Category
        Status