mongodb/mongo-ruby-driver

View on GitHub

Showing 158 of 211 total issues

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

    def update_rs_with_primary_from_member
      if topology.replica_set_name != updated_desc.replica_set_name
        log_warn(
          "Removing server #{updated_desc.address.to_s} because it has an " +
          "incorrect replica set name (#{updated_desc.replica_set_name}); " +
Severity: Minor
Found in lib/mongo/cluster/sdam_flow.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 each has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def each
          raise StopIteration.new if closed?
          retried = false
          begin
            @cursor.each do |doc|
Severity: Minor
Found in lib/mongo/collection/view/change_stream.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 clear has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def clear(options = nil)
        raise_if_closed!

        @lock.synchronize do
          @generation += 1
Severity: Minor
Found in lib/mongo/server/connection_pool.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 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 generate_reply has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def self.generate_reply(command_payload, reply_payload)
          if reply_payload
            reply = reply_payload[:reply]
            if cursor = reply[:cursor]
              if !cursor.key?(Collection::NS)
Severity: Minor
Found in lib/mongo/monitoring/event/command_succeeded.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 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 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 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 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_cert(OpenSSL::X509::Certificate.new(File.open(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

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

                def start(connection = nil)
                  if connection && connection.features.op_msg_enabled?
                    selector = LOGIN.merge(payload: payload, mechanism: LDAP::MECHANISM)
                    selector[Protocol::Msg::DATABASE_IDENTIFIER] = Auth::EXTERNAL
                    cluster_time = connection.mongos? && connection.cluster_time
        Severity: Minor
        Found in lib/mongo/auth/ldap/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

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

            def validate_camel_case_read_preference(read_pref)
              return unless enabled?
              return if read_pref.nil?
              unless read_pref.is_a?(Hash)
                raise Error::LintError, "Read preference is not a hash: #{read_pref}"
        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 validate_underscore_read_preference has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_underscore_read_preference(read_pref)
              return unless enabled?
              return if read_pref.nil?
              unless read_pref.is_a?(Hash)
                raise Error::LintError, "Read preference is not a hash: #{read_pref}"
        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 apply_cluster_time! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def apply_cluster_time!(selector, server)
                if !server.standalone?
                  cluster_time = [server.cluster_time, (session && session.cluster_time)].max_by do |doc|
                    (doc && doc[Cluster::CLUSTER_TIME]) || ZERO_TIMESTAMP
                  end
        Severity: Minor
        Found in lib/mongo/operation/shared/sessions_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 get_more_command has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def get_more_command
                  command = { :getMore => cursor.id, :collection => collection_name }
                  command[:batchSize] = batch_size.abs if batch_size && batch_size != 0
                  # If the max_await_time_ms option is set, then we set maxTimeMS on
                  # the get more command.
        Severity: Minor
        Found in lib/mongo/cursor/builder/get_more_command.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