django/django

View on GitHub
django/core/mail/message.py

Summary

Maintainability
D
2 days
Test Coverage

File message.py has 408 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import mimetypes
from email import charset as Charset
from email import encoders as Encoders
from email import generator, message_from_string
from email.errors import HeaderParseError
Severity: Minor
Found in django/core/mail/message.py - About 5 hrs to fix

    Function __init__ has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(
            self,
            subject="",
            body="",
            from_email=None,
    Severity: Minor
    Found in django/core/mail/message.py - 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

    Function attach has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def attach(self, filename=None, content=None, mimetype=None):
            """
            Attach a file with the given filename and content. The filename can
            be omitted and the mimetype is guessed, if not provided.
    
    
    Severity: Minor
    Found in django/core/mail/message.py - About 2 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

    Function sanitize_address has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def sanitize_address(addr, encoding):
        """
        Format a pair of (name, address) or an email address string.
        """
        address = None
    Severity: Minor
    Found in django/core/mail/message.py - 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

    Function __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Major
    Found in django/core/mail/message.py - About 1 hr to fix

      Function __init__ has 10 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(
      Severity: Major
      Found in django/core/mail/message.py - About 1 hr to fix

        Function _create_attachments has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def _create_attachments(self, msg):
                if self.attachments:
                    encoding = self.encoding or settings.DEFAULT_CHARSET
                    body_msg = msg
                    msg = SafeMIMEMultipart(_subtype=self.mixed_subtype, encoding=encoding)
        Severity: Minor
        Found in django/core/mail/message.py - 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

        Function forbid_multi_line_headers has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def forbid_multi_line_headers(name, val, encoding):
            """Forbid multi-line headers to prevent header injection."""
            encoding = encoding or settings.DEFAULT_CHARSET
            val = str(val)  # val may be lazy
            if "\n" in val or "\r" in val:
        Severity: Minor
        Found in django/core/mail/message.py - 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

        Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Minor
        Found in django/core/mail/message.py - About 35 mins to fix

          Function _create_mime_attachment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def _create_mime_attachment(self, content, mimetype):
                  """
                  Convert the content, mimetype pair into a MIME attachment object.
          
                  If the mimetype is message/rfc822, content may be an
          Severity: Minor
          Found in django/core/mail/message.py - 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

          There are no issues that match your filters.

          Category
          Status