mysociety/alaveteli

View on GitHub
lib/mail_handler.rb

Summary

Maintainability
C
1 day
Test Coverage

Method get_attachment_text_one_file has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  def get_attachment_text_one_file(content_type, body, charset = 'utf-8')
    # NOTE: re. charset: TMail always tries to convert email bodies
    # to UTF8 by default, so normally it should already be that.
    text = ''
    # TODO: - tell all these command line tools to return utf-8
Severity: Minor
Found in lib/mail_handler.rb - About 3 hrs 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_text_one_file has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def get_attachment_text_one_file(content_type, body, charset = 'utf-8')
    # NOTE: re. charset: TMail always tries to convert email bodies
    # to UTF8 by default, so normally it should already be that.
    text = ''
    # TODO: - tell all these command line tools to return utf-8
Severity: Major
Found in lib/mail_handler.rb - About 2 hrs to fix

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

      def get_attachment_text_from_zip_file(zip_file)
        text = ""
        zip_file.each do |entry|
          if entry.file?
            filename = entry.to_s
    Severity: Minor
    Found in lib/mail_handler.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 tnef_attachments has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def tnef_attachments(content)
        attachments = []
        Dir.mktmpdir do |dir|
          IO.popen("tnef -K -C #{dir} 2> /dev/null", "wb") do |f|
            f.write(content)
    Severity: Minor
    Found in lib/mail_handler.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

            rescue
              $stderr.puts("Error processing zip file: #{$ERROR_INFO.inspect}")
    Severity: Major
    Found in lib/mail_handler.rb - About 45 mins to fix

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

        def normalise_content_type(content_type)
          # e.g. http://www.whatdotheyknow.com/request/93/response/250
          if (content_type == 'application/excel') || (content_type == 'application/msexcel') || (content_type == 'application/x-ms-excel')
            content_type = 'application/vnd.ms-excel'
          end
      Severity: Minor
      Found in lib/mail_handler.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