SpeciesFileGroup/taxonworks

View on GitHub
lib/queries/taxon_name/filter.rb

Summary

Maintainability
D
1 day
Test Coverage

Class Filter has 34 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Filter < Queries::Query

      include Queries::Helpers

      include Queries::Concerns::Tags
Severity: Minor
Found in lib/queries/taxon_name/filter.rb - About 4 hrs to fix

    File filter.rb has 334 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Queries
      module TaxonName
    
        # https://api.taxonworks.org/#/taxon_names
        class Filter < Queries::Query
    Severity: Minor
    Found in lib/queries/taxon_name/filter.rb - About 4 hrs to fix

      Method has too many lines. [30/25]
      Open

            def initialize(params)
              @author = params[:author]
              @authors = boolean_param(params, :authors )
              @citations = params[:citations]
              @descendants = boolean_param(params,:descendants )
      Severity: Minor
      Found in lib/queries/taxon_name/filter.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 initialize has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def initialize(params)
              @author = params[:author]
              @authors = boolean_param(params, :authors )
              @citations = params[:citations]
              @descendants = boolean_param(params,:descendants )
      Severity: Minor
      Found in lib/queries/taxon_name/filter.rb - About 1 hr to fix

        Method all has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def all
                a = and_clauses
                b = merge_clauses
        
                q = nil
        Severity: Minor
        Found in lib/queries/taxon_name/filter.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def initialize(params)
                @author = params[:author]
                @authors = boolean_param(params, :authors )
                @citations = params[:citations]
                @descendants = boolean_param(params,:descendants )
        Severity: Minor
        Found in lib/queries/taxon_name/filter.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

        Use params[:taxon_name_author_ids].presence || [] instead of params[:taxon_name_author_ids].blank? ? [] : params[:taxon_name_author_ids].
        Open

                @taxon_name_author_ids = params[:taxon_name_author_ids].blank? ? [] : params[:taxon_name_author_ids]
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by rubocop

        This cop checks code that can be written more easily using Object#presence defined by Active Support.

        Example:

        # bad
        a.present? ? a : nil
        
        # bad
        !a.present? ? nil : a
        
        # bad
        a.blank? ? nil : a
        
        # bad
        !a.blank? ? a : nil
        
        # good
        a.presence

        Example:

        # bad
        a.present? ? a : b
        
        # bad
        !a.present? ? b : a
        
        # bad
        a.blank? ? b : a
        
        # bad
        !a.blank? ? a : b
        
        # good
        a.presence || b

        TODO found
        Open

              # TODO: probably should be an array for API purposes.
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by fixme

        TODO found
        Open

              # TODO: dry with Source, CollectingEvent , etc.
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by fixme

        TODO found
        Open

              # TODO: inverse is duplicated in autocomplete
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by fixme

        TODO found
        Open

              # TODO: unify globally as to whether param belongs here, or at controller level.
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by fixme

        TODO found
        Open

              # TODO: deprecate for Queries::Concerns::User
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by fixme

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

              def matching_taxon_name_author_ids
                return nil if taxon_name_author_ids.empty?
                o = table
                r = ::Role.arel_table
        
        
        Severity: Major
        Found in lib/queries/taxon_name/filter.rb and 2 other locations - About 3 hrs to fix
        lib/queries/collecting_event/filter.rb on lines 140..165
        lib/queries/source/filter.rb on lines 218..243

        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 114.

        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 3 locations. Consider refactoring.
        Open

              def author_facet
                return nil if author.blank?
                if exact
                  table[:cached_author_year].eq(author.strip)
                else
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb and 2 other locations - About 20 mins to fix
        lib/queries/content/filter.rb on lines 81..86
        lib/queries/taxon_name/filter.rb on lines 400..405

        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 28.

        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 3 locations. Consider refactoring.
        Open

              def type_metadata_facet
                return nil if type_metadata.nil?
                subquery = ::TypeMaterial.where(::TypeMaterial.arel_table[:protonym_id].eq(::TaxonName.arel_table[:id])).arel.exists
                ::TaxonName.where(type_metadata ? subquery : subquery.not)
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb and 2 other locations - About 20 mins to fix
        lib/queries/taxon_name/filter.rb on lines 263..266
        lib/queries/taxon_name/filter.rb on lines 361..364

        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 28.

        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 3 locations. Consider refactoring.
        Open

              def otus_facet
                return nil if otus.nil?
                subquery = ::Otu.where(::Otu.arel_table[:taxon_name_id].eq(::TaxonName.arel_table[:id])).arel.exists
                ::TaxonName.where(otus ? subquery : subquery.not)
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb and 2 other locations - About 20 mins to fix
        lib/queries/taxon_name/filter.rb on lines 354..357
        lib/queries/taxon_name/filter.rb on lines 361..364

        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 28.

        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 3 locations. Consider refactoring.
        Open

              def otus_facet
                return nil if otus.nil?
                subquery = ::Otu.where(::Otu.arel_table[:taxon_name_id].eq(::TaxonName.arel_table[:id])).arel.exists
                ::TaxonName.where(otus ? subquery : subquery.not)
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb and 2 other locations - About 20 mins to fix
        lib/queries/taxon_name/filter.rb on lines 263..266
        lib/queries/taxon_name/filter.rb on lines 354..357

        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 28.

        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 3 locations. Consider refactoring.
        Open

              def cached_name
                return nil if name.blank?
                if exact
                  table[:cached].eq(name.strip)
                else
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb and 2 other locations - About 20 mins to fix
        lib/queries/content/filter.rb on lines 81..86
        lib/queries/taxon_name/filter.rb on lines 414..419

        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 28.

        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

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

                  ::TaxonName.where(table[:cached].matches("%NOT SPECIFIED%").or(
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

                    table[:cached_original_combination].does_not_match("%NOT SPECIFIED%")))
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

                  ::TaxonName.where(table[:cached].does_not_match("%NOT SPECIFIED%").and(
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

                a = o.alias("a_")
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

                    table[:cached_original_combination].matches("%NOT SPECIFIED%")))
        Severity: Minor
        Found in lib/queries/taxon_name/filter.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        There are no issues that match your filters.

        Category
        Status