afair/email_address

View on GitHub
lib/email_address/host.rb

Summary

Maintainability
D
2 days
Test Coverage

Class Host has 38 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Host
    attr_reader :host_name
    attr_accessor :dns_name, :domain_name, :registration_name,
      :tld, :tld2, :subdomains, :ip_address, :config, :provider,
      :comment, :error_message, :reason, :locale
Severity: Minor
Found in lib/email_address/host.rb - About 5 hrs to fix

    File host.rb has 344 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require "simpleidn"
    require "resolv"
    
    module EmailAddress
      ##############################################################################
    Severity: Minor
    Found in lib/email_address/host.rb - About 4 hrs to fix

      Method matches? has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def matches?(rules)
            rules = Array(rules)
            return false if rules.empty?
            rules.each do |rule|
              return rule if rule == domain_name || rule == dns_name
      Severity: Minor
      Found in lib/email_address/host.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 valid_format? has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def valid_format?
            if host_name =~ CANONICAL_HOST_REGEX && to_s.size <= MAX_HOST_LENGTH
              if localhost?
                return @config[:host_local] ? true : set_error(:domain_no_localhost)
              end
      Severity: Minor
      Found in lib/email_address/host.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 valid? has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def valid?(rules = {})
            host_validation = rules[:host_validation] || @config[:host_validation] || :mx
            dns_lookup = rules[:dns_lookup] || @config[:dns_lookup] || host_validation
            self.error_message = nil
            if host_name && !host_name.empty? && !@config[:host_size].include?(host_name.size)
      Severity: Minor
      Found in lib/email_address/host.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 valid_ip? has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def valid_ip?
            if !@config[:host_allow_ip]
              bool = set_error(:ip_address_forbidden)
            elsif ip_address.include?(":")
              bool = ip_address.match(Resolv::IPv6::Regex) ? true : set_error(:ipv6_address_invalid)
      Severity: Minor
      Found in lib/email_address/host.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 host_name= has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def host_name=(name)
            name = fully_qualified_domain_name(name.downcase)
            @host_name = name
            if @config[:host_remove_spaces]
              @host_name = @host_name.delete(" ")
      Severity: Minor
      Found in lib/email_address/host.rb - About 1 hr to fix

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

            def txt(alternate_host = nil)
              return nil unless dns_enabled?
              Resolv::DNS.open do |dns|
                dns.timeouts = @config[:dns_timeout] if @config[:dns_timeout]
                records = begin
        Severity: Minor
        Found in lib/email_address/host.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 valid_mx? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def valid_mx?
              return true unless dns_enabled?
              if exchangers.nil?
                set_error(:domain_unknown)
              elsif exchangers.mx_ips.size > 0
        Severity: Minor
        Found in lib/email_address/host.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 host_name= has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def host_name=(name)
              name = fully_qualified_domain_name(name.downcase)
              @host_name = name
              if @config[:host_remove_spaces]
                @host_name = @host_name.delete(" ")
        Severity: Minor
        Found in lib/email_address/host.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 fully_qualified_domain_name has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def fully_qualified_domain_name(host_part)
              dn = @config[:address_fqdn_domain]
              if !dn
                if (host_part.nil? || host_part <= " ") && @config[:host_local] && @config[:host_auto_append]
                  "localhost"
        Severity: Minor
        Found in lib/email_address/host.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 find_provider has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def find_provider # :nodoc:
              return provider if provider
        
              Config.providers.each do |provider, config|
                if config[:host_match] && matches?(config[:host_match])
        Severity: Minor
        Found in lib/email_address/host.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

        Avoid too many return statements within this method.
        Open

                return rule if self.provider && provider_matches?(rule)
        Severity: Major
        Found in lib/email_address/host.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return rule if ip_matches?(rule)
          Severity: Major
          Found in lib/email_address/host.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return rule if domain_matches?(rule)
            Severity: Major
            Found in lib/email_address/host.rb - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status