Method save_references
has a Cognitive Complexity of 103 (exceeds 5 allowed). Consider refactoring. Open
def save_references(record, options, saved, visited = Set.new)
# TODO: Propagate error to parent relation...
return true if visited.include?(record)
visited << record
if record.is_a?(Setup::Collection)
- 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 bind_references
has a Cognitive Complexity of 103 (exceeds 5 allowed). Consider refactoring. Open
def bind_references(record, options = {})
options ||= {}
references = {}
for_each_node_starting_at(record, options) do |obj|
::Setup::Optimizer.instance.regist_data_types(obj)
- 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 utility.rb
has 461 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'objspace'
module Cenit
class Utility
Method for_each_node_starting_at
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
def for_each_node_starting_at(record, options = {}, &block)
stack = options[:stack]
unless (visited = options[:visited])
visited = options[:visited] = Set.new
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 eql_content?
has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring. Open
def eql_content?(a, b, key = nil, &block)
case a
when Hash
if b.is_a?(Hash)
if a.size < b.size
- 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 save
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
def save(record, options = {})
saved = options[:saved_collector] || Set.new
if bind_references(record, options.delete(:bind_references))
success =
if record.try(:save_self_before_refs)
- 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 find_record
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
def find_record(conditions, *scopes)
scopes.each do |original_scope|
scope = original_scope
match_conditions = {}
begin
- 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 bind_references
has 88 lines of code (exceeds 25 allowed). Consider refactoring. Open
def bind_references(record, options = {})
options ||= {}
references = {}
for_each_node_starting_at(record, options) do |obj|
::Setup::Optimizer.instance.regist_data_types(obj)
Method json_object?
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def json_object?(obj, options = {})
case obj
when Hash
if options[:recursive]
obj.keys.each { |k| return false unless k.is_a?(String) }
- 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 match?
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def match?(obj, criteria)
criteria.each do |property_name, value|
property_value =
case obj
when 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 json_value_of
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def json_value_of(value)
return value unless value.is_a?(String)
value = value.strip
if value.blank?
nil
- 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 save_references
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
def save_references(record, options, saved, visited = Set.new)
# TODO: Propagate error to parent relation...
return true if visited.include?(record)
visited << record
if record.is_a?(Setup::Collection)
Method find_record
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
def find_record(conditions, *scopes)
scopes.each do |original_scope|
scope = original_scope
match_conditions = {}
begin
Method save
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def save(record, options = {})
saved = options[:saved_collector] || Set.new
if bind_references(record, options.delete(:bind_references))
success =
if record.try(:save_self_before_refs)
Method eql_content?
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def eql_content?(a, b, key = nil, &block)
case a
when Hash
if b.is_a?(Hash)
if a.size < b.size
Method associated_ids
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def associated_ids(association, criteria)
associations =
begin
association.klass.get_associations
rescue
- 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 json_value_of
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def json_value_of(value)
return value unless value.is_a?(String)
value = value.strip
if value.blank?
nil
Avoid deeply nested control flow statements. Open
return false unless save_references(value, options, saved, visited)
Avoid deeply nested control flow statements. Open
unless saved.include?(value)
new_record = value.new_record?
if value.changed?
if value.save(options)
if new_record || value.instance_variable_get(:@dynamically_created)
Method array_hash_merge
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def array_hash_merge(val1, val2, options = {}, &block)
if val1.is_a?(Array) && val2.is_a?(Array)
if options[:array_uniq]
(val2 + val1).uniq(&block)
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 (obj = (obj.reload rescue nil))
Method deep_remove
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def deep_remove(hash, key)
if hash.is_a?(Hash)
hash.inject({}) do |h, (k, v)|
h[k] = deep_remove(v, key) unless k == key
h
- 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 too many return
statements within this method. Open
return a.eql?(b) || (block && block.call(*(block.arity == 3 ? [a, b, key] : [a, b])))
Method stringfy
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def stringfy(obj)
if obj.is_a?(Hash)
hash = {}
obj.each { |key, value| hash[key.to_s] = stringfy(value) }
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if value.save(options)
if new_record || value.instance_variable_get(:@dynamically_created)
value.instance_variable_set(:@dynamically_created, true)
options[:create_collector] << value if options[:create_collector]
else
- 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 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
- 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 value.save(options)
if new_record || value.instance_variable_get(:@dynamically_created)
value.instance_variable_set(:@dynamically_created, true)
options[:create_collector] << value if options[:create_collector]
else
- 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 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
- 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