loomio/loomio

View on GitHub
app/services/received_email_service.rb

Summary

Maintainability
D
1 day
Test Coverage

Method route has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
Open

  def self.route(email)
    return nil unless email.route_address
    return nil if email.released
    return nil if email.sender_hostname.downcase == ENV['REPLY_HOSTNAME'].downcase
    return nil if email.sender_hostname.downcase == ENV['SMTP_DOMAIN'].downcase
Severity: Minor
Found in app/services/received_email_service.rb - About 1 day 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 route has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.route(email)
    return nil unless email.route_address
    return nil if email.released
    return nil if email.sender_hostname.downcase == ENV['REPLY_HOSTNAME'].downcase
    return nil if email.sender_hostname.downcase == ENV['SMTP_DOMAIN'].downcase
Severity: Minor
Found in app/services/received_email_service.rb - About 1 hr to fix

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

      def self.actor_from_email_and_group(email, group)
        if actor = (email.dkim_valid || email.spf_valid) && User.find_by(email: email.sender_email)
          return actor if group.members.exists?(actor.id)
        end
    
    
    Severity: Minor
    Found in app/services/received_email_service.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

    Avoid deeply nested control flow statements.
    Open

                if discussion = DiscussionService.create(discussion: Discussion.new(discussion_params(email)), actor: actor)
                  email.update(released: true) if discussion.persisted?
                end
    Severity: Major
    Found in app/services/received_email_service.rb - About 45 mins to fix

      Avoid too many return statements within this method.
      Open

              return
      Severity: Major
      Found in app/services/received_email_service.rb - About 30 mins to fix

        There are no issues that match your filters.

        Category
        Status