mongodb/mongo-ruby-driver

View on GitHub

Showing 423 of 480 total issues

Method read_from_socket has 70 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def read_from_socket(length, socket_timeout: nil, csot: false)
      # Just in case
      if length == 0
        return ''.force_encoding('BINARY')
      end
Severity: Major
Found in lib/mongo/socket.rb - About 2 hrs to fix

    Method run_sdam_flow has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def run_sdam_flow(previous_desc, updated_desc, options = {})
          if load_balanced?
            if updated_desc.config.empty?
              unless options[:keep_connection_pool]
                servers_list.each do |server|
    Severity: Minor
    Found in lib/mongo/cluster.rb - About 2 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 initial has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

          def initial(cluster, monitoring, options)
            connect = options[:connect]&.to_sym
            cls = if options[:direct_connection]
              if connect && connect != :direct
                raise ArgumentError, "Conflicting topology options: direct_connection=true and connect=#{connect}"
    Severity: Minor
    Found in lib/mongo/cluster/topology.rb - About 2 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 legacy_read_with_retry has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

          def legacy_read_with_retry(session, server_selector, context = nil, &block)
            context&.check_timeout!
            attempt = attempt ? attempt + 1 : 1
            yield select_server(cluster, server_selector, session)
          rescue *legacy_retryable_exceptions, Error::OperationFailure::Family => e
    Severity: Minor
    Found in lib/mongo/retryable/read_worker.rb - About 2 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 initialize has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def initialize(options)
            Crypt.validate_ffi!
            # Note that this call may eventually, via other method invocations,
            # create additional clients which have to be cleaned up.
            @options = set_default_options(options).freeze
    Severity: Major
    Found in lib/mongo/crypt/auto_encrypter.rb - About 2 hrs to fix

      Class Base has 24 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

        Class MapReduce has 24 methods (exceeds 20 allowed). Consider refactoring.
        Open

              class MapReduce
                extend Forwardable
                include Enumerable
                include Immutable
                include Loggable
        Severity: Minor
        Found in lib/mongo/collection/view/map_reduce.rb - About 2 hrs to fix

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

            Method initialize has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
            Open

                    def initialize(options, monitoring, cluster)
                      options = validate_options(options, cluster)
            
                      @options = options
                      @monitoring = monitoring
            Severity: Minor
            Found in lib/mongo/cluster/topology/base.rb - About 2 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 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
            Severity: Minor
            Found in lib/mongo/cluster/sdam_flow.rb - About 2 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

            File collection.rb has 271 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            require 'mongo/bulk_write'
            require 'mongo/collection/view'
            require 'mongo/collection/helpers'
            require 'mongo/collection/queryable_encryption'
            
            
            Severity: Minor
            Found in lib/mongo/collection.rb - About 2 hrs to fix

              Class FSBucket has 23 methods (exceeds 20 allowed). Consider refactoring.
              Open

                  class FSBucket
                    extend Forwardable
              
                    # The default root prefix.
                    #
              Severity: Minor
              Found in lib/mongo/grid/fs_bucket.rb - About 2 hrs to fix

                Class Message has 23 methods (exceeds 20 allowed). Consider refactoring.
                Open

                    class Message
                      include Id
                      include Serializers
                
                      # The batch size constant.
                Severity: Minor
                Found in lib/mongo/protocol/message.rb - About 2 hrs to fix

                  Method validate_timeout_mode! has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def validate_timeout_mode!(options, forbid: [])
                        forbid.each do |key|
                          raise ArgumentError, "#{key} is not allowed here" if options.key?(key)
                        end
                  
                  
                  Severity: Minor
                  Found in lib/mongo/cursor_host.rb - About 2 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 validate_new_options! has 59 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def validate_new_options!(opts)
                        return Options::Redacted.new unless opts
                        if opts[:read_concern]
                          # Raise an error for non user-settable options
                          if opts[:read_concern][:after_cluster_time]
                  Severity: Major
                  Found in lib/mongo/client.rb - About 2 hrs to fix

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

                          class ChangeStream
                            include Aggregation::Behavior
                            include Retryable
                    
                            # @return [ String ] The fullDocument option default value.
                    Severity: Minor
                    Found in lib/mongo/collection/view/change_stream.rb - About 2 hrs to fix

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

                        class BulkWrite
                          extend Forwardable
                          include Operation::ResponseHandling
                      
                          # @return [ Mongo::Collection ] collection The collection.
                      Severity: Minor
                      Found in lib/mongo/bulk_write.rb - About 2 hrs to fix

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

                            class SSL < Socket
                              include OpenSSL
                        
                              # Initializes a new TLS socket.
                              #
                        Severity: Minor
                        Found in lib/mongo/socket/ssl.rb - About 2 hrs to fix

                          Method ruby_to_string has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                          Open

                                def ruby_to_string(opts)
                                  rv = {}
                                  URI_OPTION_MAP.each do |uri_key, spec|
                                    if spec[:group]
                                      v = opts[spec[:group]]
                          Severity: Minor
                          Found in lib/mongo/uri/options_mapper.rb - About 2 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 ruby_to_smc has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                          Open

                                def ruby_to_smc(opts)
                                  rv = {}
                                  URI_OPTION_MAP.each do |uri_key, spec|
                                    if spec[:group]
                                      v = opts[spec[:group]]
                          Severity: Minor
                          Found in lib/mongo/uri/options_mapper.rb - About 2 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

                          Severity
                          Category
                          Status
                          Source
                          Language