ForestAdmin/forest-rails

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

Summary

Maintainability
B
5 hrs
Test Coverage
A
97%

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

  class FiltersParser
    AGGREGATOR_OPERATOR = %w(and or)

    def initialize(filters, resource, timezone, params = nil)
      @filters = filters
Severity: Minor
Found in app/services/forest_liana/filters_parser.rb - About 2 hrs to fix

    Method get_previous_interval_condition has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_previous_interval_condition
          current_previous_interval = nil
          # NOTICE: Leaf condition at root
          unless @filters['aggregator']
            return @filters if @operator_date_parser.has_previous_interval?(@filters['operator'])
    Severity: Minor
    Found in app/services/forest_liana/filters_parser.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 parse_aggregation_on_previous_interval has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_aggregation_on_previous_interval(node, previous_condition)
          raise_empty_condition_in_filter_error unless node
    
          return parse_previous_interval_condition(node) unless node['aggregator']
    
    
    Severity: Minor
    Found in app/services/forest_liana/filters_parser.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 parse_field_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_field_name(field)
          if is_belongs_to(field)
            current_resource = @resource.reflect_on_association(field.split(':').first.to_sym)&.klass
            raise ForestLiana::Errors::HTTP422Error.new("Field '#{field}' not found") unless current_resource
    
    
    Severity: Minor
    Found in app/services/forest_liana/filters_parser.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

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

        def ensure_valid_condition(condition)
          raise_empty_condition_in_filter_error if condition.empty?
          raise ForestLiana::Errors::HTTP422Error.new('Condition cannot be a raw value') unless condition.is_a?(Hash)
          unless condition['field'].is_a?(String) and condition['operator'].is_a?(String)
            raise ForestLiana::Errors::HTTP422Error.new('Invalid condition format')
    Severity: Minor
    Found in app/services/forest_liana/filters_parser.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