mongodb/mongo-ruby-driver

View on GitHub

Showing 247 of 247 total issues

Method update_rs_from_primary has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def update_rs_from_primary
      if topology.replica_set_name.nil?
        @topology = Topology::ReplicaSetWithPrimary.new(
          topology.options.merge(replica_set_name: updated_desc.replica_set_name),
          topology.monitoring, self)
Severity: Minor
Found in lib/mongo/cluster/sdam_flow.rb - About 1 hr to fix

    Method add_error_labels has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

          def add_error_labels
            begin
              yield
            rescue Mongo::Error::SocketError => e
              if session && session.in_transaction? && !session.committing_transaction?
    Severity: Minor
    Found in lib/mongo/operation/shared/response_handling.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 15 (exceeds 5 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

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

      def self.normalized?(string, form = :nfc)
        encoding = string.encoding
        case encoding
        when Encoding::UTF_8
          case form
    Severity: Minor
    Found in lib/mongo/auth/stringprep/unicode_normalize/normalize.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 read_from_socket has 47 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def read_from_socket(length)
          # Just in case
          if length == 0
            return ''.force_encoding('BINARY')
          end
    Severity: Minor
    Found in lib/mongo/socket.rb - About 1 hr to fix

      Method commit_transaction has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def commit_transaction(options=nil)
            check_if_ended!
            check_if_no_transaction!
      
            if within_states?(TRANSACTION_ABORTED_STATE)
      Severity: Minor
      Found in lib/mongo/session.rb - About 1 hr to fix

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

            def validate_new_options!(opts = Options::Redacted.new)
              return Options::Redacted.new unless opts
              Lint.validate_underscore_read_preference(opts[:read])
              Lint.validate_read_concern_option(opts[:read_concern])
              opts.each.inject(Options::Redacted.new) do |_options, (k, v)|
        Severity: Minor
        Found in lib/mongo/client.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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                def replace_one(replacement, opts = {})
                  update_doc = { Operation::Q => filter,
                                 Operation::U => replacement,
                                }
                  if opts[:upsert]
        Severity: Major
        Found in lib/mongo/collection/view/writable.rb and 1 other location - About 1 hr to fix
        lib/mongo/collection/view/writable.rb on lines 323..344

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 70.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                def update_one(spec, opts = {})
                  update_doc = { Operation::Q => filter,
                                 Operation::U => spec,
                                 }
                  if opts[:upsert]
        Severity: Major
        Found in lib/mongo/collection/view/writable.rb and 1 other location - About 1 hr to fix
        lib/mongo/collection/view/writable.rb on lines 232..253

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 70.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

          Method add_txn_opts! has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def add_txn_opts!(command, read)
                command.tap do |c|
                  # The read concern should be added to any command that starts a transaction.
                  if starting_transaction?
                    # https://jira.mongodb.org/browse/SPEC-1161: transaction's
          Severity: Minor
          Found in lib/mongo/session.rb - About 1 hr to fix

            Method post_handshake has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def post_handshake(response, average_rtt)
                    if response["ok"] == 1
                      # Auth mechanism is entirely dependent on the contents of
                      # ismaster response *for this connection*.
                      # Ismaster received by the monitoring connection should advertise
            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 close_idle_sockets has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def close_idle_sockets
                    return if closed?
                    return unless max_idle_time
            
                    @lock.synchronize do
            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 initialize has a Cognitive Complexity of 13 (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 start has a Cognitive Complexity of 13 (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 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 13 (exceeds 5 allowed). Consider refactoring.
            Open

                    def initialize(replies, ids)
                      @replies = [*replies] if replies
                      if replies && replies.first && (doc = replies.first.documents.first)
                        if errors = doc['writeErrors']
                          # some documents were potentially inserted
            Severity: Minor
            Found in lib/mongo/operation/insert/bulk_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 legacy_read_with_retry has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def legacy_read_with_retry(session, server_selector)
                  attempt = 0
                  server = select_server(cluster, server_selector, session)
                  begin
                    attempt += 1
            Severity: Minor
            Found in lib/mongo/retryable.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 parse_code has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def parse_code
                    if document['ok'] == 1 || @options[:legacy]
                      @code = @code_name = nil
                    else
                      @code = document['code']
            Severity: Minor
            Found in lib/mongo/error/parser.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 parse! has 39 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 initialize has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def initialize(addresses_or_uri, options = nil)
                    options = options ? options.dup : {}
              
                    srv_uri = nil
                    if addresses_or_uri.is_a?(::String)
              Severity: Minor
              Found in lib/mongo/client.rb - About 1 hr to fix
                Severity
                Category
                Status
                Source
                Language