django/django

View on GitHub
django/utils/cache.py

Summary

Maintainability
D
1 day
Test Coverage

Function patch_cache_control has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

def patch_cache_control(response, **kwargs):
    """
    Patch the Cache-Control header by adding all keyword arguments to it.
    The transformation is as follows:

Severity: Minor
Found in django/utils/cache.py - About 4 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

File cache.py has 301 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
This module contains helper functions for controlling caching. It does so by
managing the "Vary" header of responses. It includes functions to patch the
header of response objects directly and decorators that change functions to do
that header-patching themselves.
Severity: Minor
Found in django/utils/cache.py - About 3 hrs to fix

    Function get_conditional_response has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_conditional_response(request, etag=None, last_modified=None, response=None):
        # Only return conditional responses on successful requests.
        if response and not (200 <= response.status_code < 300):
            return response
    
    
    Severity: Minor
    Found in django/utils/cache.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 learn_cache_key has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def learn_cache_key(request, response, cache_timeout=None, key_prefix=None, cache=None):
        """
        Learn what headers to take into account for some request URL from the
        response object. Store those headers in a global URL registry so that
        later access to that URL will know what headers to take into account
    Severity: Minor
    Found in django/utils/cache.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 learn_cache_key has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def learn_cache_key(request, response, cache_timeout=None, key_prefix=None, cache=None):
    Severity: Minor
    Found in django/utils/cache.py - About 35 mins to fix

      Avoid too many return statements within this function.
      Open

                  return _precondition_failed(request)
      Severity: Major
      Found in django/utils/cache.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return response
        Severity: Major
        Found in django/utils/cache.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return _not_modified(request, response)
          Severity: Major
          Found in django/utils/cache.py - About 30 mins to fix

            Function _not_modified has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            def _not_modified(request, response=None):
                new_response = HttpResponseNotModified()
                if response:
                    # Preserve the headers required by Section 4.1 of RFC 7232, as well as
                    # Last-Modified.
            Severity: Minor
            Found in django/utils/cache.py - 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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                        if directive == 'no-cache':
                            # no-cache supports multiple field names.
                            cc[directive].add(value)
                        else:
                            cc[directive] = value
            Severity: Minor
            Found in django/utils/cache.py and 1 other location - About 55 mins to fix
            django/utils/cache.py on lines 87..91

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 37.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if directive == 'no-cache':
                        # no-cache supports multiple field names.
                        cc[directive].add(v)
                    else:
                        cc[directive] = v
            Severity: Minor
            Found in django/utils/cache.py and 1 other location - About 55 mins to fix
            django/utils/cache.py on lines 67..71

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 37.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status