mysociety/alaveteli

View on GitHub
lib/mail_handler/backends/mail_backend.rb

Summary

Maintainability
C
1 day
Test Coverage

File mail_backend.rb has 300 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'mail'
require 'mapi/msg'
require 'mapi/convert'

module Mail
Severity: Minor
Found in lib/mail_handler/backends/mail_backend.rb - About 3 hrs to fix

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

          def expand_and_normalize_parts(part, parent_mail)
            if part.multipart?
              Mail::PartsList.new(part.parts.each{ |sub_part| expand_and_normalize_parts(sub_part, parent_mail) })
            else
              part_filename = get_part_file_name(part)
    Severity: Minor
    Found in lib/mail_handler/backends/mail_backend.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 decode_attached_part has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

          def decode_attached_part(part, parent_mail)
            if get_content_type(part) == 'message/rfc822'
              # An email attached as text
              part.rfc822_attachment = mail_from_raw_email(part.body)
              if part.rfc822_attachment.nil?
    Severity: Minor
    Found in lib/mail_handler/backends/mail_backend.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 _get_attachment_leaves_recursive has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def _get_attachment_leaves_recursive(part, within_rfc822_attachment, parent_mail)
            leaves_found = []
            if part.multipart?
              if part.parts.size == 0
                # This is typically caused by a missing final
    Severity: Minor
    Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

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

            def _get_attachment_leaves_recursive(part, within_rfc822_attachment, parent_mail)
              leaves_found = []
              if part.multipart?
                if part.parts.size == 0
                  # This is typically caused by a missing final
      Severity: Minor
      Found in lib/mail_handler/backends/mail_backend.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 expand_and_normalize_parts has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def expand_and_normalize_parts(part, parent_mail)
              if part.multipart?
                Mail::PartsList.new(part.parts.each{ |sub_part| expand_and_normalize_parts(sub_part, parent_mail) })
              else
                part_filename = get_part_file_name(part)
      Severity: Minor
      Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

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

              def extract_attached_message_headers(leaf)
                body = get_part_body(leaf)
                # Test to see if we are in the first part of the attached
                # RFC822 message and it is text, if so add headers.
                if leaf.within_rfc822_attachment == leaf && get_content_type(leaf) == 'text/plain'
        Severity: Minor
        Found in lib/mail_handler/backends/mail_backend.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 get_from_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def get_from_name(mail)
                first_from = first_from(mail)
                if first_from
                  if first_from.is_a?(String)
                    return nil
        Severity: Minor
        Found in lib/mail_handler/backends/mail_backend.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