SpeciesFileGroup/taxonworks

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

Summary

Maintainability
D
2 days
Test Coverage

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

module Queries
  module CollectionObject

    # TODO
    # - use date processing? / DateConcern
Severity: Minor
Found in lib/queries/collection_object/filter.rb - About 6 hrs to fix

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

        class Filter < Queries::Query
    
          include Queries::Helpers
    
          include Queries::Concerns::Tags
    Severity: Minor
    Found in lib/queries/collection_object/filter.rb - About 5 hrs to fix

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

            def initialize(params)
              params.reject!{ |_k, v| v.blank? } # dump all entries with empty values
      
              # Only CollectingEvent fields are permitted now.
              # (Perhaps) TODO: allow concern attributes nested inside as well, e.g. show me all COs with this Tag on CE.

      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. [34/25]
      Open

            def base_merge_clauses
              clauses = []
              clauses += collecting_event_merge_clauses + collecting_event_and_clauses
      
              clauses += [

      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 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def initialize(params)
              params.reject!{ |_k, v| v.blank? } # dump all entries with empty values
      
              # Only CollectingEvent fields are permitted now.
              # (Perhaps) TODO: allow concern attributes nested inside as well, e.g. show me all COs with this Tag on CE.
      Severity: Minor
      Found in lib/queries/collection_object/filter.rb - About 1 hr to fix

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

              def initialize(params)
                params.reject!{ |_k, v| v.blank? } # dump all entries with empty values
        
                # Only CollectingEvent fields are permitted now.
                # (Perhaps) TODO: allow concern attributes nested inside as well, e.g. show me all COs with this Tag on CE.
        Severity: Minor
        Found in lib/queries/collection_object/filter.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 base_merge_clauses has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def base_merge_clauses
                clauses = []
                clauses += collecting_event_merge_clauses + collecting_event_and_clauses
        
                clauses += [
        Severity: Minor
        Found in lib/queries/collection_object/filter.rb - About 1 hr 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
                  if a && b
          Severity: Minor
          Found in lib/queries/collection_object/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[:sled_image_id].presence instead of params[:sled_image_id].blank? ? nil : params[:sled_image_id].
          Open

                  @sled_image_id = params[:sled_image_id].blank? ? nil : params[:sled_image_id]

          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

          Use params[:ancestor_id].presence instead of params[:ancestor_id].blank? ? nil : params[:ancestor_id].
          Open

                  @ancestor_id = params[:ancestor_id].blank? ? nil : params[:ancestor_id]

          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

          Use params[:type_specimen_taxon_name_id].presence instead of params[:type_specimen_taxon_name_id].blank? ? nil : params[:type_specimen_taxon_name_id].
          Open

                  @type_specimen_taxon_name_id = params[:type_specimen_taxon_name_id].blank? ? nil : params[:type_specimen_taxon_name_id]

          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

          Use params[:repository_id].presence instead of params[:repository_id].blank? ? nil : params[:repository_id].
          Open

                  @repository_id = params[:repository_id].blank? ? nil : params[:repository_id]

          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

          Use params[:collection_object_type].presence instead of params[:collection_object_type].blank? ? nil : params[:collection_object_type].
          Open

                  @collection_object_type = params[:collection_object_type].blank? ? nil : params[:collection_object_type]

          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

          TODO found
          Open

                  # (Perhaps) TODO: allow concern attributes nested inside as well, e.g. show me all COs with this Tag on CE.

          TODO found
          Open

                # TODO: DRY with Source (author), TaxonName, etc.

          TODO found
          Open

                # TODO: look for name collisions with CE filter

          TODO found
          Open

                # TODO: is this used?

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

                def all
                  a = and_clauses
                  b = merge_clauses
                  # q = nil
                  if a && b
          Severity: Minor
          Found in lib/queries/collection_object/filter.rb and 1 other location - About 45 mins to fix
          lib/queries/extract/filter.rb on lines 103..118

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

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

                def type_material_type_facet
                  return nil if is_type.empty?
          
                  w = type_materials_table[:collection_object_id].eq(table[:id])
                    .and( type_materials_table[:type_type].eq_any(is_type) )
          Severity: Minor
          Found in lib/queries/collection_object/filter.rb and 3 other locations - About 20 mins to fix
          lib/queries/collection_object/filter.rb on lines 579..586
          lib/queries/image/filter.rb on lines 292..299
          lib/queries/image/filter.rb on lines 304..311

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

                def type_by_taxon_name_facet
                  return nil if type_specimen_taxon_name_id.nil?
          
                  w = type_materials_table[:collection_object_id].eq(table[:id])
                    .and( type_materials_table[:protonym_id].eq(type_specimen_taxon_name_id) )
          Severity: Minor
          Found in lib/queries/collection_object/filter.rb and 3 other locations - About 20 mins to fix
          lib/queries/collection_object/filter.rb on lines 591..598
          lib/queries/image/filter.rb on lines 292..299
          lib/queries/image/filter.rb on lines 304..311

          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

                  ::CollectionObject::BiologicalCollectionObject.joins(:depictions).where("depictions.sled_image_id = ?", sled_image_id)

          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_")

          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