mongodb/mongo-ruby-driver

View on GitHub

Showing 423 of 480 total issues

Method find_one_and_update has a Cognitive Complexity of 13 (exceeds 5 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

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

    def reconstruct_uri
      servers = @servers.join(',')
      options = options_mapper.ruby_to_string(@uri_options).map do |k, vs|
        unless vs.nil?
          if vs.is_a?(Array)
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 update_rs_from_primary has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def update_rs_from_primary
      if topology.replica_set_name.nil?
        @topology = Topology::ReplicaSetWithPrimary.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

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

        def initialize(replies, connection_description, connection_global_id, ids)
          @replies = [*replies] if replies
          @connection_description = connection_description
          @connection_global_id = connection_global_id
          if replies && replies.first && (doc = replies.first.documents.first)
Severity: Minor
Found in lib/mongo/operation/insert/bulk_result.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 try_next has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

        def try_next
          recreate_cursor! if @timed_out

          raise StopIteration.new if closed?

Severity: Minor
Found in lib/mongo/collection/view/change_stream.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_command has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

        def find_command
          document = BSON::Document.new(
            find: collection,
            filter: query_filter,
          )
Severity: Minor
Found in lib/mongo/protocol/query.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 run_state_machine has a Cognitive Complexity of 13 (exceeds 5 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

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

      def parse_code
        if document['ok'] == 1 || @options[:legacy]
          @code = @code_name = nil
        else
          @code = document['code']
Severity: Minor
Found in lib/mongo/error/parser.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_delete has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def find_one_and_delete(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 initialize has 37 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 handshake! has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def handshake!(speculative_auth_doc: nil)
              unless socket
                raise Error::InternalDriverError, "Cannot handshake because there is no usable socket (for #{address})"
              end
      
      
      Severity: Minor
      Found in lib/mongo/server/pending_connection.rb - About 1 hr to fix

        Method ec2_metadata_credentials has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def ec2_metadata_credentials(timeout_holder = nil)
                  timeout_holder&.check_timeout!
                  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.
        Severity: Minor
        Found in lib/mongo/auth/aws/credentials_retriever.rb - About 1 hr to fix

          Method retry_read has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def retry_read(original_error, session, server_selector, context: nil, failed_server: nil, &block)
                  server = select_server_for_retry(
                    original_error, session, server_selector, context, failed_server
                  )
          
          
          Severity: Minor
          Found in lib/mongo/retryable/read_worker.rb - About 1 hr to fix

            Method create has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def create(opts = {})
                  # Passing read options to create command causes it to break.
                  # Filter the read options out. Session is also excluded here as it gets
                  # used by the call to with_session and should not be part of the
                  # operation. If it gets passed to the operation it would fail BSON
            Severity: Minor
            Found in lib/mongo/collection.rb - About 1 hr to fix

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

                Method parse! has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def parse!(remaining)
                      hosts_and_db, options = remaining.split('?', 2)
                      if options && options.index('?')
                        raise_invalid_error!("Options contain an unescaped question mark (?), or the database name contains a question mark and was not escaped")
                      end
                Severity: Minor
                Found in lib/mongo/uri.rb - About 1 hr to fix

                  Method distinct has 36 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 delete_one has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            def delete_one(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 initial_query_op has 36 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 read_with_timeout has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def read_with_timeout(length, timeout)
                              deadline = Utils.monotonic_time + timeout
                              map_exceptions do
                                String.new.tap do |data|
                                  while data.length < length
                        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

                        Severity
                        Category
                        Status
                        Source
                        Language