fedspendingtransparency/usaspending-api

View on GitHub
usaspending_api/references/v2/views/autocomplete.py

Summary

Maintainability
B
4 hrs
Test Coverage
A
98%

File autocomplete.py has 297 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from django.db.models import Case, F, IntegerField, Q, When
from django.db.models.functions import Upper
from rest_framework.response import Response
from rest_framework.views import APIView
from usaspending_api.common.cache_decorator import cache_response
Severity: Minor
Found in usaspending_api/references/v2/views/autocomplete.py - About 3 hrs to fix

    Function agency_office_autocomplete has a Cognitive Complexity of 23 (exceeds 15 allowed). Consider refactoring.
    Open

        def agency_office_autocomplete(self, request):
            """Returns a collection of agencies, sub-agencies, and offices that match the request."""
    
            search_text, limit = self.get_request_payload(request)
            # It's important to order by toptier fields so that results are deterministic between objects.
    Severity: Minor
    Found in usaspending_api/references/v2/views/autocomplete.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

    There are no issues that match your filters.

    Category
    Status