ComplianceAsCode/content

View on GitHub
utils/create_srg_export.py

Summary

Maintainability
A
2 hrs
Test Coverage

Function handle_control has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
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()
Severity: Minor
Found in utils/create_srg_export.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

Function handle_control has 8 arguments (exceeds 4 allowed). Consider refactoring.
Open

def handle_control(product: str, control: ssg.controls.Control, env_yaml: ssg.environment,
Severity: Major
Found in utils/create_srg_export.py - About 1 hr to fix

    Function "handle_control" has 8 parameters, which is greater than the 7 authorized.
    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:
    Severity: Major
    Found in utils/create_srg_export.py by sonar-python

    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

    def handle_control(product: str, control: ssg.controls.Control, env_yaml: ssg.environment,
    Severity: Critical
    Found in utils/create_srg_export.py by sonar-python

    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.

    See

    There are no issues that match your filters.

    Category
    Status