SpeciesFileGroup/taxonworks

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

Summary

Maintainability
C
1 day
Test Coverage

Method initialize has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(params)
        @author = params[:author]
        @authors = (params[:authors]&.downcase == 'true' ? true : false) if !params[:authors].nil?
        @citations = params[:citations]
        @descendants = (params[:descendants]&.downcase == 'true' ? true : false) if !params[:descendants].nil?
Severity: Minor
Found in lib/queries/taxon_name/filter.rb - About 4 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

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

    class Filter < Queries::Query

      include Queries::Concerns::Tags
 
      # @param name [String]
Severity: Minor
Found in lib/queries/taxon_name/filter.rb - About 3 hrs to fix

    Method all has a Cognitive Complexity of 6 (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 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

    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: support here?
    Severity: Minor
    Found in lib/queries/taxon_name/filter.rb by fixme

    TODO found
    Open

                ::TaxonNameHierarchy.arel_table[:ancestor_id].in(taxon_name_id)) # TODO- in is likely not the most optimal
    Severity: Minor
    Found in lib/queries/taxon_name/filter.rb by fixme

    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: unify globally as to whether param belongs here, or at controller level.
    Severity: Minor
    Found in lib/queries/taxon_name/filter.rb by fixme

    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 171..174
    lib/queries/taxon_name/filter.rb on lines 232..235

    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 171..174
    lib/queries/taxon_name/filter.rb on lines 225..228

    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 2 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 1 other location - About 20 mins to fix
    lib/queries/taxon_name/filter.rb on lines 280..285

    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 2 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 1 other location - About 20 mins to fix
    lib/queries/taxon_name/filter.rb on lines 271..276

    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 225..228
    lib/queries/taxon_name/filter.rb on lines 232..235

    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

    Useless protected access modifier.
    Open

          protected
    Severity: Minor
    Found in lib/queries/taxon_name/filter.rb by rubocop

    This cop checks for redundant access modifiers, including those with no code, those which are repeated, and leading public modifiers in a class or module body. Conditionally-defined methods are considered as always being defined, and thus access modifiers guarding such methods are not redundant.

    Example:

    class Foo
      public # this is redundant (default access is public)
    
      def method
      end
    
      private # this is not redundant (a method is defined)
      def method2
      end
    
      private # this is redundant (no following methods are defined)
    end

    Example:

    class Foo
      # The following is not redundant (conditionally defined methods are
      # considered as always defining a method)
      private
    
      if condition?
        def method
        end
      end
    
      protected # this is not redundant (method is defined)
    
      define_method(:method2) do
      end
    
      protected # this is redundant (repeated from previous modifier)
    
      [1,2,3].each do |i|
        define_method("foo#{i}") do
        end
      end
    
      # The following is redundant (methods defined on the class'
      # singleton class are not affected by the public modifier)
      public
    
      def self.method3
      end
    end

    Example:

    # Lint/UselessAccessModifier:
    #   ContextCreatingMethods:
    #     - concerning
    require 'active_support/concern'
    class Foo
      concerning :Bar do
        def some_public_method
        end
    
        private
    
        def some_private_method
        end
      end
    
      # this is not redundant because `concerning` created its own context
      private
    
      def some_other_private_method
      end
    end

    Example:

    # Lint/UselessAccessModifier:
    #   MethodCreatingMethods:
    #     - delegate
    require 'active_support/core_ext/module/delegation'
    class Foo
      # this is not redundant because `delegate` creates methods
      private
    
      delegate :method_a, to: :method_b
    end

    There are no issues that match your filters.

    Category
    Status