mongodb/mongo-ruby-driver

View on GitHub

Showing 398 of 398 total issues

Class OptionsMapper has 37 methods (exceeds 20 allowed). Consider refactoring.
Open

    class OptionsMapper

      include Loggable

      # Instantates the options mapper.
Severity: Minor
Found in lib/mongo/uri/options_mapper.rb - About 4 hrs to fix

    Class Collection has 34 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Collection
        extend Forwardable
        include Retryable
    
        # The capped option.
    Severity: Minor
    Found in lib/mongo/collection.rb - About 4 hrs to fix

      Class View has 34 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class View
      
            # Defines read related behavior for collection view.
            #
            # @since 2.0.0
      Severity: Minor
      Found in lib/mongo/collection/view/readable.rb - About 4 hrs to fix

        Method check_out has 107 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def check_out(service_id: nil)
                check_invariants
        
                publish_cmap_event(
                  Monitoring::Event::Cmap::ConnectionCheckOutStarted.new(@server.address)
        Severity: Major
        Found in lib/mongo/server/connection_pool.rb - About 4 hrs to fix

          Method initialize has a Cognitive Complexity of 29 (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 4 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 do_execute has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
          Open

                def do_execute(connection, context, options = {})
                  unpin_maybe(session) do
                    add_error_labels(connection, context) do
                      add_server_diagnostics(connection) do
                        get_result(connection, context, options).tap do |result|
          Severity: Minor
          Found in lib/mongo/operation/shared/executable.rb - About 4 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 options_mapper.rb has 335 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          module Mongo
            class URI
          
              # Performs mapping between URI options and Ruby options.
              #
          Severity: Minor
          Found in lib/mongo/uri/options_mapper.rb - About 4 hrs to fix

            Method server_description_changed has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
            Open

                def server_description_changed
                  @previous_server_descriptions = servers_list.map do |server|
                    [server.address.to_s, server.description]
                  end
            
            
            Severity: Minor
            Found in lib/mongo/cluster/sdam_flow.rb - About 3 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 27 (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 3 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 Cluster has 31 methods (exceeds 20 allowed). Consider refactoring.
            Open

              class Cluster
                extend Forwardable
                include Monitoring::Publishable
                include Event::Subscriber
                include Loggable
            Severity: Minor
            Found in lib/mongo/cluster.rb - About 3 hrs to fix

              Method estimated_document_count has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
              Open

                      def estimated_document_count(opts = {})
                        unless view.filter.empty?
                          raise ArgumentError, "Cannot call estimated_document_count when querying with a filter"
                        end
              
              
              Severity: Minor
              Found in lib/mongo/collection/view/readable.rb - About 3 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 Binding has 30 methods (exceeds 20 allowed). Consider refactoring.
              Open

                  class Binding
                    extend FFI::Library
              
                    begin
                      ffi_lib ENV['LIBMONGOCRYPT_PATH']
              Severity: Minor
              Found in lib/mongo/crypt/binding.rb - About 3 hrs to fix

                Method initialize has 91 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: Major
                Found in lib/mongo/client.rb - About 3 hrs to fix

                  Method parse! has a Cognitive Complexity of 25 (exceeds 5 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 3 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 verify_one_responder has 89 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        def verify_one_responder(uri)
                          original_uri = uri
                          redirect_count = 0
                          http_response = nil
                          loop do
                  Severity: Major
                  Found in lib/mongo/socket/ocsp_verifier.rb - About 3 hrs to fix

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

                            def replace_one(replacement, opts = {})
                              with_session(opts) do |session|
                                write_concern = if opts[:write_concern]
                                  WriteConcern.get(opts[:write_concern])
                                else
                    Severity: Major
                    Found in lib/mongo/collection/view/writable.rb and 1 other location - About 3 hrs to fix
                    lib/mongo/collection/view/writable.rb on lines 437..470

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

                    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 = {})
                              with_session(opts) do |session|
                                write_concern = if opts[:write_concern]
                                  WriteConcern.get(opts[:write_concern])
                                else
                    Severity: Major
                    Found in lib/mongo/collection/view/writable.rb and 1 other location - About 3 hrs to fix
                    lib/mongo/collection/view/writable.rb on lines 313..346

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

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

                          def select_server(cluster, ping = nil, session = nil)
                            if cluster.topology.is_a?(Cluster::Topology::LoadBalanced)
                              return cluster.servers.first
                            end
                    
                    
                    Severity: Major
                    Found in lib/mongo/server_selector/base.rb - About 3 hrs to fix

                      File base.rb has 309 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      module Mongo
                      
                        module ServerSelector
                      
                          class Base
                      Severity: Minor
                      Found in lib/mongo/server_selector/base.rb - About 3 hrs to fix

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

                            def initialize(seeds, monitoring, options = Options::Redacted.new)
                              if seeds.nil?
                                raise ArgumentError, 'Seeds cannot be nil'
                              end
                        
                        
                        Severity: Major
                        Found in lib/mongo/cluster.rb - About 3 hrs to fix
                          Severity
                          Category
                          Status
                          Source
                          Language