fedspendingtransparency/usaspending-api

View on GitHub
usaspending_api/search/v2/views/spending_by_category_views/spending_by_locations.py

Summary

Maintainability
A
2 hrs
Test Coverage
A
99%

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

    def build_elasticsearch_result(self, response: dict) -> List[dict]:
        def _key_to_geo_code(key):
            if self.location_type == LocationType.COUNTRY:
                return key
            return f"{code_to_state[key[:2]]['fips']}{key[2:]}" if (key and key[:2] in code_to_state) else None

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