app/models/pqf_query.rb

Summary

Maintainability
D
2 days
Test Coverage

Class has too many lines. [293/100]
Open

class PqfQuery
  # relevance attribute spec says, in essence
  # sort by dynamic relevance ranking (based on query)
  # and match partial words (truncated on either the left or right, i.e. both)
  # and do fuzzy matching (any one character in term may be replaced to match in search)
Severity: Minor
Found in app/models/pqf_query.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [61/10]
Open

  def title_or_any_text_includes(terms)
    query_part = QUALIFYING_ATTRIBUTE_SPECS['relevance']
    operator = '@and'
    terms = pqf_format(terms)

Severity: Minor
Found in app/models/pqf_query.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for title_or_any_text_includes is too high. [56.51/15]
Open

  def title_or_any_text_includes(terms)
    query_part = QUALIFYING_ATTRIBUTE_SPECS['relevance']
    operator = '@and'
    terms = pqf_format(terms)

Severity: Minor
Found in app/models/pqf_query.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method title_or_any_text_includes has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

  def title_or_any_text_includes(terms)
    query_part = QUALIFYING_ATTRIBUTE_SPECS['relevance']
    operator = '@and'
    terms = pqf_format(terms)

Severity: Minor
Found in app/models/pqf_query.rb - About 5 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

Assignment Branch Condition size for to_s is too high. [40.37/15]
Open

  def to_s
    # handle the query as specified in standard ways so far
    full_query = @operators.join(' ') + ' ' + @query_parts.join(' ') + ' '

    # add special handling of searching URLs within dc subject
Severity: Minor
Found in app/models/pqf_query.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

File pqf_query.rb has 294 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class PqfQuery
  # relevance attribute spec says, in essence
  # sort by dynamic relevance ranking (based on query)
  # and match partial words (truncated on either the left or right, i.e. both)
  # and do fuzzy matching (any one character in term may be replaced to match in search)
