mongodb/mongo-ruby-driver

View on GitHub

Showing 393 of 447 total issues

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

      def validate!
        if !@tag_sets.all? { |set| set.empty? } && !tags_allowed?
          raise Error::InvalidServerPreference.new(Error::InvalidServerPreference::NO_TAG_SUPPORT)
        elsif @max_staleness && !max_staleness_allowed?
          raise Error::InvalidServerPreference.new(Error::InvalidServerPreference::NO_MAX_STALENESS_SUPPORT)
Severity: Minor
Found in lib/mongo/server_selector/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 update_one has a Cognitive Complexity of 10 (exceeds 5 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

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

      def get(**opts)
        limit = normalized_limit(opts[:limit])

        _namespace_key = namespace_key(**opts)
        _cache_key = cache_key(**opts)
Severity: Minor
Found in lib/mongo/query_cache.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 10 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(replies, connection_description = nil, connection_global_id = nil)
        if replies
          if replies.is_a?(Array)
            if replies.length != 1
              raise ArgumentError, "Only one (or zero) reply is supported, given #{replies.length}"
Severity: Minor
Found in lib/mongo/operation/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 initialize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(kms_providers, kms_tls_options, options={})
        # FFI::AutoPointer uses a custom release strategy to automatically free
        # the pointer once this object goes out of scope
        @mongocrypt = FFI::AutoPointer.new(
          Binding.mongocrypt_new,
Severity: Minor
Found in lib/mongo/crypt/handle.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 to_document has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def to_document
          BSON::Document.new.tap do |bson|
            bson[:aws] = @aws.to_document if @aws
            bson[:azure] = @azure.to_document if @azure
            bson[:gcp] = @gcp.to_document if @gcp
Severity: Minor
Found in lib/mongo/crypt/kms/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 each has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def each
          # If the caching cursor is closed and was not fully iterated,
          # the documents we have in it are not the complete result set and
          # we have no way of completing that iteration.
          # Therefore, discard that cursor and start iteration again.
Severity: Minor
Found in lib/mongo/collection/view/iterable.rb - About 1 hr to fix

    Method get_records has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def get_records(hostname, srv_service_name=nil, srv_max_hosts=nil)
            query_name = record_prefix(srv_service_name) + hostname
            resources = @resolver.getresources(query_name, Resolv::DNS::Resource::IN::SRV)
    
            # Collect all of the records into a Result object, raising an error
    Severity: Minor
    Found in lib/mongo/srv/resolver.rb - About 1 hr to fix

      Method update_options has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def update_options(new_options)
            old_options = @options
      
            new_options = self.class.canonicalize_ruby_options(new_options || {})
      
      
      Severity: Minor
      Found in lib/mongo/client.rb - About 1 hr to fix

        Method insert_one has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def insert_one(document, opts = {})
              QueryCache.clear_namespace(namespace)
        
              client.with_session(opts) do |session|
                write_concern = if opts[:write_concern]
        Severity: Minor
        Found in lib/mongo/collection.rb - About 1 hr to fix

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

            Method count has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def count(opts = {})
                      opts = @options.merge(opts) unless Mongo.broken_view_options
                      cmd = { :count => collection.name, :query => filter }
                      cmd[:skip] = opts[:skip] if opts[:skip]
                      cmd[:hint] = opts[:hint] if opts[:hint]
            Severity: Minor
            Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

              Method stale_primary? has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def stale_primary?
                    if updated_desc.max_wire_version >= 17
                      if updated_desc.election_id.nil? && !topology.max_election_id.nil?
                        return true
                      end
              Severity: Minor
              Found in lib/mongo/cluster/sdam_flow.rb - About 1 hr to fix

                Method initialize has 8 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        def initialize(command_name, database_name, address,
                          request_id, operation_id, message, failure, duration,
                          started_event:, server_connection_id: nil, service_id: nil
                Severity: Major
                Found in lib/mongo/monitoring/event/command_failed.rb - About 1 hr to fix

                  Method split_execute has 8 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def split_execute(name, values, connection, context, operation_id, result_combiner, session, txn_num)
                  Severity: Major
                  Found in lib/mongo/bulk_write.rb - About 1 hr to fix

                    Method execute_operation has 8 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def execute_operation(name, values, connection, context, operation_id, result_combiner, session, txn_num = nil)
                    Severity: Major
                    Found in lib/mongo/bulk_write.rb - About 1 hr to fix

                      Method update_options has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def update_options(new_options)
                            old_options = @options
                      
                            new_options = self.class.canonicalize_ruby_options(new_options || {})
                      
                      
                      Severity: Minor
                      Found in lib/mongo/client.rb - About 55 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 check has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def check
                              @lock.synchronize do
                                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!
                      Severity: Minor
                      Found in lib/mongo/server/push_monitor.rb - About 55 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 unknown! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def unknown!(options = {})
                            pool = pool_internal
                      
                            if load_balancer?
                              # When the client is in load-balanced topology, servers (the one and
                      Severity: Minor
                      Found in lib/mongo/server.rb - About 55 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 do_work has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def do_work
                              scan!
                              # @next_wanted_scan may be updated by the push monitor.
                              # However we need to check for termination flag so that the monitor
                              # thread exits when requested.
                      Severity: Minor
                      Found in lib/mongo/server/monitor.rb - About 55 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