ForestAdmin/forest-rails

View on GitHub
app/services/forest_liana/search_query_builder.rb

Summary

Maintainability
D
2 days
Test Coverage
D
63%

Method search_param has a Cognitive Complexity of 90 (exceeds 5 allowed). Consider refactoring.
Open

    def search_param
      if @search
        conditions = []

        @resource.columns.each_with_index do |column, index|
Severity: Minor
Found in app/services/forest_liana/search_query_builder.rb - About 1 day 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 search_param has 84 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def search_param
      if @search
        conditions = []

        @resource.columns.each_with_index do |column, index|
Severity: Major
Found in app/services/forest_liana/search_query_builder.rb - About 3 hrs to fix

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

        def perform(resource)
          @resource = @records = resource
          @tables_associated_to_relations_name =
            ForestLiana::QueryHelper.get_tables_associated_to_relations_name(@resource)
          @records = search_param
    Severity: Minor
    Found in app/services/forest_liana/search_query_builder.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

    Avoid deeply nested control flow statements.
    Open

                      if @collection.search_fields.nil? || (association_search &&
                        association_search.include?(column.name))
                        conditions << association_search_condition(resource.table_name,
                          column.name)
                      end
    Severity: Major
    Found in app/services/forest_liana/search_query_builder.rb - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                        if !(column.respond_to?(:array) && column.array) && text_type?(column.type)
                          if association_search.include?(column.name)
                            conditions << association_search_condition(resource.table_name,
                              column.name)
                          end
      Severity: Major
      Found in app/services/forest_liana/search_query_builder.rb - About 45 mins to fix

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

            def sort_query
              if @params[:sort]
                @params[:sort].split(',').each do |field|
                  order_detected = detect_sort_order(field)
                  order = order_detected.upcase
        Severity: Minor
        Found in app/services/forest_liana/search_query_builder.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 detect_reference has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def detect_reference(param)
              ref, field = param.split('.')
        
              if ref && field
                association = @resource.reflect_on_all_associations
        Severity: Minor
        Found in app/services/forest_liana/search_query_builder.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