mongodb/mongo-ruby-driver

View on GitHub

Showing 393 of 447 total issues

Method check has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def check
        if @connection && @connection.pid != Process.pid
          log_warn("Detected PID change - Mongo client should have been reconnected (old pid #{@connection.pid}, new pid #{Process.pid}")
          @connection.disconnect!
          @connection = nil
Severity: Minor
Found in lib/mongo/server/monitor.rb - About 1 hr to fix

    Method ec2_metadata_credentials has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def ec2_metadata_credentials
              http = Net::HTTP.new('169.254.169.254')
              req = Net::HTTP::Put.new('/latest/api/token',
                # The TTL is required in order to obtain the metadata token.
                {'x-aws-ec2-metadata-token-ttl-seconds' => '30'})
    Severity: Minor
    Found in lib/mongo/auth/aws/credentials_retriever.rb - About 1 hr to fix

      Method estimated_document_count has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def estimated_document_count(opts = {})
                unless view.filter.empty?
                  raise ArgumentError, "Cannot call estimated_document_count when querying with a filter"
                end
      
      
      Severity: Minor
      Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

        Method parse! has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def parse!(remaining)
              hosts_and_db, options = remaining.split('?', 2)
              if options && options.index('?')
                raise_invalid_error!("Options contain an unescaped question mark (?), or the database name contains a question mark and was not escaped")
              end
        Severity: Minor
        Found in lib/mongo/uri.rb - About 1 hr to fix

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

              def close
                @state_change_lock.synchronize do
                  unless connecting? || connected?
                    return nil
                  end
          Severity: Minor
          Found in lib/mongo/cluster.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 do_check_in has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def do_check_in(connection)
                  # When a connection is interrupted it is checked back into the pool
                  # and closed. The operation that was using the connection before it was
                  # interrupted will attempt to check it back into the pool, and we
                  # should ignore it since its already been closed and removed from the pool.
          Severity: Minor
          Found in lib/mongo/server/connection_pool.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 start_stop_srv_monitor has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def start_stop_srv_monitor
                # SRV URI is either always given or not for a given cluster, if one
                # wasn't given we shouldn't ever have an SRV monitor to manage.
                return unless options[:srv_uri]
          
          
          Severity: Minor
          Found in lib/mongo/cluster.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 initialize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def initialize(server, options = {})
                  unless server.is_a?(Server)
                    raise ArgumentError, 'First argument must be a Server instance'
                  end
                  options = options.dup
          Severity: Minor
          Found in lib/mongo/server/connection_pool.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 connect! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def connect!
                  raise_if_closed!
          
                  unless @socket
                    @socket = create_socket
          Severity: Minor
          Found in lib/mongo/server/connection.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 smc_to_ruby has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def smc_to_ruby(opts)
                  uri_options = {}
          
                  opts.each do |key, value|
                    strategy = URI_OPTION_MAP[key.downcase]
          Severity: Minor
          Found in lib/mongo/uri/options_mapper.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 try_next has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def try_next
                if @documents.nil?
                  # Since published versions of Mongoid have a copy of old driver cursor
                  # code, our dup call in #process isn't invoked when Mongoid query
                  # cache is active. Work around that by also calling dup here on
          Severity: Minor
          Found in lib/mongo/cursor.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 try_select_server has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def try_select_server(cluster, write_aggregation: false, deprioritized: [])
                  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_length! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                    def validate_length!(index, num_chunks, chunk, length_read)
                      if num_chunks > 0 && chunk.data.data.size > 0
                        raise Error::ExtraFileChunk.new unless index < num_chunks
                        if index == num_chunks - 1
                          unless chunk.data.data.size + length_read == file_info.length
          Severity: Minor
          Found in lib/mongo/grid/stream/read.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 build_message has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def build_message
                  errors = @result['writeErrors']
                  return nil unless errors
          
                  fragment = ""
          Severity: Minor
          Found in lib/mongo/error/bulk_write_error.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 parallel_scan has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def parallel_scan(cursor_count, options = {})
                    if options[:session]
                      # The session would be overwritten by the one in +options+ later.
                      session = client.send(:get_session, @options)
                    else
          Severity: Minor
          Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

            Method find_one_and_delete has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def find_one_and_delete(opts = {})
                      with_session(opts) do |session|
                        write_concern = if opts[:write_concern]
                          WriteConcern.get(opts[:write_concern])
                        else
            Severity: Minor
            Found in lib/mongo/collection/view/writable.rb - About 1 hr to fix

              Method execute has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def execute
                    operation_id = Monitoring.next_operation_id
                    result_combiner = ResultCombiner.new
                    operations = op_combiner.combine
                    validate_requests!
              Severity: Minor
              Found in lib/mongo/bulk_write.rb - About 1 hr to fix

                Method deserialize has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def self.deserialize(io,
                        max_message_size = MAX_MESSAGE_SIZE,
                        expected_response_to = nil,
                        options = {}
                      )
                Severity: Minor
                Found in lib/mongo/protocol/message.rb - About 1 hr to fix

                  Method do_check_in has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        def do_check_in(connection)
                          # When a connection is interrupted it is checked back into the pool
                          # and closed. The operation that was using the connection before it was
                          # interrupted will attempt to check it back into the pool, and we
                          # should ignore it since its already been closed and removed from the pool.
                  Severity: Minor
                  Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

                    Method server_version_gte? has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                          def server_version_gte?(version)
                            required_wv = case version
                              when '7.0'
                                21
                              when '6.0'
                    Severity: Minor
                    Found in lib/mongo/server/description.rb - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language