afair/email_address

View on GitHub

Showing 33 of 33 total issues

Method parse_srs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def parse_srs(email, options = {}, &block)
    if email&.match(SRS_FORMAT_REGEX)
      @rewrite_scheme = :srs
      hhh, tt, domain, local, sending_domain = [$1, $2, $3, $4, $5]
      # hhh = tt = sending_domain if false && hhh # Hide warnings for now :-)
Severity: Minor
Found in lib/email_address/rewriter.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 matches? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def matches?(*rules)
      rules.flatten!
      match = local.matches?(rules)
      match ||= host.matches?(rules)
      return match if match
Severity: Minor
Found in lib/email_address/address.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 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

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

    def valid_size?
      return set_error(:local_size_long) if local.size > STANDARD_MAX_SIZE
      if @host&.hosted_service?
        return false if @config[:local_private_size] && !valid_size_checks(@config[:local_private_size])
      elsif @config[:local_size] && !valid_size_checks(@config[:local_size])
Severity: Minor
Found in lib/email_address/local.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

        Avoid too many return statements within this method.
        Open

                return false unless host.valid?
        Severity: Major
        Found in lib/email_address/address.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return false unless local.valid?
          Severity: Major
          Found in lib/email_address/address.rb - About 30 mins to fix

            Method format has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def format(form = @config[:local_format] || :conventional)
                  if @config[:local_format].is_a?(Proc)
                    @config[:local_format].call(self)
                  elsif form == :conventional
                    conventional
            Severity: Minor
            Found in lib/email_address/local.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 error_messages has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.error_messages(hash = {}, locale = "en", *extra)
                  hash = extra.first if extra.first.is_a? Hash
            
                  @errors[locale] ||= {}
                  @errors[locale]["email_address"] ||= {}
            Severity: Minor
            Found in lib/email_address/config.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

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

              class CanonicalEmailAddressType < ActiveRecord::Type::Value
            
                # From user input, setter
                def cast(value)
                  super(Address.new(value).canonical)
            Severity: Minor
            Found in lib/email_address/canonical_email_address_type.rb and 1 other location - About 20 mins to fix
            lib/email_address/email_address_type.rb on lines 33..48

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

            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

              class EmailAddressType < ActiveRecord::Type::Value
            
                # From user input, setter
                def cast(value)
                  super(Address.new(value).normal)
            Severity: Minor
            Found in lib/email_address/email_address_type.rb and 1 other location - About 20 mins to fix
            lib/email_address/canonical_email_address_type.rb on lines 33..48

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

            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

            Severity
            Category
            Status
            Source
            Language