fedspendingtransparency/usaspending-api

View on GitHub
usaspending_api/search/v2/views/spending_by_geography.py

Summary

Maintainability
C
1 day
Test Coverage
B
87%

File spending_by_geography.py has 461 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
import logging
from decimal import Decimal
from enum import Enum
from typing import Dict, List, Optional
Severity: Minor
Found in usaspending_api/search/v2/views/spending_by_geography.py - About 7 hrs to fix

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

        def build_elasticsearch_result(self, response: dict) -> Dict[str, dict]:
            def _key_to_geo_code(key):
                return f"{code_to_state[key[:2]]['fips']}{key[2:]}" if (key and key[:2] in code_to_state) else None
    
            # Get the codes
    Severity: Minor
    Found in usaspending_api/search/v2/views/spending_by_geography.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