Method do_parse_json
has a Cognitive Complexity of 341 (exceeds 5 allowed). Consider refactoring. Open
def do_parse_json(data_type, model, json, options, json_schema, record = nil, new_record = nil, container = nil, container_schema = nil)
add_new = options.delete(:add_new)
updating = !(record.nil? && new_record.nil?) || options[:add_only]
(primary_fields = options.delete(:primary_field) || options.delete('primary_field')).present? ||
(primary_fields = json.is_a?(Hash) && json['_primary']).present? ||
- 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 do_parse_xml
has a Cognitive Complexity of 191 (exceeds 5 allowed). Consider refactoring. Open
def do_parse_xml(data_type, model, element, options, json_schema, record = nil, new_record = nil, enclosed_property = nil, container = nil, container_schema = nil)
updating = !(record.nil? && new_record.nil?) || options[:add_only]
json_schema = data_type.merge_schema(json_schema)
name = json_schema['edi']['segment'] if json_schema['edi']
name ||= enclosed_property || model.data_type.name
- 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 do_parse_edi
has a Cognitive Complexity of 177 (exceeds 5 allowed). Consider refactoring. Open
def do_parse_edi(data_type, model, content, json_schema, start, field_sep, segment_sep, report, options = {})
record = options[:record] || options[:new_record] || model.new
json = options[:json]
fields = options[:fields]
segment = options[:segment]
- 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 parser.rb
has 590 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Edi
class Parser
class << self
Method do_parse_json
has 211 lines of code (exceeds 25 allowed). Consider refactoring. Open
def do_parse_json(data_type, model, json, options, json_schema, record = nil, new_record = nil, container = nil, container_schema = nil)
add_new = options.delete(:add_new)
updating = !(record.nil? && new_record.nil?) || options[:add_only]
(primary_fields = options.delete(:primary_field) || options.delete('primary_field')).present? ||
(primary_fields = json.is_a?(Hash) && json['_primary']).present? ||
Method do_parse_edi
has 143 lines of code (exceeds 25 allowed). Consider refactoring. Open
def do_parse_edi(data_type, model, content, json_schema, start, field_sep, segment_sep, report, options = {})
record = options[:record] || options[:new_record] || model.new
json = options[:json]
fields = options[:fields]
segment = options[:segment]
Method do_parse_xml
has 136 lines of code (exceeds 25 allowed). Consider refactoring. Open
def do_parse_xml(data_type, model, element, options, json_schema, record = nil, new_record = nil, enclosed_property = nil, container = nil, container_schema = nil)
updating = !(record.nil? && new_record.nil?) || options[:add_only]
json_schema = data_type.merge_schema(json_schema)
name = json_schema['edi']['segment'] if json_schema['edi']
name ||= enclosed_property || model.data_type.name
Method do_parse_xml
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
def do_parse_xml(data_type, model, element, options, json_schema, record = nil, new_record = nil, enclosed_property = nil, container = nil, container_schema = nil)
Method process_options
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process_options(options)
p =
case (p = options.delete(:primary_fields) || options.delete('primary_fields'))
when Array
p
Method do_parse_json
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
def do_parse_json(data_type, model, json, options, json_schema, record = nil, new_record = nil, container = nil, container_schema = nil)
Method do_parse_edi
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
def do_parse_edi(data_type, model, content, json_schema, start, field_sep, segment_sep, report, options = {})
Method parse_edi
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def parse_edi(data_type, content, options = {}, record = nil)
start = options[:start] || 0
content = content.gsub("\r", '')
segment_sep = "\n" if (segment_sep = options[:segment_separator]) == :new_line
raise Exception.new("Record model #{record.orm_model} does not match data type model#{data_type.orm_model}") unless record.nil? || record.orm_model == data_type.records_model
- 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_options
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def process_options(options)
p =
case (p = options.delete(:primary_fields) || options.delete('primary_fields'))
when Array
p
- 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
Avoid deeply nested control flow statements. Open
next unless updating || !property_model&.modelable? || record.send(property_name).nil?
Avoid deeply nested control flow statements. Open
raise Exception.new('Can not infers segment separator without EDI segment metadata in next sub-segment schema') unless next_seg_schema['edi'] && next_seg_id = next_seg_schema['edi']['segment']
Method find_record
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def find_record(model, container, container_schema)
yield(criteria = {})
if criteria.empty?
nil
else
- 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
Avoid deeply nested control flow statements. Open
if (association_track = associations[property])
next unless associations[:kept]
sub_values = association_track[:new]
else
associations[property] = {
Avoid deeply nested control flow statements. Open
if persist && sub_value['_reference'] && ((sub_value[:id].nil? && sub_value[:_id].nil?) || options[:skip_refs_binding])
sub_value = Cenit::Utility.deep_remove(sub_value, '_reference')
unless Cenit::Utility.find_record(sub_value, association)
unless (references = record.instance_variable_get(:@_references))
record.instance_variable_set(:@_references, references = {})
Avoid deeply nested control flow statements. Open
if (length = property_schema['length']) || ((length = property_schema['maxLength']) && (property_schema['auto_fill'] || length == property_schema['minLength']))
cursor += length
else
raise Exception.new("property #{property_name} has no fixed length or auto fill option is missing while parsing with fixed length option")
end
Avoid deeply nested control flow statements. Open
if json.key?(name)
record.send("#{property_name}=", json[name])
end
Avoid deeply nested control flow statements. Open
length = top - start if start + length >= top
Avoid deeply nested control flow statements. Open
if (sub_record = do_parse_xml(data_type, property_model, sub_element, options, items_schema, nil, nil, property, association, property_schema)) &&
(sub_values || association).exclude?(sub_record)
(sub_values || association) << sub_record
end
Avoid deeply nested control flow statements. Open
if (existing = Cenit::Utility.find_record({ id: json }, container))
record = existing
else
record.id = json
end
Avoid deeply nested control flow statements. Open
if fields_count.positive?
while fields_count.positive?
cursor = content.index(field_sep, cursor) + 1
fields_count -= 1
end
Avoid deeply nested control flow statements. Open
if (property_value = json[name])
if property_model && property_value.is_a?(Hash) && property_value['_reference'] && ((property_value[:id].nil? && property_value[:_id].nil?) || options[:skip_refs_binding])
record.send("#{property_name}=", nil)
property_value = Cenit::Utility.deep_remove(property_value, '_reference')
unless (references = record.instance_variable_get(:@_references))
Avoid deeply nested control flow statements. Open
if (property_value = json[name])
association = record.send(property_name)
next unless updating || association.blank?
sub_values =
if updating_associations.include?(property_name)
Method extract_xml_value
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def extract_xml_value(xml_element, model, property, property_schema = nil)
if (property_schema ||= model.property_schema(property))
name = (property_schema['edi'] && property_schema['edi']['segment']) || property.to_s
xml_value =
if property_schema.key?('xml') && property_schema['xml']['attribute']
- 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
Avoid deeply nested control flow statements. Open
next unless kept
Avoid deeply nested control flow statements. Open
if (sub_record = do_parse_xml(data_type, property_model, sub_element, options, property_schema, nil, nil, property))
record.send("#{property}=", sub_record)
end
Avoid deeply nested control flow statements. Open
next if updating && ((property_name == '_id' || primary_fields.include?(name.to_sym)) && !record.send(property_name).nil?)
Consider simplifying this complex logical expression. Open
if property_model && property_value.is_a?(Hash) && property_value['_reference'] && ((property_value[:id].nil? && property_value[:_id].nil?) || options[:skip_refs_binding])
record.send("#{property_name}=", nil)
property_value = Cenit::Utility.deep_remove(property_value, '_reference')
unless (references = record.instance_variable_get(:@_references))
record.instance_variable_set(:@_references, references = {})
Consider simplifying this complex logical expression. Open
if (sub_model = json['_type']) &&
sub_model.is_a?(String) &&
(sub_model = sub_model.start_with?('self[') ? (json.send(:eval, sub_model) rescue nil) : sub_model) &&
(data_type = data_type.find_data_type(sub_model)) &&
(sub_model = data_type.records_model) &&
Consider simplifying this complex logical expression. Open
if (sub_model = json['_type']) &&
sub_model.is_a?(String) &&
(sub_model = sub_model.start_with?('self[') ? (json.send(:eval, sub_model) rescue nil) : sub_model) &&
(data_type = data_type.find_data_type(sub_model)) &&
(sub_model = data_type.records_model) &&
Method parse_json
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def parse_json(data_type, content, options = {}, record = nil, model = nil)
Method parse_json
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def parse_json(data_type, content, options = {}, record = nil, model = nil)
content = JSON.parse(content) unless content.is_a?(Hash)
process_options(options)
do_parse_json(data_type, model || record&.orm_model || data_type.records_model, content.with_indifferent_access, options, (record && record.orm_model.schema) || (model && model.schema) || data_type.merged_schema, nil, record)
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (sub_model = json['_type']) &&
sub_model.is_a?(String) &&
(sub_model = sub_model.start_with?('self[') ? (json.send(:eval, sub_model) rescue nil) : sub_model) &&
(data_type = data_type.find_data_type(sub_model)) &&
(sub_model = data_type.records_model) &&
- 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 37.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (sub_model = json['_type']) &&
sub_model.is_a?(String) &&
(sub_model = sub_model.start_with?('self[') ? (json.send(:eval, sub_model) rescue nil) : sub_model) &&
(data_type = data_type.find_data_type(sub_model)) &&
(sub_model = data_type.records_model) &&
- 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 37.
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