uktrade/lite-forms

View on GitHub
views.py

Summary

Maintainability
C
1 day
Test Coverage

File views.py has 338 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
from abc import ABC
from typing import List

from django.contrib import messages
Severity: Minor
Found in views.py - About 4 hrs to fix

    Function get_next_form_page has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_next_form_page(self, form_pk, action, request, post_errors):
            form = copy.deepcopy(next(form for form in self.get_forms().forms if str(form.pk) == form_pk))
    
            # Add form fields to validated_data if they dont exist
            for component in get_all_form_components(form):
    Severity: Minor
    Found in views.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 _post has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def _post(self, request, **kwargs):
            self.init(request, **kwargs)
            self._validated_data = request.POST.copy()
            self._validated_data = handle_lists(self._validated_data)
    
    
    Severity: Minor
    Found in views.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 dispatch has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def dispatch(self, request, *args, **kwargs):
            forms = [4]
            self.request.upload_handlers.insert(0, FormS3FileUploadHandler(forms, request))
    
            if request.method.lower() in self.http_method_names:
    Severity: Minor
    Found in views.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 prettify_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def prettify_data(self, data):
            """
            Takes the data to be presented on the summary list and manipulates it
            to be human readable
            """
    Severity: Minor
    Found in views.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

    Avoid too many return statements within this function.
    Open

            return redirect(request.path)
    Severity: Major
    Found in views.py - About 30 mins to fix

      There are no issues that match your filters.

      Category
      Status