mongodb/mongo-ruby-driver

View on GitHub

Showing 227 of 284 total issues

Method end_session has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def end_session
      if !ended? && @client
        if within_states?(TRANSACTION_IN_PROGRESS_STATE)
          begin
            abort_transaction
Severity: Minor
Found in lib/mongo/session.rb - About 35 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 set_kms_providers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def set_kms_providers(kms_providers)
        unless kms_providers
          raise ArgumentError.new("The kms_providers option must not be nil")
        end

Severity: Minor
Found in lib/mongo/crypt/handle.rb - About 35 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 set_cert_verification has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def set_cert_verification(context, options)
        context.verify_mode = OpenSSL::SSL::VERIFY_PEER
        cert_store = OpenSSL::X509::Store.new
        if options[:ssl_ca_cert]
          cert_store.add_file(options[:ssl_ca_cert])
Severity: Minor
Found in lib/mongo/socket/ssl.rb - About 35 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 open_download_stream_by_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def open_download_stream_by_name(filename, opts = {}, &block)
        revision = opts.fetch(:revision, -1)
        if revision < 0
          skip = revision.abs - 1
          sort = { 'uploadDate' => Mongo::Index::DESCENDING }
Severity: Minor
Found in lib/mongo/grid/fs_bucket.rb - About 35 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 collections_info_spec has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def collections_info_spec(session, options = {})
        { selector: {
            listCollections: 1,
            cursor: batch_size ? { batchSize: batch_size } : {} },
          db_name: @database.name,
Severity: Minor
Found in lib/mongo/database/view.rb - About 35 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 validate_read_preference! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def validate_read_preference!(command)
      return unless in_transaction?
      return unless command['$readPreference']

      mode = command['$readPreference']['mode'] || command['$readPreference'][:mode]
Severity: Minor
Found in lib/mongo/session.rb - About 35 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 retry_write has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def retry_write(original_error, session, txn_num, &block)
      # We do not request a scan of the cluster here, because error handling
      # for the error which triggered the retry should have updated the
      # server description and/or topology as necessary (specifically,
      # a socket error or a not master error should have marked the respective
Severity: Minor
Found in lib/mongo/retryable.rb - About 35 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 set_default_options has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def set_default_options(options)
        opts = options.dup

        extra_options = opts.delete(:extra_options) || Options::Redacted.new
        extra_options = DEFAULT_EXTRA_OPTIONS.merge(extra_options)
Severity: Minor
Found in lib/mongo/crypt/auto_encrypter.rb - About 35 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

Avoid too many return statements within this method.
Open

        return :standalone if standalone?
Severity: Major
Found in lib/mongo/server/description.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

            return :other if other?
    Severity: Major
    Found in lib/mongo/server/description.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return :secondary if secondary?
      Severity: Major
      Found in lib/mongo/server/description.rb - About 30 mins to fix

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

            def scan!(sync=true)
              if sync
                servers_list.each do |server|
                  if server.monitor
                    server.monitor.scan!
        Severity: Minor
        Found in lib/mongo/cluster.rb - About 25 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 stale_primary? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def stale_primary?
              if updated_desc.election_id && updated_desc.set_version
                if topology.max_set_version && topology.max_election_id &&
                    (updated_desc.set_version < topology.max_set_version ||
                        (updated_desc.set_version == topology.max_set_version &&
        Severity: Minor
        Found in lib/mongo/cluster/sdam_flow.rb - About 25 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 validate_max_min_pool_size! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_max_min_pool_size!(option, opts)
              if option == :min_pool_size && opts[:min_pool_size]
                max = opts[:max_pool_size] || Server::ConnectionPool::DEFAULT_MAX_SIZE
                raise Error::InvalidMinPoolSize.new(opts[:min_pool_size], max) unless opts[:min_pool_size] <= max
              end
        Severity: Minor
        Found in lib/mongo/client.rb - About 25 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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize(string, options = {})
              unless string
                raise Error::InvalidURI.new(string, 'URI must be a string, not nil.')
              end
              if string.empty?
        Severity: Minor
        Found in lib/mongo/uri.rb - About 25 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 parse_user! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def parse_user!(string)
              if (string && user = string.partition(AUTH_USER_PWD_DELIM)[0])
                raise_invalid_error!(UNESCAPED_USER_PWD) if user =~ UNSAFE
                user_decoded = decode(user)
                if user_decoded =~ PERCENT_CHAR && encode(user_decoded) != user
        Severity: Minor
        Found in lib/mongo/uri.rb - About 25 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 update_selector_for_read_pref has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def update_selector_for_read_pref(sel, server)
                if read && server.mongos? && read_pref = read.to_mongos
                  Mongo::Lint.validate_camel_case_read_preference(read_pref)
                  sel = sel[:$query] ? sel : {:$query => sel}
                  sel = sel.merge(:$readPreference => read_pref)
        Severity: Minor
        Found in lib/mongo/operation/shared/read_preference_supported.rb - About 25 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 update_options_for_slave_ok has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def update_options_for_slave_ok(opts, server)
                if (server.cluster.single? && !server.mongos?) || (read && read.slave_ok?)
                  opts.dup.tap do |o|
                    (o[:flags] ||= []) << SLAVE_OK
                  end
        Severity: Minor
        Found in lib/mongo/operation/shared/read_preference_supported.rb - About 25 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 n_modified has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def n_modified
                  return 0 unless acknowledged?
                  @replies.reduce(0) do |n, reply|
                    if n && reply.documents.first[MODIFIED]
                      n += reply.documents.first[MODIFIED]
        Severity: Minor
        Found in lib/mongo/operation/update/bulk_result.rb - About 25 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 continue has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def continue(reply, connection)
                  validate_first_message!(reply, connection.server)
        
                  if connection && connection.features.op_msg_enabled?
                    selector = CLIENT_CONTINUE_MESSAGE.merge(
        Severity: Minor
        Found in lib/mongo/auth/scram/conversation.rb - About 25 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