mongodb/mongo-ruby-driver

View on GitHub

Showing 447 of 447 total issues

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

        def validate_update_documents!(spec)
          if update = spec.is_a?(Array) ? spec&.first : spec
            if key = update.keys&.first
              unless key.to_s.start_with?("$")
                if Mongo.validate_update_replace
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 convert_limit_and_batch_size! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

          module_function def convert_limit_and_batch_size!(command)
            if command[:limit] && command[:limit] < 0 &&
              command[:batchSize] && command[:batchSize] < 0
            then
              command[:limit] = command[:limit].abs
Severity: Minor
Found in lib/mongo/operation/find/builder/command.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 maybe_set_schema_map has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def maybe_set_schema_map(options)
        if !options[:schema_map] && !options[:schema_map_path]
          @schema_map = nil
        elsif options[:schema_map] && options[:schema_map_path]
          raise ArgumentError.new(
Severity: Minor
Found in lib/mongo/crypt/handle.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 set_algorithm_opts has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def set_algorithm_opts(options)
        Binding.ctx_setopt_algorithm(self, options[:algorithm])
        if %w(Indexed RangePreview).include?(options[:algorithm])
          if options[:contention_factor]
            Binding.ctx_setopt_contention_factor(self, options[:contention_factor])
Severity: Minor
Found in lib/mongo/crypt/explicit_encryption_context.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_records has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def get_records(hostname, srv_service_name=nil, srv_max_hosts=nil)
        query_name = record_prefix(srv_service_name) + hostname
        resources = @resolver.getresources(query_name, Resolv::DNS::Resource::IN::SRV)

        # Collect all of the records into a Result object, raising an error
Severity: Minor
Found in lib/mongo/srv/resolver.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 11 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(flags, options, main_document, *sequences)
        if flags
          flags.each do |flag|
            unless KNOWN_FLAGS.key?(flag)
              raise ArgumentError, "Unknown flag: #{flag.inspect}"
Severity: Minor
Found in lib/mongo/protocol/msg.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 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def initialize(address, cluster, monitoring, event_listeners, options = {})
      @address = address
      @cluster = cluster
      @monitoring = monitoring
      options = options.dup
Severity: Minor
Found in lib/mongo/server.rb - About 1 hr to fix

    Method check has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def check
            @lock.synchronize do
              if @connection && @connection.pid != Process.pid
                log_warn("Detected PID change - Mongo client should have been reconnected (old pid #{@connection.pid}, new pid #{Process.pid}")
                @connection.disconnect!
    Severity: Minor
    Found in lib/mongo/server/push_monitor.rb - About 1 hr to fix

      Method initial has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def initial(cluster, monitoring, options)
              connect = options[:connect]&.to_sym
              cls = if options[:direct_connection]
                if connect && connect != :direct
                  raise ArgumentError, "Conflicting topology options: direct_connection=true and connect=#{connect}"
      Severity: Minor
      Found in lib/mongo/cluster/topology.rb - About 1 hr to fix

        Method create_and_add_connection has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def create_and_add_connection
                connection = nil
        
                @lock.synchronize do
                  if !closed? && @ready &&
        Severity: Minor
        Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

          Method close has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def close
                @state_change_lock.synchronize do
                  unless connecting? || connected?
                    return nil
                  end
          Severity: Minor
          Found in lib/mongo/cluster.rb - About 1 hr to fix

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

              Method change_doc has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      def change_doc
                        {}.tap do |doc|
                          if @options[:full_document]
                            doc[:fullDocument] = @options[:full_document]
                          end
              Severity: Minor
              Found in lib/mongo/collection/view/change_stream.rb - About 1 hr to fix

                Method delete_many has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        def delete_many(opts = {})
                          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

                  Method initialize has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        def initialize(flags, options, main_document, *sequences)
                          if flags
                            flags.each do |flag|
                              unless KNOWN_FLAGS.key?(flag)
                                raise ArgumentError, "Unknown flag: #{flag.inspect}"
                  Severity: Minor
                  Found in lib/mongo/protocol/msg.rb - About 1 hr to fix

                    Method validate_requests! has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def validate_requests!
                          requests_empty = true
                          @requests.each do |req|
                            requests_empty = false
                            if op = req.keys.first
                    Severity: Minor
                    Found in lib/mongo/bulk_write.rb - About 1 hr to fix

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

                                  write_with_retry(write_concern, context: context) do |connection, txn_num, context|
                                    gte_4_4 = connection.server.description.server_version_gte?('4.4')
                                    if !gte_4_4 && opts[:hint] && write_concern && !write_concern.acknowledged?
                                      raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
                                    end
                      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 84..96

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

                      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

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

                                  write_with_retry(write_concern, context: context) do |connection, txn_num, context|
                                    gte_4_4 = connection.server.description.server_version_gte?('4.4')
                                    if !gte_4_4 && opts[:hint] && write_concern && !write_concern.acknowledged?
                                      raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
                                    end
                      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 192..204

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

                      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 create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          def create(opts = {})
                            # Passing read options to create command causes it to break.
                            # Filter the read options out. Session is also excluded here as it gets
                            # used by the call to with_session and should not be part of the
                            # operation. If it gets passed to the operation it would fail BSON
                      Severity: Minor
                      Found in lib/mongo/collection.rb - About 1 hr to fix

                        Method update_rs_with_primary_from_member has 30 lines of code (exceeds 25 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 1 hr to fix
                          Severity
                          Category
                          Status
                          Source
                          Language