mongodb/mongo-ruby-driver

View on GitHub
lib/mongo/server/connection_pool.rb

Summary

Maintainability
F
3 days
Test Coverage

File connection_pool.rb has 414 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'mongo/server/connection_pool/populator'

module Mongo
  class Server

Severity: Minor
Found in lib/mongo/server/connection_pool.rb - About 5 hrs to fix

    Method check_out has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

          def check_out
            check_invariants
    
            publish_cmap_event(
              Monitoring::Event::Cmap::ConnectionCheckOutStarted.new(@server.address)
    Severity: Minor
    Found in lib/mongo/server/connection_pool.rb - About 5 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 check_out has 99 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

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

      Class ConnectionPool has 25 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class ConnectionPool
            include Loggable
            include Monitoring::Publishable
            extend Forwardable
      
      
      Severity: Minor
      Found in lib/mongo/server/connection_pool.rb - About 2 hrs to fix

        Method check_in has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

              def check_in(connection)
                check_invariants
        
                @lock.synchronize do
                  unless connection.connection_pool == self
        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 initialize has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def initialize(server, options = {})
                unless server.is_a?(Server)
                  raise ArgumentError, 'First argument must be a Server instance'
                end
                options = options.dup
        Severity: Minor
        Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

          Method initialize has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

                def initialize(server, options = {})
                  unless server.is_a?(Server)
                    raise ArgumentError, 'First argument must be a Server instance'
                  end
                  options = options.dup
          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_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 check_in has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def check_in(connection)
                  check_invariants
          
                  @lock.synchronize do
                    unless connection.connection_pool == self
          Severity: Minor
          Found in lib/mongo/server/connection_pool.rb - About 1 hr to fix

            Method close has a Cognitive Complexity of 9 (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 55 mins 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 check_invariants has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                  def check_invariants
                    return unless Lint.enabled?
            
                    # Server summary calls pool summary which requires pool lock -> deadlock.
                    # Obtain the server summary ahead of time.
            Severity: Minor
            Found in lib/mongo/server/connection_pool.rb - About 45 mins 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 clear has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                  def clear(options = nil)
                    raise_if_closed!
            
                    check_invariants
            
            
            Severity: Minor
            Found in lib/mongo/server/connection_pool.rb - About 45 mins 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

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

                    if options[:wait_timeout] && options[:wait_queue_timeout] && options[:wait_timeout] != options[:wait_queue_timeout]
                      raise ArgumentError, "Wait timeout #{options[:wait_timeout]} is not identical to wait queue timeout #{options[:wait_queue_timeout]}"
                    end
            Severity: Minor
            Found in lib/mongo/server/connection_pool.rb and 3 other locations - About 20 mins to fix
            lib/mongo/server/connection_pool.rb on lines 85..87
            lib/mongo/server/connection_pool.rb on lines 88..90
            lib/mongo/server/connection_pool.rb on lines 98..102

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

            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 4 locations. Consider refactoring.
            Open

                    if options[:max_size] && options[:max_pool_size] && options[:max_size] != options[:max_pool_size]
                      raise ArgumentError, "Max size #{options[:max_size]} is not identical to max pool size #{options[:max_pool_size]}"
                    end
            Severity: Minor
            Found in lib/mongo/server/connection_pool.rb and 3 other locations - About 20 mins to fix
            lib/mongo/server/connection_pool.rb on lines 85..87
            lib/mongo/server/connection_pool.rb on lines 91..93
            lib/mongo/server/connection_pool.rb on lines 98..102

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

            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 4 locations. Consider refactoring.
            Open

                    if options[:min_size] && options[:min_pool_size] && options[:min_size] != options[:min_pool_size]
                      raise ArgumentError, "Min size #{options[:min_size]} is not identical to min pool size #{options[:min_pool_size]}"
                    end
            Severity: Minor
            Found in lib/mongo/server/connection_pool.rb and 3 other locations - About 20 mins to fix
            lib/mongo/server/connection_pool.rb on lines 88..90
            lib/mongo/server/connection_pool.rb on lines 91..93
            lib/mongo/server/connection_pool.rb on lines 98..102

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

            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 4 locations. Consider refactoring.
            Open

                    if options[:min_size] && options[:max_size] &&
                      options[:min_size] > options[:max_size]
                    then
                      raise ArgumentError, "Cannot have min size #{options[:min_size]} exceed max size #{options[:max_size]}"
                    end
            Severity: Minor
            Found in lib/mongo/server/connection_pool.rb and 3 other locations - About 20 mins to fix
            lib/mongo/server/connection_pool.rb on lines 85..87
            lib/mongo/server/connection_pool.rb on lines 88..90
            lib/mongo/server/connection_pool.rb on lines 91..93

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

            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

            There are no issues that match your filters.

            Category
            Status