mongodb/mongo-ruby-driver

View on GitHub

Showing 178 of 233 total issues

Method open_download_stream_by_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def open_download_stream_by_name(filename, opts = {}, &block)
        revision = opts.fetch(:revision, -1)
        if revision < 0
          skip = revision.abs - 1
          sort = { 'uploadDate' => Mongo::Index::DESCENDING }
Severity: Minor
Found in lib/mongo/grid/fs_bucket.rb - About 35 mins 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 set_cert_verification has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def set_cert_verification(context, options)
        context.verify_mode = OpenSSL::SSL::VERIFY_PEER
        cert_store = OpenSSL::X509::Store.new
        if options[:ssl_ca_cert]
          cert_store.add_file(options[:ssl_ca_cert])
Severity: Minor
Found in lib/mongo/socket/ssl.rb - About 35 mins 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

Avoid too many return statements within this method.
Open

        return :standalone if standalone?
Severity: Major
Found in lib/mongo/server/description.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

            return :secondary if secondary?
    Severity: Major
    Found in lib/mongo/server/description.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return :other if other?
      Severity: Major
      Found in lib/mongo/server/description.rb - About 30 mins to fix

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

            def disconnect!(wait=false)
              unless @connecting || @connected
                return true
              end
              if options[:cleanup] != false
        Severity: Minor
        Found in lib/mongo/cluster.rb - About 25 mins 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_camel_case_read_preference_mode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_camel_case_read_preference_mode(mode)
              return unless enabled?
              if mode
                unless %w(primary primaryPreferred secondary secondaryPreferred nearest).include?(mode.to_s)
                  raise Error::LintError, "Invalid read preference mode: #{mode}"
        Severity: Minor
        Found in lib/mongo/lint.rb - About 25 mins 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 candidates has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def candidates(cluster)
                if cluster.single?
                  cluster.servers.each { |server| validate_max_staleness_support!(server) }
                elsif cluster.sharded?
                  local_threshold = local_threshold_with_cluster(cluster)
        Severity: Minor
        Found in lib/mongo/server_selector/selectable.rb - About 25 mins 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 written_count has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def written_count
                if acknowledged?
                  multiple? ? aggregate_written_count : (first_document[N] || 0)
                else
                  0
        Severity: Minor
        Found in lib/mongo/operation/result.rb - About 25 mins 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 deliver has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def deliver(message)
                buffer = serialize(message)
                ensure_connected do |socket|
                  operation_id = Monitoring.next_operation_id
                  command_started(address, operation_id, message.payload, socket.object_id)
        Severity: Minor
        Found in lib/mongo/server/connection_base.rb - About 25 mins 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_txt_options! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def parse_txt_options!(string)
                string.split(INDIV_URI_OPTS_DELIM).reduce({}) do |txt_options, opt|
                  raise Error::InvalidTXTRecord.new(INVALID_OPTS_VALUE_DELIM) unless opt.index(URI_OPTS_VALUE_DELIM)
                  key, value = opt.split(URI_OPTS_VALUE_DELIM)
                  raise Error::InvalidTXTRecord.new(INVALID_TXT_RECORD_OPTION) unless VALID_TXT_OPTIONS.include?(key.downcase)
        Severity: Minor
        Found in lib/mongo/uri/srv_protocol.rb - About 25 mins 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 handshake! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def handshake!(socket)
                unless socket
                  raise Error::HandshakeError, "Cannot handshake because there is no usable socket (for #{address})"
                end
        
        
        Severity: Minor
        Found in lib/mongo/server/connection.rb - About 25 mins 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 hangul_comp_one has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.hangul_comp_one(string)
            length = string.length
            if length>1 and 0 <= (lead =string[0].ord-LBASE) and lead  < LCOUNT and
                            0 <= (vowel=string[1].ord-VBASE) and vowel < VCOUNT
              lead_vowel = SBASE + (lead * VCOUNT + vowel) * TCOUNT
        Severity: Minor
        Found in lib/mongo/auth/stringprep/unicode_normalize/normalize.rb - About 25 mins 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_camel_case_read_preference has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_camel_case_read_preference(read_pref)
              return unless enabled?
              return if read_pref.nil?
              unless read_pref.is_a?(Hash)
                raise Error::LintError, "Read preference is not a hash: #{read_pref}"
        Severity: Minor
        Found in lib/mongo/lint.rb - About 25 mins 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 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def stale_primary?
              if updated_desc.election_id && updated_desc.set_version
                if topology.max_set_version && topology.max_election_id &&
                    (updated_desc.set_version < topology.max_set_version ||
                        (updated_desc.set_version == topology.max_set_version &&
        Severity: Minor
        Found in lib/mongo/cluster/sdam_flow.rb - About 25 mins 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 each has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def each
              # If we already iterated past the first batch (i.e., called get_more
              # at least once), the cursor on the server side has advanced past
              # the first batch and restarting iteration from the beginning by
              # returning initial result would miss documents in the second batch
        Severity: Minor
        Found in lib/mongo/cursor.rb - About 25 mins 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_max_min_pool_size! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_max_min_pool_size!(option, opts)
              if option == :min_pool_size && opts[:min_pool_size]
                max = opts[:max_pool_size] || Server::ConnectionPool::DEFAULT_MAX_SIZE
                raise Error::InvalidMinPoolSize.new(opts[:min_pool_size], max) unless opts[:min_pool_size] <= max
              end
        Severity: Minor
        Found in lib/mongo/client.rb - About 25 mins 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 continue has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def continue(reply, connection = nil)
                  validate_first_message!(reply)
        
                  # The salted password needs to be calculated now; otherwise, if the
                  # client key is cached from a previous authentication, the salt in the
        Severity: Minor
        Found in lib/mongo/auth/scram/conversation.rb - About 25 mins 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 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def start(connection = nil)
                  if connection && connection.features.op_msg_enabled?
                    selector = LOGIN.merge(payload: payload, mechanism: LDAP::MECHANISM)
                    selector[Protocol::Msg::DATABASE_IDENTIFIER] = Auth::EXTERNAL
                    cluster_time = connection.mongos? && connection.cluster_time
        Severity: Minor
        Found in lib/mongo/auth/ldap/conversation.rb - About 25 mins 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 modern_read_with_retry has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def modern_read_with_retry(session, server_selector, &block)
              attempt = 0
              server = select_server(cluster, server_selector, session)
              begin
                yield server
        Severity: Minor
        Found in lib/mongo/retryable.rb - About 25 mins 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