Showing 236 of 236 total issues
Method matches?
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
module_function def matches?(exists, value, condition, original_operator)
case condition
when Range
# Since $ne invokes $eq, the exception message needs to handle
# both operators.
Method and
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def and(*criteria)
_mongoid_flatten_arrays(criteria).inject(self.clone) do |c, new_s|
if new_s.is_a?(Selectable)
new_s = new_s.selector
end
Method bind_one
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def bind_one(doc)
binding do
inverse_keys = try_method(doc, _association.inverse_foreign_key) unless doc.frozen?
if inverse_keys
record_id = inverse_record_id(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 attribute_or_path_allowed?
has a Cognitive Complexity of 9 (exceeds 5 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)
- 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 database_field_name
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def database_field_name(name, relations, aliased_fields, aliased_associations)
return nil unless name.present?
key = name.to_s
segment, remaining = key.split('.', 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
Method _mongoid_add_top_level_operation
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private def _mongoid_add_top_level_operation(operator, criteria)
# Flatten the criteria. The idea is that predicates in MongoDB
# are always hashes and are never arrays. This method additionally
# allows Criteria instances as predicates.
# The flattening is existing Mongoid behavior but we could possibly
- 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 create_client
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def create_client(configuration)
raise Errors::NoClientsConfig.new unless configuration
config = configuration.dup
uri = config.delete(:uri)
database = config.delete(:database) || Mongo::URI.get(uri).database
- 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 validate_each
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def validate_each(document, attribute, value)
field = document.fields[document.database_field_name(attribute)]
if field.try(:localized?) && !value.blank?
value.each_pair do |_locale, _value|
document.errors.add(
- 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 __multi__
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def __multi__(criteria, operator)
clone.tap do |query|
sel = query.selector
criteria.flatten.each do |expr|
next unless expr
- 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 shard_key
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def shard_key(*args)
unless args.first.is_a?(Hash)
# Shorthand syntax
if args.last.is_a?(Hash)
raise ArgumentError, 'Shorthand shard_key syntax does not permit options'
- 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 upsert
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def upsert(options = {})
prepare_upsert(options) do
if options[:replace]
if options[:set_on_insert]
raise ArgumentError, "cannot specify :set_on_insert with `replace: true`"
- 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 pre_process_batch_remove
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def pre_process_batch_remove(docs, method)
docs.map do |doc|
self.path = doc.atomic_path unless path
execute_callback :before_remove, doc
unless _assigning?
- 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 resolve_name
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def resolve_name(mod, name)
cls = exc = nil
parts = name.to_s.split('::')
if parts.first == ''
parts.shift
- 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 add_to_set
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def add_to_set(adds)
prepare_atomic_operation do |ops|
process_atomic_operations(adds) do |field, value|
existing = send(field) || attributes[field]
if existing.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 evolve_multi
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def evolve_multi(specs)
unless specs.is_a?(Array)
raise ArgumentError, "specs is not an array: #{specs.inspect}"
end
specs.map do |spec|
- 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 validate_spec
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def validate_spec(klass, spec, options)
raise Errors::InvalidIndex.new(klass, spec, options) if !spec.is_a?(::Hash)
spec.each_pair do |name, value|
next if name == :options
unless VALID_TYPES.include?(value)
- 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 create_document
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def create_document(method, attrs = nil, &block)
attrs = (create_attrs || {}).merge(attrs || {})
attributes = selector.reduce(attrs) do |hash, (key, value)|
unless invalid_key?(hash, key) || invalid_embedded_doc?(value)
hash[key] = value
- 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 add_field_expression
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def add_field_expression(field, value)
unless field.is_a?(String)
raise ArgumentError, "Field must be a string: #{field}"
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 remove_indexes
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def remove_indexes
indexed_database_names.each do |database|
with(database: database) do |klass|
begin
klass.collection.indexes(session: _session).each do |spec|
- 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
def determine_inverses(other)
matches = relation_class.relations.values.select do |rel|
relation_complements.include?(rel.class) &&
# https://jira.mongodb.org/browse/MONGOID-4882
rel.relation_class_name.sub(/\A::/, '') == inverse_class_name
- 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 43.
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