mongodb/mongo-ruby-driver

View on GitHub
lib/mongo/uri.rb

Summary

Maintainability
F
3 days
Test Coverage

File uri.rb has 445 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Mongo

  # The URI class provides a way for users to parse the MongoDB uri as
  # defined in the connection string format spec.
  #
Severity: Minor
Found in lib/mongo/uri.rb - About 6 hrs to fix

    Class URI has 39 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class URI
        include Loggable
        include Address::Validator
    
        # The uri parser object options.
    Severity: Minor
    Found in lib/mongo/uri.rb - About 5 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 validate_uri_options! has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate_uri_options!
            # The URI options spec requires that we raise an error if there are conflicting values of
            # 'tls' and 'ssl'. In order to fulfill this, we parse the values of each instance into an
            # array; assuming all values in the array are the same, we replace the array with that value.
            unless uri_options[:ssl].nil? || uri_options[:ssl].empty?
      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 parse! has 39 lines of code (exceeds 25 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 1 hr to fix

        Method validate_uri_options! has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def validate_uri_options!
              # The URI options spec requires that we raise an error if there are conflicting values of
              # 'tls' and 'ssl'. In order to fulfill this, we parse the values of each instance into an
              # array; assuming all values in the array are the same, we replace the array with that value.
              unless uri_options[:ssl].nil? || uri_options[:ssl].empty?
        Severity: Minor
        Found in lib/mongo/uri.rb - About 1 hr to fix

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

              def parse_password!(string)
                if (string && pwd = string.partition(AUTH_USER_PWD_DELIM)[2])
                  if pwd.length > 0
                    raise_invalid_error!(UNESCAPED_USER_PWD) if pwd =~ UNSAFE
                    pwd_decoded = decode(pwd)
          Severity: Minor
          Found in lib/mongo/uri.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 parse_uri_options! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_uri_options!(string)
                uri_options = {}
                unless string
                  return uri_options
                end
          Severity: Minor
          Found in lib/mongo/uri.rb - About 35 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 max_staleness has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def max_staleness(value)
                if /\A-?\d+\z/ =~ value
                  int = value.to_i
          
                  if int == -1
          Severity: Minor
          Found in lib/mongo/uri.rb - About 35 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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def initialize(string, options = {})
                unless string
                  raise Error::InvalidURI.new(string, 'URI must be a string, not nil.')
                end
                if string.empty?
          Severity: Minor
          Found in lib/mongo/uri.rb - About 25 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 parse_user! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_user!(string)
                if (string && user = string.partition(AUTH_USER_PWD_DELIM)[0])
                  raise_invalid_error!(UNESCAPED_USER_PWD) if user =~ UNSAFE
                  user_decoded = decode(user)
                  if user_decoded =~ PERCENT_CHAR && encode(user_decoded) != user
          Severity: Minor
          Found in lib/mongo/uri.rb - About 25 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

          There are no issues that match your filters.

          Category
          Status