mongodb/mongo-ruby-driver

View on GitHub

Showing 196 of 247 total issues

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

      def check_in(connection)
        @lock.synchronize do
          unless connection.connection_pool == self
            raise ArgumentError, "Trying to check in a connection which was not checked out by this pool: #{connection} checked out from pool #{connection.connection_pool} (for #{self})"
          end
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 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 execute_operation has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def execute_operation(name, values, server, operation_id, result_combiner, session, txn_num = nil)
      raise Error::UnsupportedCollation.new if op_combiner.has_collation && !server.features.collation_enabled?
      raise Error::UnsupportedArrayFilters.new if op_combiner.has_array_filters && !server.features.array_filters_enabled?
      unpin_maybe(session) do
        if values.size > server.max_write_batch_size
Severity: Minor
Found in lib/mongo/bulk_write.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 write_with_retry has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def write_with_retry(session, write_concern, ending_transaction = false, &block)
      if ending_transaction && !session
        raise ArgumentError, 'Cannot end a transaction without a session'
      end

Severity: Minor
Found in lib/mongo/retryable.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 abort_transaction has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def abort_transaction
            check_if_ended!
            check_if_no_transaction!
      
            if within_states?(TRANSACTION_COMMITTED_STATE)
      Severity: Minor
      Found in lib/mongo/session.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)
                unless (data.length > 0 || length == 0)
                  raise IOError, "Expected to read > 0 bytes but read 0 bytes"
        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 find_one_and_update has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

                def find_one_and_update(document, opts = {})
                  cmd = { :findAndModify => collection.name, :query => filter }
                  cmd[:update] = document
                  cmd[:fields] = projection if projection
                  cmd[:sort] = sort if sort
        Severity: Minor
        Found in lib/mongo/collection/view/writable.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_with_retry has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def read_with_retry(session = nil, server_selector = nil, &block)
              if session.nil? && server_selector.nil?
                # Older versions of Mongoid call read_with_retry without arguments.
                # This is already not correct in a MongoDB 3.6+ environment with
                # sessions. For compatibility we emulate the legacy driver behavior
        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 parallel_scan has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def parallel_scan(cursor_count, options = {})
                  if options[:session]
                    session = client.send(:get_session, @options)
                  else
                    session = nil
        Severity: Minor
        Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

          Method execute has 31 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
          
          
          Severity: Minor
          Found in lib/mongo/bulk_write.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 ismaster has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def ismaster
                      @mutex.synchronize do
                        if monitoring.monitoring?
                          monitoring.started(
                            Monitoring::SERVER_HEARTBEAT,
              Severity: Minor
              Found in lib/mongo/server/monitor.rb - About 1 hr to fix

                Method initialize has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def initialize(user, used_mechanism: nil, message: nil,
                        server: nil
                      )
                        configured_bits = []
                        used_bits = [
                Severity: Minor
                Found in lib/mongo/auth.rb - About 1 hr to fix

                  Method validate_authentication_options! has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def validate_authentication_options!
                        auth_mech = options[:auth_mech]
                        user = options[:user]
                        password = options[:password]
                        auth_source = options[:auth_source]
                  Severity: Minor
                  Found in lib/mongo/client.rb - About 1 hr to fix

                    Method create_context has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                          def create_context(options)
                            OpenSSL::SSL::SSLContext.new.tap do |context|
                              if OpenSSL::SSL.const_defined?(:OP_NO_RENEGOTIATION)
                                context.options = context.options | OpenSSL::SSL::OP_NO_RENEGOTIATION
                              end
                    Severity: Minor
                    Found in lib/mongo/socket/ssl.rb - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language