mongodb/mongo-ruby-driver

View on GitHub

Showing 447 of 447 total issues

Method legacy_read_with_retry has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

      def legacy_read_with_retry(session, server_selector, &block)
        attempt = attempt ? attempt + 1 : 1
        yield select_server(cluster, server_selector, session)
      rescue *retryable_exceptions, Error::OperationFailure, Error::PoolError => e
        e.add_notes('legacy retry', "attempt #{attempt}")
Severity: Minor
Found in lib/mongo/retryable/read_worker.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 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def initialize(options)
        Crypt.validate_ffi!
        # Note that this call may eventually, via other method invocations,
        # create additional clients which have to be cleaned up.
        @options = set_default_options(options).freeze
Severity: Major
Found in lib/mongo/crypt/auto_encrypter.rb - About 2 hrs to fix

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

          def ruby_to_smc(opts)
            rv = {}
            URI_OPTION_MAP.each do |uri_key, spec|
              if spec[:group]
                v = opts[spec[:group]]
    Severity: Major
    Found in lib/mongo/uri/options_mapper.rb and 1 other location - About 2 hrs to fix
    lib/mongo/uri/options_mapper.rb on lines 169..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 98.

    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 ruby_to_string(opts)
            rv = {}
            URI_OPTION_MAP.each do |uri_key, spec|
              if spec[:group]
                v = opts[spec[:group]]
    Severity: Major
    Found in lib/mongo/uri/options_mapper.rb and 1 other location - About 2 hrs to fix
    lib/mongo/uri/options_mapper.rb on lines 126..161

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

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

          def stale_primary?
            if updated_desc.max_wire_version >= 17
              if updated_desc.election_id.nil? && !topology.max_election_id.nil?
                return true
              end
      Severity: Minor
      Found in lib/mongo/cluster/sdam_flow.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 TLS related exceptions.
          #
      Severity: Minor
      Found in lib/mongo/socket.rb - About 2 hrs to fix

        Class MapReduce has 23 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

          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

            File readable.rb has 269 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            module Mongo
              class Collection
                class View
            
                  # Defines read related behavior for collection view.
            Severity: Minor
            Found in lib/mongo/collection/view/readable.rb - About 2 hrs to fix

              Method validate_new_options! has 59 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def validate_new_options!(opts)
                    return Options::Redacted.new unless opts
                    if opts[:read_concern]
                      # Raise an error for non user-settable options
                      if opts[:read_concern][:after_cluster_time]
              Severity: Major
              Found in lib/mongo/client.rb - About 2 hrs to fix

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

                    class FSBucket
                      extend Forwardable
                
                      # The default root prefix.
                      #
                Severity: Minor
                Found in lib/mongo/grid/fs_bucket.rb - About 2 hrs to fix

                  Method update_rs_from_primary has 57 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: Major
                  Found in lib/mongo/cluster/sdam_flow.rb - About 2 hrs to fix

                    Method ruby_to_string has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def ruby_to_string(opts)
                            rv = {}
                            URI_OPTION_MAP.each do |uri_key, spec|
                              if spec[:group]
                                v = opts[spec[:group]]
                    Severity: Minor
                    Found in lib/mongo/uri/options_mapper.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 ruby_to_smc has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def ruby_to_smc(opts)
                            rv = {}
                            URI_OPTION_MAP.each do |uri_key, spec|
                              if spec[:group]
                                v = opts[spec[:group]]
                    Severity: Minor
                    Found in lib/mongo/uri/options_mapper.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

                    File cursor.rb has 258 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    module Mongo
                    
                      # Client-side representation of an iterator over a query result set on
                      # the server.
                      #
                    Severity: Minor
                    Found in lib/mongo/cursor.rb - About 2 hrs to fix

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

                        class SdamFlow
                          extend Forwardable
                      
                          def initialize(cluster, previous_desc, updated_desc, awaited: false)
                            @cluster = cluster
                      Severity: Minor
                      Found in lib/mongo/cluster/sdam_flow.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

                        Severity
                        Category
                        Status
                        Source
                        Language