mongodb/mongo-ruby-driver

View on GitHub

Showing 161 of 214 total issues

Method check_out has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def check_out
        raise_if_closed!

        publish_cmap_event(
          Monitoring::Event::Cmap::ConnectionCheckOutStarted.new(@server.address)
Severity: Minor
Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

    Method initialize has 44 lines of code (exceeds 25 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

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

          def validate_options!(opts = Options::Redacted.new)
            return Options::Redacted.new unless opts
            opts.each.inject(Options::Redacted.new) do |_options, (k, v)|
              key = k.to_sym
              if VALID_OPTIONS.include?(key)
      Severity: Minor
      Found in lib/mongo/client.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 add_txn_opts! has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def add_txn_opts!(command, read)
            command.tap do |c|
              # The read preference should be added for all read operations.
              if read && txn_read_pref = txn_read_preference
                Mongo::Lint.validate_underscore_read_preference(txn_read_pref)
      Severity: Minor
      Found in lib/mongo/session.rb - About 1 hr to fix

        Method close_idle_sockets has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

              def close_idle_sockets
                return if closed?
                return unless max_idle_time
        
                @lock.synchronize do
        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 legacy_read_with_retry has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def legacy_read_with_retry(session, server_selector)
              attempt = 0
              server = select_server(cluster, server_selector)
              begin
                attempt += 1
        Severity: Minor
        Found in lib/mongo/retryable.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 post_handshake has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

              def post_handshake(response, average_rtt)
                if response["ok"] == 1
                  # Auth mechanism is entirely dependent on the contents of
                  # ismaster response *for this connection*.
                  # Ismaster received by the monitoring connection should advertise
        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 initialize has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                def initialize(replies, ids)
                  @replies = [*replies] if replies
                  if replies && replies.first && (doc = replies.first.documents.first)
                    if errors = doc['writeErrors']
                      # some documents were potentially inserted
        Severity: Minor
        Found in lib/mongo/operation/insert/bulk_result.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 kill_cursors has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def kill_cursors
                to_kill_copy = {}
                active_cursors_copy = []
        
                @mutex.synchronize do
        Severity: Minor
        Found in lib/mongo/cluster/reapers/cursor_reaper.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 command has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def command(server)
                sel = selector(server).dup
                add_write_concern!(sel)
                sel[Protocol::Msg::DATABASE_IDENTIFIER] = db_name
                sel['$readPreference'] = read.to_doc if read
        Severity: Minor
        Found in lib/mongo/operation/shared/sessions_supported.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 read_from_socket has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def read_from_socket(length)
              # Just in case
              if length == 0
                return ''.force_encoding('BINARY')
              end
        Severity: Minor
        Found in lib/mongo/socket.rb - About 1 hr to fix

          Method initialize has 33 lines of code (exceeds 25 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 1 hr to fix

            Method command has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def command(server)
                    sel = selector(server).dup
                    add_write_concern!(sel)
                    sel[Protocol::Msg::DATABASE_IDENTIFIER] = db_name
                    sel['$readPreference'] = read.to_doc if read
            Severity: Minor
            Found in lib/mongo/operation/shared/sessions_supported.rb - About 1 hr to fix

              Method read has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  def read(length)
                    handle_errors do
                      data = read_from_socket(length)
                      raise IOError unless (data.length > 0 || length == 0)
                      while data.length < length
              Severity: Minor
              Found in lib/mongo/socket.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 suppress_read_write_concern! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  def suppress_read_write_concern!(command)
                    command.tap do |c|
                      next unless in_transaction?
              
                      c.delete(:readConcern) unless starting_transaction?
              Severity: Minor
              Found in lib/mongo/session.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 convert_limit_and_batch_size has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                        def convert_limit_and_batch_size(command)
                          if command[:limit] && command[:limit] < 0 &&
                              command[:batchSize] && command[:batchSize] < 0
              
                            command[:limit] = command[:limit].abs
              Severity: Minor
              Found in lib/mongo/collection/view/builder/find_command.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_read! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  def validate_read!(option, opts)
                    if option == :read && opts.has_key?(:read)
                      read = opts[:read]
                      # We could check if read is a Hash, but this would fail
                      # for custom classes implementing key access ([]).
              Severity: Minor
              Found in lib/mongo/client.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 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def initialize(addresses_or_uri, options = nil)
                    if options
                      options = options.dup
                    else
                      options = {}
              Severity: Minor
              Found in lib/mongo/client.rb - About 1 hr to fix
                Severity
                Category
                Status
                Source
                Language