mongodb/mongo-ruby-driver

View on GitHub

Showing 393 of 447 total issues

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

      def initialize(address, config = {}, average_round_trip_time: nil,
        load_balancer: false, force_load_balancer: false
      )
        @address = address
        @config = config
Severity: Minor
Found in lib/mongo/server/description.rb - About 1 hr to fix

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

      Method add_read_preference has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def add_read_preference(sel, connection)
              Lint.assert_type(connection, Server::Connection)
      
              # https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#topology-type-single
              read_doc = if connection.description.standalone?
      Severity: Minor
      Found in lib/mongo/operation/shared/sessions_supported.rb - About 1 hr to fix

        Method update_rs_without_primary has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def update_rs_without_primary
              if topology.replica_set_name.nil?
                @topology = Topology::ReplicaSetNoPrimary.new(
                  topology.options.merge(replica_set_name: updated_desc.replica_set_name),
                  topology.monitoring, self)
        Severity: Minor
        Found in lib/mongo/cluster/sdam_flow.rb - About 1 hr to fix

          Method distinct has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def distinct(field_name, opts = {})
                    if field_name.nil?
                      raise ArgumentError, 'Field name for distinct operation must be not nil'
                    end
                    opts = @options.merge(opts) unless Mongo.broken_view_options
          Severity: Minor
          Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

            Method add has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def add(host, add_options=nil)
                  address = Address.new(host, options)
                  if !addresses.include?(address)
                    opts = options.merge(monitor: false)
                    # If we aren't starting the montoring threads, we also don't want to
            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 wait_for_connection has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                  def wait_for_connection(connection_global_id, deadline)
                    connection = nil
                    while connection.nil?
                      # The second gate to checking out a connection. Make sure 1) there
                      # exists an available connection and 2) we are under max_connecting.
            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 ec2_metadata_credentials has a Cognitive Complexity of 10 (exceeds 5 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

            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 retrieve_and_connect_connection has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                  def retrieve_and_connect_connection(connection_global_id)
                    deadline = Utils.monotonic_time + wait_timeout
                    connection = nil
            
                    @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 credentials_valid? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                    def credentials_valid?(credentials, source)
                      unless credentials.access_key_id || credentials.secret_access_key ||
                        credentials.session_token
                      then
                        return false
            Severity: Minor
            Found in lib/mongo/auth/aws/credentials_retriever.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 check has a Cognitive Complexity of 10 (exceeds 5 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

            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_concern_option has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def validate_read_concern_option(read_concern)
                  return unless enabled?
                  return if read_concern.nil?
                  unless read_concern.is_a?(Hash)
                    raise Error::LintError, "Read concern is not a hash: #{read_concern}"
            Severity: Minor
            Found in lib/mongo/lint.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 has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def read(length, timeout: nil)
                  map_exceptions do
                    data = read_from_socket(length, timeout: timeout)
                    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 update_many has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                    def update_many(spec, 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

            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 10 (exceeds 5 allowed). Consider refactoring.
            Open

                  def command(connection)
                    if Lint.enabled?
                      unless connection.is_a?(Server::Connection)
                        raise Error::LintError, "Connection is not a Connection instance: #{connection}"
                      end
            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 add_read_preference_legacy has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                  def add_read_preference_legacy(sel, connection)
                    if read && (
                      connection.description.mongos? || connection.description.load_balancer?
                    ) && read_pref = read.to_mongos
                      # If the read preference contains only mode and mode is secondary
            Severity: Minor
            Found in lib/mongo/operation/shared/read_preference_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 apply_session_options has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                  def apply_session_options(sel, connection)
                    apply_cluster_time!(sel, connection)
                    sel[:txnNumber] = BSON::Int64.new(txn_num) if txn_num
                    sel.merge!(lsid: session.session_id)
                    apply_start_transaction!(sel)
            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 replace_one has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                    def replace_one(replacement, 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

            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 parse_password! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def parse_password!(string)
                  if (string && pwd = string.partition(AUTH_USER_PWD_DELIM)[2])
                    if pwd.length > 0
                      raise_invalid_error!(UNESCAPED_USER_PWD) if pwd =~ UNSAFE
                      pwd_decoded = decode(pwd)
            Severity: Minor
            Found in lib/mongo/uri.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 effective_read_preference has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                    def effective_read_preference(connection)
                      return unless view.read_preference
                      return view.read_preference unless write?
                      return view.read_preference unless [:secondary, :secondary_preferred].include?(view.read_preference[:mode])
            
            
            Severity: Minor
            Found in lib/mongo/collection/view/aggregation.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

            Severity
            Category
            Status
            Source
            Language