File sdam_flow.rb
has 437 lines of code (exceeds 250 allowed). Consider refactoring. Open
class Mongo::Cluster
# Handles SDAM flow for a server description changed event.
#
# Updates server descriptions, topology descriptions and publishes
# SDAM events.
Method server_description_changed
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def server_description_changed
@previous_server_descriptions = servers_list.map do |server|
[server.address.to_s, server.description]
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 server_description_changed
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
def server_description_changed
@previous_server_descriptions = servers_list.map do |server|
[server.address.to_s, server.description]
end
Method update_rs_from_primary
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_rs_from_primary
if topology.replica_set_name.nil?
@topology = Topology::ReplicaSetWithPrimary.new(
topology.options.merge(replica_set_name: updated_desc.replica_set_name),
topology.monitoring, self)
Method stale_primary?
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def stale_primary?
if updated_desc.max_wire_version >= 17
if updated_desc.election_id.nil? && !topology.max_election_id.nil?
return true
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
Class SdamFlow
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
class SdamFlow
extend Forwardable
def initialize(cluster, previous_desc, updated_desc, awaited: false)
@cluster = cluster
Method update_rs_from_primary
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def update_rs_from_primary
if topology.replica_set_name.nil?
@topology = Topology::ReplicaSetWithPrimary.new(
topology.options.merge(replica_set_name: updated_desc.replica_set_name),
topology.monitoring, self)
- 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_rs_with_primary_from_member
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_rs_with_primary_from_member
if topology.replica_set_name != updated_desc.replica_set_name
log_warn(
"Removing server #{updated_desc.address.to_s} because it has an " +
"incorrect replica set name (#{updated_desc.replica_set_name}); " +
Method update_rs_without_primary
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_rs_without_primary
if topology.replica_set_name.nil?
@topology = Topology::ReplicaSetNoPrimary.new(
topology.options.merge(replica_set_name: updated_desc.replica_set_name),
topology.monitoring, self)
Method stale_primary?
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def stale_primary?
if updated_desc.max_wire_version >= 17
if updated_desc.election_id.nil? && !topology.max_election_id.nil?
return true
end
Method commit_changes
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def commit_changes
# The application-visible sequence of events should be as follows:
#
# 1. Description change for the server which we are processing;
# 2. Topology change, if any;
- 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_rs_with_primary_from_member
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def update_rs_with_primary_from_member
if topology.replica_set_name != updated_desc.replica_set_name
log_warn(
"Removing server #{updated_desc.address.to_s} because it has an " +
"incorrect replica set name (#{updated_desc.replica_set_name}); " +
- 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_servers_not_in_desc
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def remove_servers_not_in_desc(updated_desc)
updated_desc_address_strs = %w(hosts passives arbiters).map do |m|
updated_desc.send(m)
end.flatten
servers_list.each do |server|
- 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 true
Method verify_invariants
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def verify_invariants
if Mongo::Lint.enabled?
if cluster.topology.single?
if cluster.servers_list.length > 1
raise Mongo::Error::LintError, "Trying to create a single topology with multiple servers: #{cluster.servers_list}"
- 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_server_descriptions
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def update_server_descriptions
servers_list.each do |server|
if server.address == updated_desc.address
# SDAM flow must be run when topology version in the new description
# is equal to the current topology version, per the example in
- 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"