archivesspace/archivesspace

View on GitHub
indexer/app/lib/indexer_common.rb

Summary

Maintainability
F
1 wk
Test Coverage

Method configure_doc_rules has a Cognitive Complexity of 199 (exceeds 5 allowed). Consider refactoring.
Open

  def configure_doc_rules

    add_document_prepare_hook {|doc, record|
      found_keys = Set.new

Severity: Minor
Found in indexer/app/lib/indexer_common.rb - About 4 days 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

File indexer_common.rb has 1095 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'ashttp'
require 'uri'
require 'json'
require 'fileutils'
require 'aspace_i18n'
Severity: Major
Found in indexer/app/lib/indexer_common.rb - About 2 days to fix

    Method configure_doc_rules has 536 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def configure_doc_rules
    
        add_document_prepare_hook {|doc, record|
          found_keys = Set.new
    
    
    Severity: Major
    Found in indexer/app/lib/indexer_common.rb - About 2 days to fix

      Class IndexerCommon has 50 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class IndexerCommon
      
        include JSONModel
      
        @@record_types = IndexerCommonConfig.record_types
      Severity: Minor
      Found in indexer/app/lib/indexer_common.rb - About 7 hrs to fix

        Method extract_string_values has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.extract_string_values(doc, *opts)
            return doc, doc if doc.is_a?(String)
        
            if doc.is_a?(Array)
              published_queue = doc.flatten
        Severity: Minor
        Found in indexer/app/lib/indexer_common.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

        Method index_records has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
        Open

          def index_records(records, timing = IndexerTiming.new)
            batch = IndexBatch.new
        
            records = dedupe_by_uri(records)
        
        
        Severity: Minor
        Found in indexer/app/lib/indexer_common.rb - About 3 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

        Method add_agents has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          def add_agents(doc, record)
            if record['record']['linked_agents']
              # index all linked agents first
              doc['agents'] = record['record']['linked_agents'].collect{|link| link['_resolved']['display_name']['sort_name']}
              doc['agent_uris'] = record['record']['linked_agents'].collect{|link| link['ref']}
        Severity: Minor
        Found in indexer/app/lib/indexer_common.rb - About 2 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

        Method apply_pui_fields has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          def apply_pui_fields(doc, record)
            # only add pui types if the record is published
            if doc['publish']
              object_record_types = ['accession', 'digital_object', 'digital_object_component']
        
        
        Severity: Minor
        Found in indexer/app/lib/indexer_common.rb - About 2 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

        Method extract_string_values has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.extract_string_values(doc, *opts)
            return doc, doc if doc.is_a?(String)
        
            if doc.is_a?(Array)
              published_queue = doc.flatten
        Severity: Major
        Found in indexer/app/lib/indexer_common.rb - About 2 hrs to fix

          Method index_records has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def index_records(records, timing = IndexerTiming.new)
              batch = IndexBatch.new
          
              records = dedupe_by_uri(records)
          
          
          Severity: Minor
          Found in indexer/app/lib/indexer_common.rb - About 1 hr to fix

            Method enum_fields has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

              def enum_fields
                return @enum_fields if @enum_fields
            
                enum_fields = []
                queue = JSONModel.models.map {|_,model| model.schema['properties']}.flatten.uniq
            Severity: Minor
            Found in indexer/app/lib/indexer_common.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 sanitize_json has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              def sanitize_json(json)
                IndexerCommonConfig.do_not_index.each do |k, v|
                  if json["jsonmodel_type"] == k
                    # subrec is a reference used to navigate inside of the JSON as specified by the v[:location] to find the part of the tree to sanitize
                    subrec = json
            Severity: Minor
            Found in indexer/app/lib/indexer_common.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 add_years has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              def add_years(doc, record)
                if record['record']['dates']
                  doc['years'] = []
                  record['record']['dates'].each do |date|
                    doc['years'] += IndexerCommon.generate_years_for_date_range(date['begin'], date['end'])
            Severity: Minor
            Found in indexer/app/lib/indexer_common.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 index_batch has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def index_batch(batch, timing = IndexerTiming.new, opts = {})
                timing ||= IndexerTiming.new
            
                timing.time_block(:batch_hooks_ms) do
                  # Allow hooks to operate on the entire batch if desired
            Severity: Minor
            Found in indexer/app/lib/indexer_common.rb - About 1 hr to fix

              Method apply_pui_fields has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def apply_pui_fields(doc, record)
                  # only add pui types if the record is published
                  if doc['publish']
                    object_record_types = ['accession', 'digital_object', 'digital_object_component']
              
              
              Severity: Minor
              Found in indexer/app/lib/indexer_common.rb - About 1 hr to fix

                Method add_subjects_subrecord has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def add_subjects_subrecord(doc, record, subrecord, type = 'subjects')
                    doc['subjects'] ||= []
                    doc['subject_uris'] ||= []
                
                    if record['record'][subrecord]
                Severity: Minor
                Found in indexer/app/lib/indexer_common.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

                Method add_summary has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def add_summary(doc, record)
                    if record['record'].has_key?('notes') && record['record']['notes'].is_a?(Array)
                      notes = record['record']['notes']
                      abstract = notes.find {|note| note['type'] == 'abstract'}
                      if abstract
                Severity: Minor
                Found in indexer/app/lib/indexer_common.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

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

                  def index_batch(batch, timing = IndexerTiming.new, opts = {})
                    timing ||= IndexerTiming.new
                
                    timing.time_block(:batch_hooks_ms) do
                      # Allow hooks to operate on the entire batch if desired
                Severity: Minor
                Found in indexer/app/lib/indexer_common.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 t has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def t(*args)
                    if @@selenium
                      args[0]
                    else
                      args << {} unless args.last.is_a?(Hash)
                Severity: Minor
                Found in indexer/app/lib/indexer_common.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

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

                  def self.generate_years_for_date_range(begin_date, end_date)
                    return [] unless begin_date
                
                    end_date ||= begin_date
                
                
                Severity: Minor
                Found in indexer/app/lib/indexer_common.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

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

                  def clean_whitespace(doc)
                    if doc.is_a?(String) && !doc.frozen?
                      doc.strip!
                    elsif doc.is_a?(Hash)
                      doc.values.each {|v| clean_whitespace(v)}
                Severity: Minor
                Found in indexer/app/lib/indexer_common.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

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

                      if record['record']['location_profile']
                        doc['location_profile_uri_u_sstr'] = record['record']['location_profile']['ref']
                        doc['location_profile_display_string_u_ssort'] = record['record']['location_profile']['_resolved']['display_string']
                Severity: Minor
                Found in indexer/app/lib/indexer_common.rb and 1 other location - About 25 mins to fix
                indexer/app/lib/indexer_common.rb on lines 814..816

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

                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

                        if record['record']['container_profile']
                          doc['container_profile_uri_u_sstr'] = record['record']['container_profile']['ref']
                          doc['container_profile_display_string_u_sstr'] = record['record']['container_profile']['_resolved']['display_string']
                Severity: Minor
                Found in indexer/app/lib/indexer_common.rb and 1 other location - About 25 mins to fix
                indexer/app/lib/indexer_common.rb on lines 914..916

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

                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

                There are no issues that match your filters.

                Category
                Status