ari/jobsworth

View on GitHub
app/models/mailman.rb

Summary

Maintainability
D
1 day
Test Coverage

File mailman.rb has 259 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Mailman < ActionMailer::Base
  # The marker in the email body that shows where the new content ends
  BODY_SPLIT = 'o------ please reply above this line ------o'

  def self.receive(mail)
Severity: Minor
Found in app/models/mailman.rb - About 2 hrs to fix

    Method receive has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def receive(email)
        # create wrapper email object
        wrapper = Mailman::Email.new(email)
    
        logger.tagged('EMAIL TRACKING') { logger.info 'receive wrapper' }
    Severity: Minor
    Found in app/models/mailman.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 receive has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def receive(email)
        # create wrapper email object
        wrapper = Mailman::Email.new(email)
    
        logger.tagged('EMAIL TRACKING') { logger.info 'receive wrapper' }
    Severity: Minor
    Found in app/models/mailman.rb - About 1 hr to fix

      Method get_body has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.get_body(email)
            body = nil
            if email.multipart?
              email.parts.each do |m|
                next if body
      Severity: Minor
      Found in app/models/mailman.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 add_email_to_task has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def add_email_to_task(wrapper, task)
          files = save_attachments(wrapper, task)
      
          # if it's from unknown, add email to task email_addresses
          unless wrapper.user or task.email_addresses.include? wrapper.email_address
      Severity: Minor
      Found in app/models/mailman.rb - About 1 hr to fix

        Method initialize has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize(email)
              @from = email.from.first
              @body = Email.get_body(email)
              @subject = email.subject
              @email = email
        Severity: Minor
        Found in app/models/mailman.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 create_task_from_email has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def create_task_from_email(wrapper, project)
            task = TaskRecord.new(
                :name => wrapper.subject,
                :project => project,
                :company => project.company,
        Severity: Minor
        Found in app/models/mailman.rb - About 1 hr to fix

          Method attach_customers_to_task has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def attach_customers_to_task(task)
              task.users.each do |user|
                if user.customer and !task.customers.include?(user.customer)
                  task.customers << user.customer
                  user.customer.users.auto_add.each do |u|
          Severity: Minor
          Found in app/models/mailman.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 attach_user_or_email_address has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def attach_user_or_email_address(email, task, users)
              user = task.project.company.users.active.by_email(email.strip).first
              if user
                users << user
              elsif !task.company.suppressed_emails.include?(email.strip)
          Severity: Minor
          Found in app/models/mailman.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 target_for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def target_for(email, company)
              logger.tagged('EMAIL TRACKING') { logger.info 'target_for email' }
              logger.tagged('EMAIL TRACKING') { logger.info email }
          
              logger.tagged('EMAIL TRACKING') { logger.info 'target_for company' }
          Severity: Minor
          Found in app/models/mailman.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 clean_body has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.clean_body(body)
                new_body_end = body.to_s.index(Mailman::BODY_SPLIT) || body.to_s.length
                body = body.to_s[0, new_body_end].strip
          
                lines = body.to_s.split("\n")
          Severity: Minor
          Found in app/models/mailman.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