mongodb/mongo-ruby-driver

View on GitHub

Showing 336 of 336 total issues

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

    def validate_session_support!
      @state_change_lock.synchronize do
        @sdam_flow_lock.synchronize do
          if topology.data_bearing_servers?
            unless topology.logical_session_timeout
Severity: Minor
Found in lib/mongo/cluster.rb - About 2 hrs 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 19 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(seeds, monitoring, options = Options::Redacted.new)
      if seeds.nil?
        raise ArgumentError, 'Seeds cannot be nil'
      end

Severity: Minor
Found in lib/mongo/cluster.rb - About 2 hrs 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

Class Socket has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Socket
    include ::Socket::Constants

    # Error message for SSL related exceptions.
    #
Severity: Minor
Found in lib/mongo/socket.rb - About 2 hrs to fix

    Class Message has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Message
          include Id
          include Serializers
    
          # The batch size constant.
    Severity: Minor
    Found in lib/mongo/protocol/message.rb - About 2 hrs to fix

      Method validate_options! has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def validate_options!(addresses = nil)
            if options[:write] && options[:write_concern] && options[:write] != options[:write_concern]
              raise ArgumentError, "If :write and :write_concern are both given, they must be identical: #{options.inspect}"
            end
      
      
      Severity: Major
      Found in lib/mongo/client.rb - About 2 hrs to fix

        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 2 hrs to fix
        lib/mongo/collection/view/writable.rb on lines 376..402

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

        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 2 hrs to fix
        lib/mongo/collection/view/writable.rb on lines 265..292

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

        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

        Class Base has 22 methods (exceeds 20 allowed). Consider refactoring.
        Open

            class Base
        
              # Initialize the server selector.
              #
              # @example Initialize the selector.
        Severity: Minor
        Found in lib/mongo/server_selector/base.rb - About 2 hrs to fix

          Method initialize has a Cognitive Complexity of 17 (exceeds 5 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 2 hrs 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 create_context has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

                def create_context(options)
                  OpenSSL::SSL::SSLContext.new.tap do |context|
                    if OpenSSL::SSL.const_defined?(:OP_NO_RENEGOTIATION)
                      context.options = context.options | OpenSSL::SSL::OP_NO_RENEGOTIATION
                    end
          Severity: Minor
          Found in lib/mongo/socket/ssl.rb - About 2 hrs 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

          Class MapReduce has 21 methods (exceeds 20 allowed). Consider refactoring.
          Open

                class MapReduce
                  extend Forwardable
                  include Enumerable
                  include Immutable
                  include Loggable
          Severity: Minor
          Found in lib/mongo/collection/view/map_reduce.rb - About 2 hrs to fix

            File server.rb has 256 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            module Mongo
            
              # Represents a single server on the server side that can be standalone, part of
              # a replica set, or a mongos.
              #
            Severity: Minor
            Found in lib/mongo/server.rb - About 2 hrs to fix

              Method validate_authentication_options! has a Cognitive Complexity of 16 (exceeds 5 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 2 hrs 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 52 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def read_from_socket(length, timeout: nil)
                    # Just in case
                    if length == 0
                      return ''.force_encoding('BINARY')
                    end
              Severity: Major
              Found in lib/mongo/socket.rb - About 2 hrs to fix

                Method set_crypto_hooks has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def set_crypto_hooks
                        @aes_encrypt = Proc.new do |_, key_binary_p, iv_binary_p, input_binary_p,
                          output_binary_p, response_length_p, status_p|
                          do_aes(
                            key_binary_p,
                Severity: Major
                Found in lib/mongo/crypt/handle.rb - About 2 hrs to fix

                  Method run has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def run
                      opts = {
                        region: ENV.fetch('MONGO_RUBY_DRIVER_AWS_AUTH_REGION'),
                        access_key_id: ENV.fetch('MONGO_RUBY_DRIVER_AWS_AUTH_ACCESS_KEY_ID'),
                        secret_access_key: ENV.fetch('MONGO_RUBY_DRIVER_AWS_AUTH_SECRET_ACCESS_KEY'),
                  Severity: Minor
                  Found in .evergreen/lib/ecs_setup.rb - About 1 hr to fix

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

                            def add_error_labels(client, connection, session)
                              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

                      Severity
                      Category
                      Status
                      Source
                      Language