django/django

View on GitHub
django/http/response.py

Summary

Maintainability
D
3 days
Test Coverage

File response.py has 554 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import datetime
import io
import json
import mimetypes
import os
Severity: Major
Found in django/http/response.py - About 1 day to fix

    Function set_cookie has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def set_cookie(
            self,
            key,
            value="",
            max_age=None,
    Severity: Minor
    Found in django/http/response.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

    HttpResponseBase has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class HttpResponseBase:
        """
        An HTTP response base class with dictionary-accessed headers.
    
        This class doesn't handle content. It should not be used directly.
    Severity: Minor
    Found in django/http/response.py - About 3 hrs to fix

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

          def set_headers(self, filelike):
              """
              Set some common response headers (Content-Length, Content-Type, and
              Content-Disposition) based on the `filelike` response content.
              """
      Severity: Minor
      Found in django/http/response.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 _convert_to_charset has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def _convert_to_charset(self, value, charset, mime_encode=False):
              """
              Convert headers key/value to ascii/latin-1 native strings.
              `charset` must be 'ascii' or 'latin-1'. If `mime_encode` is True and
              `value` can't be represented in the given charset, apply MIME-encoding.
      Severity: Minor
      Found in django/http/response.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 set_cookie has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def set_cookie(
      Severity: Major
      Found in django/http/response.py - About 1 hr to fix

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

            def __init__(
                self, content_type=None, status=None, reason=None, charset=None, headers=None
            ):
                self.headers = ResponseHeaders(headers)
                self._charset = charset
        Severity: Minor
        Found in django/http/response.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

        Consider simplifying this complex logical expression.
        Open

                    if (isinstance(value, bytes) and (b"\n" in value or b"\r" in value)) or (
                        isinstance(value, str) and ("\n" in value or "\r" in value)
                    ):
                        raise BadHeaderError(
                            f"Header values can't contain newlines (got {value!r})"
        Severity: Major
        Found in django/http/response.py - About 40 mins to fix

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

              def __init__(
          Severity: Minor
          Found in django/http/response.py - About 35 mins to fix

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

                def __init__(
            Severity: Minor
            Found in django/http/response.py - About 35 mins to fix

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

                  def content(self, value):
                      # Consume iterators upon assignment to allow repeated iteration.
                      if hasattr(value, "__iter__") and not isinstance(
                          value, (bytes, memoryview, str)
                      ):
              Severity: Minor
              Found in django/http/response.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