lib/mongo/collection.rb
Class Collection
has 37 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class Collection
extend Forwardable
include Retryable
include QueryableEncryption
include Helpers
File collection.rb
has 271 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
require 'mongo/bulk_write'
require 'mongo/collection/view'
require 'mongo/collection/helpers'
require 'mongo/collection/queryable_encryption'
Method create
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def create(opts = {})
# Passing read options to create command causes it to break.
# Filter the read options out. Session is also excluded here as it gets
# used by the call to with_session and should not be part of the
# operation. If it gets passed to the operation it would fail BSON
Method insert_one
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def insert_one(document, opts = {})
QueryCache.clear_namespace(namespace)
client.with_session(opts) do |session|
write_concern = if opts[:write_concern]
Method create
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def create(opts = {})
# Passing read options to create command causes it to break.
# Filter the read options out. Session is also excluded here as it gets
# used by the call to with_session and should not be part of the
# operation. If it gets passed to the operation it would fail BSON
- 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 with
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def with(new_options)
new_options.keys.each do |k|
raise Error::UnchangeableCollectionOption.new(k) unless CHANGEABLE_OPTIONS.include?(k)
end
options = @options.dup
- 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"