mysociety/alaveteli

View on GitHub
app/models/incoming_message.rb

Summary

Maintainability
D
1 day
Test Coverage

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

require 'rexml/document'
require 'zip'

class IncomingMessage < ApplicationRecord
  include MessageProminence
Severity: Minor
Found in app/models/incoming_message.rb - About 5 hrs to fix

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

    class IncomingMessage < ApplicationRecord
      include MessageProminence
      include CacheAttributesFromRawEmail
      include Taggable
    
    
    Severity: Minor
    Found in app/models/incoming_message.rb - About 4 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 extract_attachments has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def extract_attachments
            _mail = raw_email.mail!
            attachment_attributes = MailHandler.get_attachment_attributes(_mail)
            attachment_attributes = attachment_attributes.inject({}) do |memo, attrs|
              attrs.delete(:original_body)
        Severity: Minor
        Found in app/models/incoming_message.rb - About 1 hr to fix

          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 = 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 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 get_present_file_extensions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_present_file_extensions
              ret = {}
              get_attachments_for_display.each do |attachment|
                ext = AlaveteliFileTypes.mimetype_to_extension(attachment.content_type)
                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

          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 find_all_unknown_mime_types has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.find_all_unknown_mime_types
              IncomingMessage.find_each do |incoming_message|
                incoming_message.get_attachments_for_display.each do |attachment|
                  if attachment.content_type.nil?
                    raise "internal error incoming_message " + incoming_message.id.to_s
          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