Method process_file_versions
has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring. Open
def process_file_versions(json)
dig_f = {}
unless json['file_versions'].blank?
embed_caption = ''
rep_caption = ''
- 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 handle_dates
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
def handle_dates(json)
json['html'] = {} if !json.dig('html')
json['html']['dates'] = []
json['dates'].each do |date|
label = date['label'].blank? ? '' : "#{date['label'].titlecase}: "
- 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 process_digital_instance
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
def process_digital_instance(instances)
dig_objs = []
if instances && instances.is_a?(Array)
instances.each do |instance|
unless !instance.dig('digital_object', '_resolved')
- 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 process_repo_info
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def process_repo_info(repo)
info = {}
info['top'] = {}
unless repo.nil?
%w(name uri url parent_institution_name image_url repo_code description).each do |item|
- 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 get_rep_image
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def get_rep_image(instances)
rep = {}
if instances && instances.is_a?(Array)
instances.each do |instance|
unless instance['digital_object'].blank? || instance['digital_object']['_resolved'].blank?
- 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 process_extents
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def process_extents(json)
unless json['extents'].blank?
json['html'] = {} if !json.dig('html')
json['html']['extents'] = []
json['extents'].each do |ext|
- 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 process_digital
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def process_digital(json)
dig_obj = {}
unless json['digital_object_id'].blank? || !json['digital_object_id'].start_with?('http')
dig_obj['out'] = json['digital_object_id']
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 handle_external_docs
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def handle_external_docs(json)
unless !json.has_key?('external_documents') || json['external_documents'].blank?
json['html'] = {} if !json.dig('html')
json['html']['external_documents'] = []
json['external_documents'].each do |doc|
- 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 process_agents
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def process_agents(agents_arr, subjects_arr = [])
agents_h = {}
agents_arr.each do |agent|
unless agent['role'].blank? || agent['_resolved'].blank?
role = agent['role']
- 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 process_file_versions
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process_file_versions(json)
dig_f = {}
unless json['file_versions'].blank?
embed_caption = ''
rep_caption = ''
Avoid deeply nested control flow statements. Open
rep_caption = version['title'] if version['is_representative']
Avoid deeply nested control flow statements. Open
rep_caption = version['caption'] if version['is_representative']
Method breadcrumb_info
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def breadcrumb_info
context = [] # FIXME get_path(@tree)
path = [] # FIXME @tree.dig('path_to_root')
unless !path || !path.is_a?(Array) || path.size == 0
type = path[0].dig('node_type')
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if in_h['address_1'].present?
info['address'] = []
[1, 2, 3].each do |i|
info['address'].push(in_h["address_#{i}"]) if in_h["address_#{i}"].present?
- 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 33.
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