Method build_hash_with_flat
has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring. Open
def build_hash_with_flat(hash, key_string, value)
current_object = hash
splitted = key_string.split(/\.|\[/, 2)
current_key = splitted[0] # first is always a hash
key_string = splitted[1]
- 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 build_hash_with_flat
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
def build_hash_with_flat(hash, key_string, value)
current_object = hash
splitted = key_string.split(/\.|\[/, 2)
current_key = splitted[0] # first is always a hash
key_string = splitted[1]
Method gsub_keys!
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def gsub_keys!(h, from_1, from_2, to_1, to_2)
if h.is_a?(Hash)
h.keys.each do |key|
if key.to_s.include?(from_1) || key.to_s.include?(from_2)
new_key = key.to_s.gsub(from_1, to_1).gsub(from_2, to_2)
- 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 no_key?(current_object, current_key)
current_object[current_key] = {}
end
Avoid deeply nested control flow statements. Open
if key_string.count(']') > key_string.count('[')
key_string = '[' + key_string
end
Method remove_reserved_keys!
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def remove_reserved_keys!(h)
if h.is_a?(Hash)
h.keys.each do |key|
if [TrueClass, FalseClass].include?(key.class)
# # This warning is commented because Rails admin uses bad keys: https://github.com/sferik/rails_admin/blob/master/config/locales/rails_admin.en.yml
- 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
current_object[array_pos] = value if current_object.is_a?(Array)
Avoid deeply nested control flow statements. Open
current_object[new_key] = value if current_object.is_a?(Hash)
Avoid deeply nested control flow statements. Open
if no_key?(current_object, current_key)
current_object[current_key] = {}
end
Method gsub_keys!
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def gsub_keys!(h, from_1, from_2, to_1, to_2)