uktrade/lite-api

View on GitHub
api/applications/libraries/application_helpers.py

Summary

Maintainability
B
6 hrs
Test Coverage
B
87%

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

def check_user_can_set_status(request, application, data):
    """
    Checks whether an user (internal/exporter) can set the requested status
    Returns error response if user cannot set the status, None otherwise
    """
Severity: Minor
Found in api/applications/libraries/application_helpers.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 can_status_be_set_by_gov_user has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

def can_status_be_set_by_gov_user(user: GovUser, original_status: str, new_status: str, is_mod: bool) -> bool:
    """
    Check that a status can be set by a gov user. Gov users can not set a case's status to
    `Applicant editing`. They also cannot set a case's status to `Finalised` or open a closed case
    without additional permissions.
Severity: Minor
Found in api/applications/libraries/application_helpers.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 can_status_be_set_by_exporter_user has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def can_status_be_set_by_exporter_user(original_status: str, new_status: str) -> bool:
    """Check that a status can be set by an exporter user. Exporter users cannot withdraw an application
    that is already in a terminal state and they cannot set an application to `Applicant editing` if the
    application is read only.
    """
Severity: Minor
Found in api/applications/libraries/application_helpers.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

Avoid too many return statements within this function.
Open

            return JsonResponse(
Severity: Major
Found in api/applications/libraries/application_helpers.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

            return JsonResponse(data={"errors": ["Invalid user type"]}, status=status.HTTP_401_UNAUTHORIZED)
    Severity: Major
    Found in api/applications/libraries/application_helpers.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

          return True
      Severity: Major
      Found in api/applications/libraries/application_helpers.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return None
        Severity: Major
        Found in api/applications/libraries/application_helpers.py - About 30 mins to fix

          There are no issues that match your filters.

          Category
          Status