Severity: Minor
Found in app/models/pqf_query.rb - About 3 hrs to fix

    Perceived complexity for title_or_any_text_includes is too high. [18/7]
    Open

      def title_or_any_text_includes(terms)
        query_part = QUALIFYING_ATTRIBUTE_SPECS['relevance']
        operator = '@and'
        terms = pqf_format(terms)
    
    
    Severity: Minor
    Found in app/models/pqf_query.rb by rubocop

    This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

    Example:

    def my_method                   # 1
      if cond                       # 1
        case var                    # 2 (0.8 + 4 * 0.2, rounded)
        when 1 then func_one
        when 2 then func_two
        when 3 then func_three
        when 4..10 then func_other
        end
      else                          # 1
        do_something until a && b   # 2
      end                           # ===
    end                             # 7 complexity points

    Method has too many lines. [20/10]
    Open

      def create_query_part(options = {})
        query_part = options[:attribute_spec]
        # should always be an array by the time it gets here
        term_or_terms = options[:term_or_terms]
        should_be_exact = options[:should_be_exact] || false
    Severity: Minor
    Found in app/models/pqf_query.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Method has too many lines. [20/10]
    Open

      def to_s
        # handle the query as specified in standard ways so far
        full_query = @operators.join(' ') + ' ' + @query_parts.join(' ') + ' '
    
        # add special handling of searching URLs within dc subject
    Severity: Minor
    Found in app/models/pqf_query.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Assignment Branch Condition size for oai_datestamp_comparison is too high. [24.43/15]
    Open

      def oai_datestamp_comparison(options = {})
        beginning = !options[:beginning].blank? ? options[:beginning] : nil
        ending = !options[:ending].blank? ? options[:ending] : nil
    
        if !beginning.nil? && !ending.nil?
    Severity: Minor
    Found in app/models/pqf_query.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Method has too many lines. [18/10]
    Open

      def oai_datestamp_between(options = {})
        beginning = options[:beginning]
        ending = options[:ending]
    
        query_part = '@and ' + oai_datestamp_on_or_after(
    Severity: Minor
    Found in app/models/pqf_query.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Assignment Branch Condition size for create_query_part is too high. [23.02/15]
    Open

      def create_query_part(options = {})
        query_part = options[:attribute_spec]
        # should always be an array by the time it gets here
        term_or_terms = options[:term_or_terms]
        should_be_exact = options[:should_be_exact] || false
    Severity: Minor
    Found in app/models/pqf_query.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Cyclomatic complexity for title_or_any_text_includes is too high. [13/6]
    Open

      def title_or_any_text_includes(terms)
        query_part = QUALIFYING_ATTRIBUTE_SPECS['relevance']
        operator = '@and'
        terms = pqf_format(terms)
    
    
    Severity: Minor
    Found in app/models/pqf_query.rb by rubocop

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Method title_or_any_text_includes has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def title_or_any_text_includes(terms)
        query_part = QUALIFYING_ATTRIBUTE_SPECS['relevance']
        operator = '@and'
        terms = pqf_format(terms)
    
    
    Severity: Major
    Found in app/models/pqf_query.rb - About 2 hrs to fix

      Method has too many lines. [16/10]
      Open

        def creators_or_contributors_include(term_or_terms, options = {})
          query_part = '@or ' + creators_include(
            term_or_terms,
            options.merge({
                            only_return_as_string: true,
      Severity: Minor
      Found in app/models/pqf_query.rb by rubocop

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Method has too many lines. [16/10]
      Open

        def creators_or_contributors_equals_completely(term_or_terms, options = {})
          query_part = '@or ' + creators_equals_completely(
            term_or_terms,
            options.merge({
                            only_return_as_string: true,
      Severity: Minor
      Found in app/models/pqf_query.rb by rubocop

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Cyclomatic complexity for oai_datestamp_comparison is too high. [9/6]
      Open

        def oai_datestamp_comparison(options = {})
          beginning = !options[:beginning].blank? ? options[:beginning] : nil
          ending = !options[:ending].blank? ? options[:ending] : nil
      
          if !beginning.nil? && !ending.nil?
      Severity: Minor
      Found in app/models/pqf_query.rb by rubocop

      This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

      An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

      Perceived complexity for oai_datestamp_comparison is too high. [10/7]
      Open

        def oai_datestamp_comparison(options = {})
          beginning = !options[:beginning].blank? ? options[:beginning] : nil
          ending = !options[:ending].blank? ? options[:ending] : nil
      
          if !beginning.nil? && !ending.nil?
      Severity: Minor
      Found in app/models/pqf_query.rb by rubocop

      This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

      Example:

      def my_method                   # 1
        if cond                       # 1
          case var                    # 2 (0.8 + 4 * 0.2, rounded)
          when 1 then func_one
          when 2 then func_two
          when 3 then func_three
          when 4..10 then func_other
          end
        else                          # 1
          do_something until a && b   # 2
        end                           # ===
      end                             # 7 complexity points

      Method has too many lines. [12/10]
      Open

        def self.define_query_method_for(method_name, attribute_spec)
          # create the template code
          code =
            Proc.new do |term_or_terms, *options|
              options = options.first || {}
      Severity: Minor
      Found in app/models/pqf_query.rb by rubocop

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Method has too many lines. [11/10]
      Open

        def oai_datestamp_comparison(options = {})
          beginning = !options[:beginning].blank? ? options[:beginning] : nil
          ending = !options[:ending].blank? ? options[:ending] : nil
      
          if !beginning.nil? && !ending.nil?
      Severity: Minor
      Found in app/models/pqf_query.rb by rubocop

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Cyclomatic complexity for to_s is too high. [7/6]
      Open

        def to_s
          # handle the query as specified in standard ways so far
          full_query = @operators.join(' ') + ' ' + @query_parts.join(' ') + ' '
      
          # add special handling of searching URLs within dc subject
      Severity: Minor
      Found in app/models/pqf_query.rb by rubocop

      This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

      An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

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

        def to_s
          # handle the query as specified in standard ways so far
          full_query = @operators.join(' ') + ' ' + @query_parts.join(' ') + ' '
      
          # add special handling of searching URLs within dc subject
      Severity: Minor
      Found in app/models/pqf_query.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 oai_datestamp_comparison has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def oai_datestamp_comparison(options = {})
          beginning = !options[:beginning].blank? ? options[:beginning] : nil
          ending = !options[:ending].blank? ? options[:ending] : nil
      
          if !beginning.nil? && !ending.nil?
      Severity: Minor
      Found in app/models/pqf_query.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

      Avoid deeply nested control flow statements.
      Open

                    if (query_starts_with_not == true) && (term_count == 2)
                      # this just treats even terms found in
                      # Search.boolean_operators as regular words
                      # since their placement makes them meaningless as boolean operators
                      terms_array << term
      Severity: Major
      Found in app/models/pqf_query.rb - About 45 mins to fix

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

          def self.define_query_method_for(method_name, attribute_spec)
            # create the template code
            code =
              Proc.new do |term_or_terms, *options|
                options = options.first || {}
        Severity: Minor
        Found in app/models/pqf_query.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

        Avoid more than 3 levels of block nesting.
        Open

                    if term_count > 1
                      # in the rare case that @not has replaced
                      # @and at the front of the whole query
                      # and this is the second term
                      # skip adding a boolean operator
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for excessive nesting of conditional and looping constructs.

        You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

        The maximum level of nesting allowed is configurable.

        Avoid more than 3 levels of block nesting.
        Open

                    if term.casecmp('not').zero?
                      query_starts_with_not = true
                    else
                      terms_array << term
                    end
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for excessive nesting of conditional and looping constructs.

        You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

        The maximum level of nesting allowed is configurable.

        TODO found
        Open

          # TODO: make this more concise via singleton method?
        Severity: Minor
        Found in app/models/pqf_query.rb by fixme

        TODO found
        Open

          # TODO: my hash_fu is failing me, DRY this up
        Severity: Minor
        Found in app/models/pqf_query.rb by fixme

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          def creators_or_contributors_include(term_or_terms, options = {})
            query_part = '@or ' + creators_include(
              term_or_terms,
              options.merge({
                              only_return_as_string: true,
        Severity: Minor
        Found in app/models/pqf_query.rb and 1 other location - About 50 mins to fix
        app/models/pqf_query.rb on lines 271..288

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 43.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          def creators_or_contributors_equals_completely(term_or_terms, options = {})
            query_part = '@or ' + creators_equals_completely(
              term_or_terms,
              options.merge({
                              only_return_as_string: true,
        Severity: Minor
        Found in app/models/pqf_query.rb and 1 other location - About 50 mins to fix
        app/models/pqf_query.rb on lines 251..268

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 43.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

          QUALIFYING_ATTRIBUTE_SPECS = {
            'relevance' => '@attr 2=102 @attr 5=3 ', # we specify @attr 5=103, or fuzzy, separately now
            'exact' => '@attr 4=3 ', # this is meant for exact matches against key indexes
            'complete' => '@attr 6=3 ', # this is like exact, except to find exact matches against word or phrase indexes
            'partial' => '@attr 5=3 ',
        Severity: Minor
        Found in app/models/pqf_query.rb and 1 other location - About 20 mins to fix
        old_test/unit/pqf_query_test.rb on lines 29..42

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 27.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Use operators_array.size.positive? instead of operators_array.size > 0.
        Open

                if operators_array.size > 0
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

        The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

        The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

        Example: EnforcedStyle: predicate (default)

        # bad
        
        foo == 0
        0 > foo
        bar.baz > 0
        
        # good
        
        foo.zero?
        foo.negative?
        bar.baz.positive?

        Example: EnforcedStyle: comparison

        # bad
        
        foo.zero?
        foo.negative?
        bar.baz.positive?
        
        # good
        
        foo == 0
        0 > foo
        bar.baz > 0

        Use self-assignment shorthand +=.
        Open

              @sort_spec = @sort_spec +
                           '_sort' if Search.date_types.include?(@sort_spec) && !@sort_spec.include?('_sort')
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop enforces the use the shorthand for self-assignment.

        Example:

        # bad
        x = x + 1
        
        # good
        x += 1

        Favor a normal unless-statement over a modifier clause in a multiline statement.
        Open

          ATTRIBUTE_SPECS = {
            'oai_identifier' => '@attr 1=12 ',
            'oai_setspec' => '@attr 1=20 ',
            'description' => '@attr 1=1010 ',
            'relations' => '@attr 1=1026 ',
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        Checks for uses of if/unless modifiers with multiple-lines bodies.

        Example:

        # bad
        {
          result: 'this should not happen'
        } unless cond
        
        # good
        { result: 'ok' } if cond

        Favor a normal unless-statement over a modifier clause in a multiline statement.
        Open

          DATETIME_COMPARISON_SPECS = {
            'before' => QUALIFYING_ATTRIBUTE_SPECS['lt'],
            'after' => QUALIFYING_ATTRIBUTE_SPECS['gt'],
            'on' => QUALIFYING_ATTRIBUTE_SPECS['eq'],
            'on_or_before' => QUALIFYING_ATTRIBUTE_SPECS['le'],
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        Checks for uses of if/unless modifiers with multiple-lines bodies.

        Example:

        # bad
        {
          result: 'this should not happen'
        } unless cond
        
        # good
        { result: 'ok' } if cond

        Freeze mutable objects assigned to constants.
        Open

          DATETIME_SPECS = {
            'oai_datestamp' => ATTRIBUTE_SPECS['last_modified'],
            'last_modified' => ATTRIBUTE_SPECS['last_modified'],
            'date' => ATTRIBUTE_SPECS['date']
          } unless defined?(DATETIME_SPECS)
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

        Example:

        # bad
        CONST = [1, 2, 3]
        
        # good
        CONST = [1, 2, 3].freeze

        Redundant curly braces around a hash parameter.
        Open

              options.merge({
                              only_return_as_string: true,
                              operator: 'none'
                            })
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

        Example: EnforcedStyle: braces

        # The `braces` style enforces braces around all method
        # parameters that are hashes.
        
        # bad
        some_method(x, y, a: 1, b: 2)
        
        # good
        some_method(x, y, {a: 1, b: 2})

        Example: EnforcedStyle: no_braces (default)

        # The `no_braces` style checks that the last parameter doesn't
        # have braces around it.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        
        # good
        some_method(x, y, a: 1, b: 2)

        Example: EnforcedStyle: context_dependent

        # The `context_dependent` style checks that the last parameter
        # doesn't have braces around it, but requires braces if the
        # second to last parameter is also a hash literal.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
        
        # good
        some_method(x, y, a: 1, b: 2)
        some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

        Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
        Open

                if query_starts_with_not == true
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

        Example:

        # bad
        if condition
          do_stuff(bar)
        end
        
        unless qux.empty?
          Foo.do_something
        end
        
        # good
        do_stuff(bar) if condition
        Foo.do_something unless qux.empty?

        Freeze mutable objects assigned to constants.
        Open

          DATETIME_COMPARISON_SPECS = {
            'before' => QUALIFYING_ATTRIBUTE_SPECS['lt'],
            'after' => QUALIFYING_ATTRIBUTE_SPECS['gt'],
            'on' => QUALIFYING_ATTRIBUTE_SPECS['eq'],
            'on_or_before' => QUALIFYING_ATTRIBUTE_SPECS['le'],
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

        Example:

        # bad
        CONST = [1, 2, 3]
        
        # good
        CONST = [1, 2, 3].freeze

        Favor unless over if for negative conditions.
        Open

            if !@sort_spec.nil?
              # date specs when doing a non-sorting query
              # have a slightly different format (specifies structure of date normalized as @attr 4=5)
              # grab the correct spec for sorting
              @sort_spec = @sort_spec +
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

        - both
        - prefix
        - postfix

        Example: EnforcedStyle: both (default)

        # enforces `unless` for `prefix` and `postfix` conditionals
        
        # bad
        
        if !foo
          bar
        end
        
        # good
        
        unless foo
          bar
        end
        
        # bad
        
        bar if !foo
        
        # good
        
        bar unless foo

        Example: EnforcedStyle: prefix

        # enforces `unless` for just `prefix` conditionals
        
        # bad
        
        if !foo
          bar
        end
        
        # good
        
        unless foo
          bar
        end
        
        # good
        
        bar if !foo

        Example: EnforcedStyle: postfix

        # enforces `unless` for just `postfix` conditionals
        
        # bad
        
        bar if !foo
        
        # good
        
        bar unless foo
        
        # good
        
        if !foo
          bar
        end

        Convert if nested inside else to elsif.
        Open

                    if term_count > 1
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        If the else branch of a conditional consists solely of an if node, it can be combined with the else to become an elsif. This helps to keep the nesting level from getting too deep.

        Example:

        # bad
        if condition_a
          action_a
        else
          if condition_b
            action_b
          else
            action_c
          end
        end
        
        # good
        if condition_a
          action_a
        elsif condition_b
          action_b
        else
          action_c
        end

        Redundant curly braces around a hash parameter.
        Open

              options.merge({
                              only_return_as_string: true,
                              operator: 'none'
                            })
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

        Example: EnforcedStyle: braces

        # The `braces` style enforces braces around all method
        # parameters that are hashes.
        
        # bad
        some_method(x, y, a: 1, b: 2)
        
        # good
        some_method(x, y, {a: 1, b: 2})

        Example: EnforcedStyle: no_braces (default)

        # The `no_braces` style checks that the last parameter doesn't
        # have braces around it.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        
        # good
        some_method(x, y, a: 1, b: 2)

        Example: EnforcedStyle: context_dependent

        # The `context_dependent` style checks that the last parameter
        # doesn't have braces around it, but requires braces if the
        # second to last parameter is also a hash literal.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
        
        # good
        some_method(x, y, a: 1, b: 2)
        some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

        Redundant curly braces around a hash parameter.
        Open

              options.merge({
                              only_return_as_string: true,
                              operator: 'none'
                            })
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

        Example: EnforcedStyle: braces

        # The `braces` style enforces braces around all method
        # parameters that are hashes.
        
        # bad
        some_method(x, y, a: 1, b: 2)
        
        # good
        some_method(x, y, {a: 1, b: 2})

        Example: EnforcedStyle: no_braces (default)

        # The `no_braces` style checks that the last parameter doesn't
        # have braces around it.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        
        # good
        some_method(x, y, a: 1, b: 2)

        Example: EnforcedStyle: context_dependent

        # The `context_dependent` style checks that the last parameter
        # doesn't have braces around it, but requires braces if the
        # second to last parameter is also a hash literal.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
        
        # good
        some_method(x, y, a: 1, b: 2)
        some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

        Favor a normal unless-statement over a modifier clause in a multiline statement.
        Open

          QUALIFYING_ATTRIBUTE_SPECS = {
            'relevance' => '@attr 2=102 @attr 5=3 ', # we specify @attr 5=103, or fuzzy, separately now
            'exact' => '@attr 4=3 ', # this is meant for exact matches against key indexes
            'complete' => '@attr 6=3 ', # this is like exact, except to find exact matches against word or phrase indexes
            'partial' => '@attr 5=3 ',
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        Checks for uses of if/unless modifiers with multiple-lines bodies.

        Example:

        # bad
        {
          result: 'this should not happen'
        } unless cond
        
        # good
        { result: 'ok' } if cond

        Use proc instead of Proc.new.
        Open

              Proc.new do |term_or_terms, *options|
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cops checks for uses of Proc.new where Kernel#proc would be more appropriate.

        Example:

        # bad
        p = Proc.new { |n| puts n }
        
        # good
        p = proc { |n| puts n }

        Redundant curly braces around a hash parameter.
        Open

              options.merge({
                              only_return_as_string: true,
                              operator: 'none'
                            })
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

        Example: EnforcedStyle: braces

        # The `braces` style enforces braces around all method
        # parameters that are hashes.
        
        # bad
        some_method(x, y, a: 1, b: 2)
        
        # good
        some_method(x, y, {a: 1, b: 2})

        Example: EnforcedStyle: no_braces (default)

        # The `no_braces` style checks that the last parameter doesn't
        # have braces around it.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        
        # good
        some_method(x, y, a: 1, b: 2)

        Example: EnforcedStyle: context_dependent

        # The `context_dependent` style checks that the last parameter
        # doesn't have braces around it, but requires braces if the
        # second to last parameter is also a hash literal.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
        
        # good
        some_method(x, y, a: 1, b: 2)
        some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

        Redundant curly braces around a hash parameter.
        Open

              options.merge({
                              only_return_as_string: true,
                              operator: 'none'
                            })
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

        Example: EnforcedStyle: braces

        # The `braces` style enforces braces around all method
        # parameters that are hashes.
        
        # bad
        some_method(x, y, a: 1, b: 2)
        
        # good
        some_method(x, y, {a: 1, b: 2})

        Example: EnforcedStyle: no_braces (default)

        # The `no_braces` style checks that the last parameter doesn't
        # have braces around it.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        
        # good
        some_method(x, y, a: 1, b: 2)

        Example: EnforcedStyle: context_dependent

        # The `context_dependent` style checks that the last parameter
        # doesn't have braces around it, but requires braces if the
        # second to last parameter is also a hash literal.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
        
        # good
        some_method(x, y, a: 1, b: 2)
        some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

        Useless assignment to variable - query_part.
        Open

                query_part = create_query_part(options.merge({
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

        assigned but unused variable - foo

        Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

        Example:

        # bad
        
        def some_method
          some_var = 1
          do_something
        end

        Example:

        # good
        
        def some_method
          some_var = 1
          do_something(some_var)
        end

        Freeze mutable objects assigned to constants.
        Open

          ATTRIBUTE_SPECS = {
            'oai_identifier' => '@attr 1=12 ',
            'oai_setspec' => '@attr 1=20 ',
            'description' => '@attr 1=1010 ',
            'relations' => '@attr 1=1026 ',
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

        Example:

        # bad
        CONST = [1, 2, 3]
        
        # good
        CONST = [1, 2, 3].freeze

        Favor a normal unless-statement over a modifier clause in a multiline statement.
        Open

          DATETIME_SPECS = {
            'oai_datestamp' => ATTRIBUTE_SPECS['last_modified'],
            'last_modified' => ATTRIBUTE_SPECS['last_modified'],
            'date' => ATTRIBUTE_SPECS['date']
          } unless defined?(DATETIME_SPECS)
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        Checks for uses of if/unless modifiers with multiple-lines bodies.

        Example:

        # bad
        {
          result: 'this should not happen'
        } unless cond
        
        # good
        { result: 'ok' } if cond

        Favor a normal if-statement over a modifier clause in a multiline statement.
        Open

              @sort_spec = @sort_spec +
                           '_sort' if Search.date_types.include?(@sort_spec) && !@sort_spec.include?('_sort')
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        Checks for uses of if/unless modifiers with multiple-lines bodies.

        Example:

        # bad
        {
          result: 'this should not happen'
        } unless cond
        
        # good
        { result: 'ok' } if cond

        Freeze mutable objects assigned to constants.
        Open

          QUALIFYING_ATTRIBUTE_SPECS = {
            'relevance' => '@attr 2=102 @attr 5=3 ', # we specify @attr 5=103, or fuzzy, separately now
            'exact' => '@attr 4=3 ', # this is meant for exact matches against key indexes
            'complete' => '@attr 6=3 ', # this is like exact, except to find exact matches against word or phrase indexes
            'partial' => '@attr 5=3 ',
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

        Example:

        # bad
        CONST = [1, 2, 3]
        
        # good
        CONST = [1, 2, 3].freeze

        Use next to skip iteration.
        Open

            unless DO_NOT_AUTO_DEF_INCLUDE_METHODS_FOR.include?(spec_key)
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        Use next to skip iteration instead of a condition at the end.

        Example: EnforcedStyle: skipmodifierifs (default)

        # bad
        [1, 2].each do |a|
          if a == 1
            puts a
          end
        end
        
        # good
        [1, 2].each do |a|
          next unless a == 1
          puts a
        end
        
        # good
        [1, 2].each do |o|
          puts o unless o == 1
        end

        Example: EnforcedStyle: always

        # With `always` all conditions at the end of an iteration needs to be
        # replaced by next - with `skip_modifier_ifs` the modifier if like
        # this one are ignored: `[1, 2].each { |a| return 'yes' if a == 1 }`
        
        # bad
        [1, 2].each do |o|
          puts o unless o == 1
        end
        
        # bad
        [1, 2].each do |a|
          if a == 1
            puts a
          end
        end
        
        # good
        [1, 2].each do |a|
          next unless a == 1
          puts a
        end

        Redundant curly braces around a hash parameter.
        Open

            push_to_appropriate_variables({ query_part: query_part, operator: operator })
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

        Example: EnforcedStyle: braces

        # The `braces` style enforces braces around all method
        # parameters that are hashes.
        
        # bad
        some_method(x, y, a: 1, b: 2)
        
        # good
        some_method(x, y, {a: 1, b: 2})

        Example: EnforcedStyle: no_braces (default)

        # The `no_braces` style checks that the last parameter doesn't
        # have braces around it.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        
        # good
        some_method(x, y, a: 1, b: 2)

        Example: EnforcedStyle: context_dependent

        # The `context_dependent` style checks that the last parameter
        # doesn't have braces around it, but requires braces if the
        # second to last parameter is also a hash literal.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
        
        # good
        some_method(x, y, a: 1, b: 2)
        some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

        Useless assignment to variable - terms.
        Open

            terms = terms_to_a(terms)
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

        assigned but unused variable - foo

        Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

        Example:

        # bad
        
        def some_method
          some_var = 1
          do_something
        end

        Example:

        # good
        
        def some_method
          some_var = 1
          do_something(some_var)
        end

        Redundant curly braces around a hash parameter.
        Open

                query_part = create_query_part(options.merge({
                                                               attribute_spec: attribute_spec,
                                                               term_or_terms: terms
                                                             }))
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

        Example: EnforcedStyle: braces

        # The `braces` style enforces braces around all method
        # parameters that are hashes.
        
        # bad
        some_method(x, y, a: 1, b: 2)
        
        # good
        some_method(x, y, {a: 1, b: 2})

        Example: EnforcedStyle: no_braces (default)

        # The `no_braces` style checks that the last parameter doesn't
        # have braces around it.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        
        # good
        some_method(x, y, a: 1, b: 2)

        Example: EnforcedStyle: context_dependent

        # The `context_dependent` style checks that the last parameter
        # doesn't have braces around it, but requires braces if the
        # second to last parameter is also a hash literal.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
        
        # good
        some_method(x, y, a: 1, b: 2)
        some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

        Convert if nested inside else to elsif.
        Open

                        if Search.boolean_operators.include?(term.downcase)
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        If the else branch of a conditional consists solely of an if node, it can be combined with the else to become an elsif. This helps to keep the nesting level from getting too deep.

        Example:

        # bad
        if condition_a
          action_a
        else
          if condition_b
            action_b
          else
            action_c
          end
        end
        
        # good
        if condition_a
          action_a
        elsif condition_b
          action_b
        else
          action_c
        end

        Favor unless over if for negative conditions.
        Open

            if !terms.blank?
              if terms.size > 1
        
                # work through terms
                # if there is a boolean operator specified
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

        - both
        - prefix
        - postfix

        Example: EnforcedStyle: both (default)

        # enforces `unless` for `prefix` and `postfix` conditionals
        
        # bad
        
        if !foo
          bar
        end
        
        # good
        
        unless foo
          bar
        end
        
        # bad
        
        bar if !foo
        
        # good
        
        bar unless foo

        Example: EnforcedStyle: prefix

        # enforces `unless` for just `prefix` conditionals
        
        # bad
        
        if !foo
          bar
        end
        
        # good
        
        unless foo
          bar
        end
        
        # good
        
        bar if !foo

        Example: EnforcedStyle: postfix

        # enforces `unless` for just `postfix` conditionals
        
        # bad
        
        bar if !foo
        
        # good
        
        bar unless foo
        
        # good
        
        if !foo
          bar
        end

        Useless assignment to variable - no_relevance_query_string.
        Open

              no_relevance_query_string =
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

        assigned but unused variable - foo

        Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

        Example:

        # bad
        
        def some_method
          some_var = 1
          do_something
        end

        Example:

        # good
        
        def some_method
          some_var = 1
          do_something(some_var)
        end

        Redundant curly braces around a hash parameter.
        Open

              options.merge({
                              only_return_as_string: true,
                              operator: 'none'
                            })
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

        Example: EnforcedStyle: braces

        # The `braces` style enforces braces around all method
        # parameters that are hashes.
        
        # bad
        some_method(x, y, a: 1, b: 2)
        
        # good
        some_method(x, y, {a: 1, b: 2})

        Example: EnforcedStyle: no_braces (default)

        # The `no_braces` style checks that the last parameter doesn't
        # have braces around it.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        
        # good
        some_method(x, y, a: 1, b: 2)

        Example: EnforcedStyle: context_dependent

        # The `context_dependent` style checks that the last parameter
        # doesn't have braces around it, but requires braces if the
        # second to last parameter is also a hash literal.
        
        # bad
        some_method(x, y, {a: 1, b: 2})
        some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
        
        # good
        some_method(x, y, a: 1, b: 2)
        some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

        Use !empty? instead of size > 0.
        Open

                if operators_array.size > 0
        Severity: Minor
        Found in app/models/pqf_query.rb by rubocop

        This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.

        Example:

        # bad
        [1, 2, 3].length == 0
        0 == "foobar".length
        array.length < 1
        {a: 1, b: 2}.length != 0
        string.length > 0
        hash.size > 0
        
        # good
        [1, 2, 3].empty?
        "foobar".empty?
        array.empty?
        !{a: 1, b: 2}.empty?
        !string.empty?
        !hash.empty?

        There are no issues that match your filters.

        Category
        Status