mongodb/mongo-ruby-driver

View on GitHub

Showing 423 of 480 total issues

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

      def initialize(address, config = {}, average_round_trip_time: nil,
        minimum_round_trip_time: 0, load_balancer: false,
        force_load_balancer: false
      )
        @address = address
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 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 find_one_and_update has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def find_one_and_update(document, opts = {})
          value = 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

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

          def run_state_machine(timeout_holder)
            while true
              timeout_ms = timeout_holder.remaining_timeout_ms!
              case state
              when :error
    Severity: Minor
    Found in lib/mongo/crypt/context.rb - About 1 hr to fix

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

            def do_execute(connection, context, options = {})
              # Save the context on the instance, to avoid having to pass it as a
              # parameter to every single method. There are many legacy methods that
              # still accept it as a parameter, which are left as-is for now to
              # minimize the impact of this change. Moving forward, it may be
      Severity: Minor
      Found in lib/mongo/operation/shared/executable.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 replace_one has 41 lines of code (exceeds 25 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

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

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

                      def update_one(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

                Method handshake_and_authenticate! has 40 lines of code (exceeds 25 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

                  Method estimated_document_count has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          def estimated_document_count(opts = {})
                            unless view.filter.empty?
                              raise ArgumentError, "Cannot call estimated_document_count when querying with a filter"
                            end
                  
                  
                  Severity: Minor
                  Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

                    Method parallel_scan has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            def parallel_scan(cursor_count, options = {})
                              if options[:session]
                                # The session would be overwritten by the one in +options+ later.
                                session = client.get_session(@options)
                              else
                    Severity: Minor
                    Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

                      Method execute has 40 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
                            validate_requests!
                      Severity: Minor
                      Found in lib/mongo/bulk_write.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 close has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                              def close(options = nil)
                                return if closed?
                        
                                options ||= {}
                        
                        
                        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 get_connection has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                              def get_connection(pid, connection_global_id)
                                if connection = next_available_connection(connection_global_id)
                                  unless valid_available_connection?(connection, pid, connection_global_id)
                                    return nil
                                  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 validate_session_support! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def validate_session_support!(timeout: nil)
                              if topology.is_a?(Topology::LoadBalanced)
                                return
                              end
                        
                        
                        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

                        Severity
                        Category
                        Status
                        Source
                        Language