mysociety/alaveteli

View on GitHub
app/models/incoming_message.rb

Summary

Maintainability
D
2 days
Test Coverage

Class IncomingMessage has 46 methods (exceeds 20 allowed). Consider refactoring.
Open

class IncomingMessage < ActiveRecord::Base
  include AdminColumn
  include MessageProminence

  MAX_ATTACHMENT_TEXT_CLIPPED = 1000000 # 1Mb ish
Severity: Minor
Found in app/models/incoming_message.rb - About 6 hrs to fix

    File incoming_message.rb has 427 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'rexml/document'
    require 'zip'
    require 'iconv' unless String.method_defined?(:encode)
    
    class IncomingMessage < ActiveRecord::Base
    Severity: Minor
    Found in app/models/incoming_message.rb - About 6 hrs to fix

      Method remove_quoted_sections has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.remove_quoted_sections(text, replacement = "FOLDED_QUOTED_SECTION")
          text = text.dup
          replacement = "\n" + replacement + "\n"
      
          # First do this peculiar form of quoting, as the > single line quoting
      Severity: Minor
      Found in app/models/incoming_message.rb - About 1 hr to fix

        Method get_body_for_html_display has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def get_body_for_html_display(collapse_quoted_sections = true)
            # Find the body text and remove emails for privacy/anti-spam reasons
            text = get_main_body_text_unfolded
            folded_quoted_text = get_main_body_text_folded
        
        
        Severity: Minor
        Found in app/models/incoming_message.rb - About 1 hr to fix

          Method _calculate_valid_to_reply_to has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def _calculate_valid_to_reply_to
              email = from_email.try(:downcase)
          
              # check validity of email
              return false if email.nil? || !MySociety::Validate.is_valid_email(email)
          Severity: Minor
          Found in app/models/incoming_message.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 find_all_unknown_mime_types has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.find_all_unknown_mime_types
              IncomingMessage.find_each do |incoming_message|
                for attachment in incoming_message.get_attachments_for_display
                  raise "internal error incoming_message " + incoming_message.id.to_s if attachment.content_type.nil?
                  if AlaveteliFileTypes.mimetype_to_extension(attachment.content_type).nil?
          Severity: Minor
          Found in app/models/incoming_message.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 get_main_body_text_part has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_main_body_text_part(leaves=[])
              leaves = self.foi_attachments if leaves.empty?
          
              # Find first part which is text/plain or text/html
              # (We have to include HTML, as increasingly there are mail clients that
          Severity: Minor
          Found in app/models/incoming_message.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 parse_raw_email! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def parse_raw_email!(force = nil)
              # The following fields may be absent; we treat them as cached
              # values in case we want to regenerate them (due to mail
              # parsing bugs, etc).
              if self.raw_email.nil?
          Severity: Minor
          Found in app/models/incoming_message.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

          Avoid too many return statements within this method.
          Wontfix

              return false if MailHandler.empty_return_path?(mail)
          Severity: Major
          Found in app/models/incoming_message.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Wontfix

                return false if MailHandler.get_auto_submitted(mail)
            Severity: Major
            Found in app/models/incoming_message.rb - About 30 mins to fix

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

                def self.get_attachment_by_url_part_number_and_filename(attachments, found_url_part_number, display_filename)
                  attachment_by_part_number = attachments.detect { |a| a.url_part_number == found_url_part_number }
                  if attachment_by_part_number && attachment_by_part_number.display_filename == display_filename
                    # Then the filename matches, which is fine:
                    attachment_by_part_number
              Severity: Minor
              Found in app/models/incoming_message.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 get_body_for_html_display has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def get_body_for_html_display(collapse_quoted_sections = true)
                  # Find the body text and remove emails for privacy/anti-spam reasons
                  text = get_main_body_text_unfolded
                  folded_quoted_text = get_main_body_text_folded
              
              
              Severity: Minor
              Found in app/models/incoming_message.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 _convert_part_body_to_text has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def _convert_part_body_to_text(part)
                  if part.nil?
                    text = "[ Email has no body, please see attachments ]"
                  else
                    # whatever kind of attachment it is, get the UTF-8 encoded text
              Severity: Minor
              Found in app/models/incoming_message.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 get_present_file_extensions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def get_present_file_extensions
                  ret = {}
                  for attachment in self.get_attachments_for_display
                    ext = AlaveteliFileTypes.mimetype_to_extension(attachment.content_type)
                    ext = File.extname(attachment.filename).gsub(/^[.]/, "") if ext.nil? && !attachment.filename.nil?
              Severity: Minor
              Found in app/models/incoming_message.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