mongodb/mongo-ruby-driver

View on GitHub

Showing 447 of 447 total issues

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

  module Crypt
    module KMS
      module Azure
        # Azure KMS master key document object contains KMS master key parameters.
        #
Severity: Major
Found in lib/mongo/crypt/kms/azure/master_document.rb and 1 other location - About 1 hr to fix
lib/mongo/crypt/kms/aws/master_document.rb on lines 19..70

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 68.

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

  module Crypt
    module KMS
      module AWS
        # AWS KMS master key document object contains KMS master key parameters.
        #
Severity: Major
Found in lib/mongo/crypt/kms/aws/master_document.rb and 1 other location - About 1 hr to fix
lib/mongo/crypt/kms/azure/master_document.rb on lines 19..70

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 68.

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

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

        def validate_authentication_options!
          auth_mech = options[:auth_mech]
          user = options[:user]
          password = options[:password]
          auth_source = options[:auth_source]
    Severity: Minor
    Found in lib/mongo/client.rb - About 1 hr to fix

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

            def kill_cursors
              # TODO optimize this to batch kill cursor operations for the same
              # server/database/collection instead of killing each cursor
              # individually.
              loop do
      Severity: Minor
      Found in lib/mongo/cluster/reapers/cursor_reaper.rb - About 1 hr to fix

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

                def initial_query_op(session)
                  spec = {
                    coll_name: collection.name,
                    filter: filter,
                    projection: projection,
        Severity: Minor
        Found in lib/mongo/collection/view/iterable.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 do_execute has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def do_execute(connection, context, options = {})
                    session&.materialize_if_needed
                    unpin_maybe(session, connection) do
                      add_error_labels(connection, context) do
                        check_for_network_error do
            Severity: Minor
            Found in lib/mongo/operation/shared/executable.rb - About 1 hr to fix

              Method handshake_and_authenticate! has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def handshake_and_authenticate!
                      speculative_auth_doc = nil
                      if options[:user] || options[:auth_mech]
                        # To create an Auth instance, we need to specify the mechanism,
                        # but at this point we don't know the mechanism that ultimately
              Severity: Minor
              Found in lib/mongo/server/pending_connection.rb - About 1 hr to fix

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

                      def close(options = nil)
                        return if closed?
                
                        options ||= {}
                
                
                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 validate_session_support! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    def validate_session_support!
                      if topology.is_a?(Topology::LoadBalanced)
                        return
                      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 get_connection has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                      def get_connection(pid, connection_global_id)
                        if connection = next_available_connection(connection_global_id)
                          unless valid_available_connection?(connection, pid, connection_global_id)
                            return nil
                          end
                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 reconstruct_uri has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    def reconstruct_uri
                      servers = @servers.join(',')
                      options = options_mapper.ruby_to_string(@uri_options).map do |k, vs|
                        unless vs.nil?
                          if vs.is_a?(Array)
                Severity: Minor
                Found in lib/mongo/uri.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 update_rs_from_primary has a Cognitive Complexity of 13 (exceeds 5 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

                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, connection_description, connection_global_id, ids)
                          @replies = [*replies] if replies
                          @connection_description = connection_description
                          @connection_global_id = connection_global_id
                          if replies && replies.first && (doc = replies.first.documents.first)
                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 find_one_and_update has a Cognitive Complexity of 13 (exceeds 5 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

                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 13 (exceeds 5 allowed). Consider refactoring.
                Open

                      def self.deserialize(io,
                        max_message_size = MAX_MESSAGE_SIZE,
                        expected_response_to = nil,
                        options = {}
                      )
                Severity: Minor
                Found in lib/mongo/protocol/message.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 find_command has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                        def find_command
                          document = BSON::Document.new(
                            find: collection,
                            filter: query_filter,
                          )
                Severity: Minor
                Found in lib/mongo/protocol/query.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