utils/create_srg_export.py
Function handle_control
has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring. Open
Open
def handle_control(product: str, control: ssg.controls.Control, env_yaml: ssg.environment,
rule_json: dict, srgs: dict, used_rules: list, root_path: str,
prefer_controls: bool) -> list:
if len(control.selections) > 0 and use_rule_content(control, prefer_controls):
rows = list()
- 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
Function handle_control
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def handle_control(product: str, control: ssg.controls.Control, env_yaml: ssg.environment,
Function "handle_control" has 8 parameters, which is greater than the 7 authorized. Open
Open
def handle_control(product: str, control: ssg.controls.Control, env_yaml: ssg.environment,
rule_json: dict, srgs: dict, used_rules: list, root_path: str,
prefer_controls: bool) -> list:
- Read upRead up
- Exclude checks
A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.
Noncompliant Code Example
With a maximum number of 4 parameters:
def do_something(param1, param2, param3, param4, param5): ...
Compliant Solution
def do_something(param1, param2, param3, param4): ...
Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed. Open
Open
def handle_control(product: str, control: ssg.controls.Control, env_yaml: ssg.environment,
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.