mongodb/mongo-ruby-driver

View on GitHub

Showing 447 of 447 total issues

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

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 39 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 download_url has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def download_url
        @download_url ||= begin
          info = JSON.load(uri_open('http://downloads.mongodb.org/current.json').read)
          version = info['versions'].detect do |version|
            version['version'].start_with?(desired_version) &&
    Severity: Minor
    Found in .evergreen/tools.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 update_one has 37 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 update_many has 37 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 replace_one has 37 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 ec2_metadata_credentials has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      def ec2_metadata_credentials
                        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.
                          {'x-aws-ec2-metadata-token-ttl-seconds' => '30'})
              Severity: Minor
              Found in lib/mongo/auth/aws/credentials_retriever.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 estimated_document_count has 36 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 start_stop_srv_monitor has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def start_stop_srv_monitor
                            # SRV URI is either always given or not for a given cluster, if one
                            # wasn't given we shouldn't ever have an SRV monitor to manage.
                            return unless options[:srv_uri]
                      
                      
                      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

                      Method close has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def close
                            @state_change_lock.synchronize do
                              unless connecting? || connected?
                                return nil
                              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

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

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

                            def do_check_in(connection)
                              # When a connection is interrupted it is checked back into the pool
                              # and closed. The operation that was using the connection before it was
                              # interrupted will attempt to check it back into the pool, and we
                              # should ignore it since its already been closed and removed from the pool.
                      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 connect! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def connect!
                              raise_if_closed!
                      
                              unless @socket
                                @socket = create_socket
                      Severity: Minor
                      Found in lib/mongo/server/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 try_select_server has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def try_select_server(cluster, write_aggregation: false, deprioritized: [])
                              servers = if write_aggregation && cluster.replica_set?
                                # 1. Check if ALL servers in cluster support secondary writes.
                                is_write_supported = cluster.servers.reduce(true) do |res, server|
                                  res && server.features.merge_out_on_secondary_enabled?
                      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 try_next has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def try_next
                            if @documents.nil?
                              # Since published versions of Mongoid have a copy of old driver cursor
                              # code, our dup call in #process isn't invoked when Mongoid query
                              # cache is active. Work around that by also calling dup here on
                      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 smc_to_ruby has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def smc_to_ruby(opts)
                              uri_options = {}
                      
                              opts.each do |key, value|
                                strategy = URI_OPTION_MAP[key.downcase]
                      Severity: Minor
                      Found in lib/mongo/uri/options_mapper.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_length! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                                def validate_length!(index, num_chunks, chunk, length_read)
                                  if num_chunks > 0 && chunk.data.data.size > 0
                                    raise Error::ExtraFileChunk.new unless index < num_chunks
                                    if index == num_chunks - 1
                                      unless chunk.data.data.size + length_read == file_info.length
                      Severity: Minor
                      Found in lib/mongo/grid/stream/read.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