nephila/djangocms-redirect

View on GitHub

Showing 4 of 4 total issues

Function do_redirect has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

    def do_redirect(self, request, response=None):
        site_id = int(settings.SITE_ID)
        if getattr(settings, "DJANGOCMS_REDIRECT_404_ONLY", True) and response and response.status_code != 404:
            return response

Severity: Minor
Found in djangocms_redirect/middleware.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 towncrier_check has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

def towncrier_check(c):  # NOQA
    """Check towncrier files."""
    output = io.StringIO()
    c.run("git branch -a --contains HEAD", out_stream=output)
    skipped_branch_prefix = ["pull/", "release/", "develop", "master", "HEAD"]
Severity: Minor
Found in tasks.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

Avoid too many return statements within this function.
Open

            return self.response_gone_class()
Severity: Major
Found in djangocms_redirect/middleware.py - About 30 mins to fix

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

        def _match_substring(self, original_path):
            redirects = [
                (r.old_path, r) for r in Redirect.objects.filter(Q(subpath_match=True) | Q(catchall_redirect=True))
            ]
            redirects = sorted(redirects, key=itemgetter(0), reverse=True)
    Severity: Minor
    Found in djangocms_redirect/middleware.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

    Severity
    Category
    Status
    Source
    Language