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
- Read upRead up
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'
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
Class IndexerCommon
has 50 methods (exceeds 20 allowed). Consider refactoring. Open
class IndexerCommon
include JSONModel
@@record_types = IndexerCommonConfig.record_types
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
- Read upRead up
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)
- Read upRead up
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']}
- Read upRead up
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']
- Read upRead up
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
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)
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
- Read upRead up
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
- Read upRead up
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'])
- Read upRead up
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
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']
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]
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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)
- Read upRead up
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
- Read upRead up
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)}
- Read upRead up
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']
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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']
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76