mongodb/mongo-ruby-driver

View on GitHub

Showing 393 of 447 total issues

Method run_benchmark has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

      def run_benchmark
        [].tap do |timings|
          iteration_count = 0
          cumulative_time = 0

Severity: Minor
Found in profile/driver_bench/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 normalized? has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def self.normalized?(string, form = :nfc)
    encoding = string.encoding
    case encoding
    when Encoding::UTF_8
      case form
Severity: Minor
Found in lib/mongo/auth/stringprep/unicode_normalize/normalize.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 each has a Cognitive Complexity of 15 (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
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 add_read_preference has a Cognitive Complexity of 15 (exceeds 5 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

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

          def initialize(opts)
            @opts = opts
            return if empty?

            if opts[:access_token]
Severity: Minor
Found in lib/mongo/crypt/kms/gcp/credentials.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 46 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 deliver has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def deliver(message, context, options = {})
            if Lint.enabled? && !@socket
              raise Error::LintError, "Trying to deliver a message over a disconnected connection (to #{address})"
            end
            buffer = serialize(message, context)
    Severity: Minor
    Found in lib/mongo/server/connection_base.rb - About 1 hr to fix

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

            def handshake_and_authenticate!
              speculative_auth_doc = nil
              if options[:user] || options[:auth_mech]
                # To create an Auth instance, we need to specify the mechanism,
                # but at this point we don't know the mechanism that ultimately
      Severity: Minor
      Found in lib/mongo/server/pending_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 14 (exceeds 5 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

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

            def add_server_diagnostics
              yield
            # Note that the exception should already have been mapped to a
            # Mongo::Error subclass when it gets to this method.
            rescue Error::SocketError, Error::SocketTimeoutError => e
      Severity: Minor
      Found in lib/mongo/server/connection_common.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_replacement_documents! has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

              def validate_replacement_documents!(spec)
                if replace = spec.is_a?(Array) ? spec&.first : spec
                  if key = replace.keys&.first
                    if key.to_s.start_with?("$")
                      if Mongo.validate_update_replace
      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 add_error_labels has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_error_labels(connection, context)
              yield
            rescue Mongo::Error::SocketError => e
              if context.in_transaction? && !context.committing_transaction?
                e.add_label('TransientTransactionError')
      Severity: Minor
      Found in lib/mongo/operation/shared/response_handling.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_param has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

              def validate_param(key, opts, format_hint, required: true)
                value = opts.fetch(key)
                return nil if value.nil? && !required
                if value.nil?
                  raise ArgumentError.new(
      Severity: Minor
      Found in lib/mongo/crypt/kms.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 abort_transaction has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def abort_transaction
            QueryCache.clear
      
            check_if_ended!
            check_if_no_transaction!
      Severity: Minor
      Found in lib/mongo/session.rb - About 1 hr to fix

        Method run_state_machine has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def run_state_machine
                while true
                  case state
                  when :error
                    Binding.check_ctx_status(self)
        Severity: Minor
        Found in lib/mongo/crypt/context.rb - About 1 hr to fix

          Method validate_authentication_options! has 41 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 initial_query_op has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def initial_query_op(session)
                      spec = {
                        coll_name: collection.name,
                        filter: filter,
                        projection: projection,
            Severity: Minor
            Found in lib/mongo/collection/view/iterable.rb - About 1 hr to fix

              Method kill_cursors has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def kill_cursors
                      # TODO optimize this to batch kill cursor operations for the same
                      # server/database/collection instead of killing each cursor
                      # individually.
                      loop do
              Severity: Minor
              Found in lib/mongo/cluster/reapers/cursor_reaper.rb - About 1 hr to fix

                Method do_execute has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def do_execute(connection, context, options = {})
                        session&.materialize_if_needed
                        unpin_maybe(session, connection) do
                          add_error_labels(connection, context) do
                            check_for_network_error do
                Severity: Minor
                Found in lib/mongo/operation/shared/executable.rb - About 1 hr to fix

                  Method add_txn_opts! has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def add_txn_opts!(command, read)
                        command.tap do |c|
                          # The read concern should be added to any command that starts a transaction.
                          if starting_transaction?
                            # https://jira.mongodb.org/browse/SPEC-1161: transaction's
                  Severity: Minor
                  Found in lib/mongo/session.rb - About 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language