mongodb/mongo-ruby-driver

View on GitHub
lib/mongo/server_selector/base.rb

Summary

Maintainability
D
3 days
Test Coverage

Method select_server has a Cognitive Complexity of 74 (exceeds 5 allowed). Consider refactoring.
Open

      def select_server(cluster, ping = nil, session = nil, write_aggregation: false)
        if cluster.topology.is_a?(Cluster::Topology::LoadBalanced)
          return cluster.servers.first
        end

Severity: Minor
Found in lib/mongo/server_selector/base.rb - About 1 day 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

File base.rb has 320 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Mongo

  module ServerSelector

    class Base
Severity: Minor
Found in lib/mongo/server_selector/base.rb - About 3 hrs to fix

    Method select_server has 87 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def select_server(cluster, ping = nil, session = nil, write_aggregation: false)
            if cluster.topology.is_a?(Cluster::Topology::LoadBalanced)
              return cluster.servers.first
            end
    
    
    Severity: Major
    Found in lib/mongo/server_selector/base.rb - About 3 hrs to fix

      Class Base has 22 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class Base
      
            # Initialize the server selector.
            #
            # @example Initialize the selector.
      Severity: Minor
      Found in lib/mongo/server_selector/base.rb - About 2 hrs to fix

        Method try_select_server has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def try_select_server(cluster, write_aggregation: false)
                servers = if write_aggregation && cluster.replica_set?
                  # 1. Check if ALL servers in cluster support secondary writes.
                  is_write_supported = cluster.servers.reduce(true) do |res, server|
                    res && server.features.merge_out_on_secondary_enabled?
        Severity: Minor
        Found in lib/mongo/server_selector/base.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 validate! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

              def validate!
                if !@tag_sets.all? { |set| set.empty? } && !tags_allowed?
                  raise Error::InvalidServerPreference.new(Error::InvalidServerPreference::NO_TAG_SUPPORT)
                elsif @max_staleness && !max_staleness_allowed?
                  raise Error::InvalidServerPreference.new(Error::InvalidServerPreference::NO_MAX_STALENESS_SUPPORT)
        Severity: Minor
        Found in lib/mongo/server_selector/base.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 server_selection_diagnostic_message has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def server_selection_diagnostic_message(cluster)
                msg = ''
                dead_monitors = []
                cluster.servers_list.each do |server|
                  thread = server.monitor.instance_variable_get('@thread')
        Severity: Minor
        Found in lib/mongo/server_selector/base.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