mongodb/mongo-ruby-driver

View on GitHub

Showing 190 of 244 total issues

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

      def initial(cluster, monitoring, options)
        cls = if options.key?(:connect)
          OPTIONS.fetch(options[:connect].to_sym)
        elsif options.key?(:replica_set) || options.key?(:replica_set_name)
          ReplicaSetNoPrimary
Severity: Minor
Found in lib/mongo/cluster/topology.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 document has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def document
        client_document = full_client_document
        while client_document.to_bson.to_s.size > MAX_DOCUMENT_SIZE do
          if client_document[:os][:name] || client_document[:os][:architecture]
            client_document[:os].delete(:name)
Severity: Minor
Found in lib/mongo/server/app_metadata.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 server_type has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def server_type
        return :arbiter if arbiter?
        return :ghost if ghost?
        return :sharded if mongos?
        return :primary if primary?
Severity: Minor
Found in lib/mongo/server/description.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 start has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def start(connection = nil)
          login = LOGIN.merge(mechanism: X509::MECHANISM)
          login[:user] = user.name if user.name
          if connection && connection.features.op_msg_enabled?
            selector = login
Severity: Minor
Found in lib/mongo/auth/x509/conversation.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 max_staleness has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def max_staleness(value)
      if /\A-?\d+\z/ =~ value
        int = value.to_i

        if int == -1
Severity: Minor
Found in lib/mongo/uri.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 count has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def count(opts = {})
          cmd = { :count => collection.name, :query => filter }
          cmd[:skip] = opts[:skip] if opts[:skip]
          cmd[:hint] = opts[:hint] if opts[:hint]
          cmd[:limit] = opts[:limit] if opts[:limit]
Severity: Minor
Found in lib/mongo/collection/view/readable.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 deserialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def self.deserialize(io, max_message_size = MAX_MESSAGE_SIZE, expected_response_to = nil)
        length, _request_id, response_to, _op_code = deserialize_header(BSON::ByteBuffer.new(io.read(16)))

        # Protection from potential DOS man-in-the-middle attacks. See
        # DRIVERS-276.
Severity: Minor
Found in lib/mongo/protocol/message.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 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

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 :secondary if secondary?
    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

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

            def validate_underscore_read_preference_mode(mode)
              return unless enabled?
              if mode
                unless %w(primary primary_preferred secondary secondary_preferred nearest).include?(mode.to_s)
                  raise Error::LintError, "Invalid read preference mode: #{mode}"
        Severity: Minor
        Found in lib/mongo/lint.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 with has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def with(new_options)
              new_options.keys.each do |k|
                raise Error::UnchangeableCollectionOption.new(k) unless CHANGEABLE_OPTIONS.include?(k)
              end
              options = @options.dup
        Severity: Minor
        Found in lib/mongo/collection.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 connect! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def connect!
                if closed?
                  if Lint.enabled?
                    raise Error::LintError, "Reconnecting closed connections is no longer supported (for #{address})"
                  else
        Severity: Minor
        Found in lib/mongo/server/connection.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 each has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def each
                  raise StopIteration.new if closed?
                  loop do
                    document = try_next
                    yield document if document
        Severity: Minor
        Found in lib/mongo/collection/view/change_stream.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 each has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def each
              # If we already iterated past the first batch (i.e., called get_more
              # at least once), the cursor on the server side has advanced past
              # the first batch and restarting iteration from the beginning by
              # returning initial result would miss documents in the second batch
        Severity: Minor
        Found in lib/mongo/cursor.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 server_selection_diagnostic_message has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def server_selection_diagnostic_message(cluster)
                msg = ''
                dead_monitors = []
                cluster.servers_list.each do |server|
                  thread = server.monitor.instance_variable_get('@thread')
        Severity: Minor
        Found in lib/mongo/server_selector/selectable.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