components/collector/src/model/parameters.py
Function get
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Open
def get(self, parameter_key: str, quote: bool = False) -> str | list[str]:
"""Return the parameter with the given key."""
def quote_if_needed(parameter_value: str) -> str:
"""Quote the string if needed."""
- Read upRead up
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
Consider simplifying this complex logical expression. Open
Open
if parameter_info.type == "multiple_choice":
# If the user didn't pick any values, select the default value if any, otherwise select all values:
default_value = parameter_info.default_value
value = self.__parameters.get(parameter_key) or default_value or parameter_info.values or []
# Ensure all values picked by the user are still allowed. Remove any values that are no longer allowed: