mongodb/mongo-ruby-driver

View on GitHub
lib/mongo/cluster/sdam_flow.rb

Summary

Maintainability
D
2 days
Test Coverage

File sdam_flow.rb has 399 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.
Severity: Minor
Found in lib/mongo/cluster/sdam_flow.rb - About 5 hrs to fix

    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
    
    
    Severity: Minor
    Found in lib/mongo/cluster/sdam_flow.rb - About 3 hrs to fix

    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 80 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
    
    
    Severity: Major
    Found in lib/mongo/cluster/sdam_flow.rb - About 3 hrs to fix

      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
      Severity: Minor
      Found in lib/mongo/cluster/sdam_flow.rb - About 2 hrs to fix

        Method update_rs_from_primary has 49 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)
        Severity: Minor
        Found in lib/mongo/cluster/sdam_flow.rb - About 1 hr to fix

          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}); " +
          Severity: Minor
          Found in lib/mongo/cluster/sdam_flow.rb - About 1 hr to fix

            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)
            Severity: Minor
            Found in lib/mongo/cluster/sdam_flow.rb - About 1 hr to fix

              Method update_rs_from_primary has a Cognitive Complexity of 10 (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)
              Severity: Minor
              Found in lib/mongo/cluster/sdam_flow.rb - About 1 hr to fix

              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 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;
              Severity: Minor
              Found in lib/mongo/cluster/sdam_flow.rb - About 45 mins to fix

              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}); " +
              Severity: Minor
              Found in lib/mongo/cluster/sdam_flow.rb - About 35 mins to fix

              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|
              Severity: Minor
              Found in lib/mongo/cluster/sdam_flow.rb - About 35 mins to fix

              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 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}"
              Severity: Minor
              Found in lib/mongo/cluster/sdam_flow.rb - About 25 mins to fix

              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 stale_primary? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def stale_primary?
                    if updated_desc.election_id && updated_desc.set_version
                      if topology.max_set_version && topology.max_election_id &&
                          (updated_desc.set_version < topology.max_set_version ||
                              (updated_desc.set_version == topology.max_set_version &&
              Severity: Minor
              Found in lib/mongo/cluster/sdam_flow.rb - About 25 mins to fix

              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
              Severity: Minor
              Found in lib/mongo/cluster/sdam_flow.rb - About 25 mins to fix

              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

              There are no issues that match your filters.

              Category
              Status