Showing 236 of 236 total issues
Method get_relation
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def get_relation(name, association, object, reload = false)
field_name = database_field_name(name)
# As per the comments under MONGOID-5034, I've decided to only raise on
# embedded associations for a missing attribute. Rails does not raise
- 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 batch_replace
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def batch_replace(docs)
if docs.blank?
if _assigning? && !empty?
_base.delayed_atomic_sets.delete(path)
clear_atomic_path_cache
- 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 mongoize
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def mongoize(object)
return if object.blank?
if Mongoid.map_big_decimal_to_decimal128
if object.is_a?(BSON::Decimal128)
object
- 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 all
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def all(*criteria)
if criteria.empty?
return clone.tap do |query|
query.reset_strategies!
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 demongoize
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def demongoize(object)
return if object.nil?
if object.is_a?(Hash)
hash = object.slice('min', 'max', 'exclude_end', :min, :max, :exclude_end)
unless hash.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 merge!
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def merge!(other)
other.each_pair do |key, value|
if value.is_a?(Hash) && self[key.to_s].is_a?(Hash)
value = self[key.to_s].merge(value) do |_key, old_val, new_val|
case _key.to_s
- 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 update_inverse_keys
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def update_inverse_keys(association)
if previous_changes.has_key?(association.foreign_key)
old, new = previous_changes[association.foreign_key]
adds, subs = new - (old || []), (old || []) - 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
Method matches?
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def matches?(exists, value, condition)
case value
when BSON::Binary
value = value.data.split('').map { |n| '%02x' % n.ord }.join.to_i(16)
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 evolve_range
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def evolve_range(key, serializer, value)
v = value.__evolve_range__(serializer: serializer)
assocs = []
Fields.traverse_association_tree(key, serializers, associations, aliased_associations) do |meth, obj, is_field|
assocs.push([meth, obj, is_field])
- 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 metadata_for
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def metadata_for(model)
metadata = {}.tap do |metadata|
if (key_id = key_id_for(model.encrypt_metadata[:key_id], model.encrypt_metadata[:key_name_field]))
metadata['keyId'] = key_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 batch_remove
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def batch_remove(docs, method = :delete)
# If the _id is nil, we cannot use $pull and delete by searching for
# the id. Therefore we have to use pullAll with the documents'
# attributes.
removals = pre_process_batch_remove(docs, method)
Method matches?
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def matches?(exists, value, condition)
case value
when BSON::Binary
value = value.data.split('').map { |n| '%02x' % n.ord }.join.to_i(16)
end
Method set
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set(setters)
prepare_atomic_operation do |ops|
process_atomic_operations(setters) do |field, value|
field_seq = field.to_s.split('.')
Method _mongoid_filter_selected_fields
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _mongoid_filter_selected_fields(assoc_key)
return nil unless __selected_fields
# If the list of fields was specified using #without instead of #only
# and the provided list does not include the association, any of its
Method not
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def not(*criteria)
if criteria.empty?
dup.tap { |query| query.negating = true }
else
criteria.compact.inject(self.clone) do |c, new_s|
Method extract_value
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def extract_value(attrs, field_name)
i = 1
num_meths = field_name.count('.') + 1
curr = attrs.dup
Method add_logical_operator_expression
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def add_logical_operator_expression(operator, op_expr)
unless operator.is_a?(String)
raise ArgumentError, "Operator must be a string: #{operator}"
end
Similar blocks of code found in 2 locations. Consider refactoring. Open
Benchmark.ips do |bm|
bm.config(:time => 5, :warmup => 2, :suite => suite)
bm.report("#each [ normal ]") do
Person.all.each do |person|
- 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 49.
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
Benchmark.ips do |bm|
bm.config(:time => 5, :warmup => 2, :suite => suite)
bm.report("#each [ normal ]") do
Person.all.each do |person|
- 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 49.
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
Method attribute_or_path_allowed?
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def attribute_or_path_allowed?(name)
# Special handling for _id.
if name == '_id'
result = unless id_projection_value.nil?
value_inclusionary?(id_projection_value)