pboling/sanitize_email

View on GitHub

Showing 12 of 12 total issues

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

    %i[from to cc bcc subject reply_to].each do |attribute|
      RSpec::Matchers.define("match_#{attribute}") do |matcher|
        match do |actual|
          @actual = actual.send(attribute)
          @actual = @actual.join(", ") if @actual.respond_to?(:join)
Severity: Major
Found in lib/sanitize_email/rspec_matchers.rb and 2 other locations - About 45 mins to fix
lib/sanitize_email/rspec_matchers.rb on lines 14..19
lib/sanitize_email/rspec_matchers.rb on lines 34..39

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

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

    %i[from to cc bcc subject reply_to].each do |attribute|
      RSpec::Matchers.define("be_#{attribute}") do |matcher|
        match do |actual|
          @actual = actual.send(attribute)
          @actual = @actual.join(", ") if @actual.respond_to?(:join)
Severity: Major
Found in lib/sanitize_email/rspec_matchers.rb and 2 other locations - About 45 mins to fix
lib/sanitize_email/rspec_matchers.rb on lines 14..19
lib/sanitize_email/rspec_matchers.rb on lines 24..29

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

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

    %i[from to cc bcc subject reply_to].each do |attribute|
      RSpec::Matchers.define("have_#{attribute}") do |matcher|
        match do |actual|
          @actual = actual.send(attribute)
          @actual = @actual.join(", ") if @actual.respond_to?(:join)
Severity: Major
Found in lib/sanitize_email/rspec_matchers.rb and 2 other locations - About 45 mins to fix
lib/sanitize_email/rspec_matchers.rb on lines 24..29
lib/sanitize_email/rspec_matchers.rb on lines 34..39

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

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

    RSpec::Matchers.define("have_sanitized_cc_header") do |matcher|
      def get_sanitized_cc_header(email_message)
        sanitized_cc_header = email_message.header["X-Sanitize-Email-Cc"]
        return sanitized_cc_header.value if sanitized_cc_header.is_a?(Mail::Field)

Severity: Minor
Found in lib/sanitize_email/rspec_matchers.rb and 1 other location - About 35 mins to fix
lib/sanitize_email/rspec_matchers.rb on lines 55..64

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

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 address_list_filter has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def address_list_filter(list_type, address)
      # TODO: How does this handle email addresses with user names like "Foo Example <foo@example.org>"
      has_address = send(list_type).include?(address)
      case list_type
      when :good_list then
Severity: Minor
Found in lib/sanitize_email/overridden_addresses.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 7 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(message, **args)
      # Not using extract_options! because non-rails compatibility is a goal
      args = SanitizeEmail::Config.to_init.merge(args)
      @sanitized_to = args[:sanitized_to]
      @sanitized_cc = args[:sanitized_cc]
Severity: Minor
Found in lib/sanitize_email/overridden_addresses.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

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

    RSpec::Matchers.define("have_sanitized_to_header") do |matcher|
      def get_sanitized_to_header(email_message)
        sanitized_to_header = email_message.header["X-Sanitize-Email-To"]
        return sanitized_to_header.value if sanitized_to_header.is_a?(Mail::Field)

Severity: Minor
Found in lib/sanitize_email/rspec_matchers.rb and 1 other location - About 35 mins to fix
lib/sanitize_email/rspec_matchers.rb on lines 79..88

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

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

    RSpec::Matchers.define("have_cc_username") do |matcher|
      def get_cc_usernames(email_message)
        to_addrs = email_message[:cc].addrs
        to_addrs.map(&:name)
      end
Severity: Minor
Found in lib/sanitize_email/rspec_matchers.rb and 2 other locations - About 25 mins to fix
lib/sanitize_email/rspec_matchers.rb on lines 44..51
lib/sanitize_email/rspec_matchers.rb on lines 92..99

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

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

    RSpec::Matchers.define("have_bcc_username") do |matcher|
      def get_bcc_usernames(email_message)
        to_addrs = email_message[:bcc].addrs
        to_addrs.map(&:name)
      end
Severity: Minor
Found in lib/sanitize_email/rspec_matchers.rb and 2 other locations - About 25 mins to fix
lib/sanitize_email/rspec_matchers.rb on lines 44..51
lib/sanitize_email/rspec_matchers.rb on lines 68..75

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

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

    RSpec::Matchers.define("have_to_username") do |matcher|
      def get_to_usernames(email_message)
        to_addrs = email_message[:to].addrs
        to_addrs.map(&:name)
      end
Severity: Minor
Found in lib/sanitize_email/rspec_matchers.rb and 2 other locations - About 25 mins to fix
lib/sanitize_email/rspec_matchers.rb on lines 68..75
lib/sanitize_email/rspec_matchers.rb on lines 92..99

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

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 override_email has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def override_email(type, actual_addresses)
      # Normalized to an arrays
      # puts "override_email 1: #{type} - #{actual_addresses}"
      real_addresses = Array(actual_addresses)

Severity: Minor
Found in lib/sanitize_email/overridden_addresses.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 sanitize_engaged? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def sanitize_engaged?(message)
        # Don't sanitize the message if it will not be delivered
        return false unless message.perform_deliveries

        # Has it been forced via the force_sanitize mattr?
Severity: Minor
Found in lib/sanitize_email/bleach.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

Severity
Category
Status
Source
Language