Function build
has a Cognitive Complexity of 12 (exceeds 7 allowed). Consider refactoring. Open
def build(self, profile_id=None, rule_id=None):
"""
Creates Playbooks for a specified profile.
If profile is not given, creates playbooks for all profiles
in the product.
- 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 _get_rules_variables
has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring. Open
def _get_rules_variables(self, base_dir):
for dirpath, dirnames, filenames in os.walk(base_dir):
dirnames.sort()
filenames.sort()
for filename in filenames:
- 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 __init__
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, product_yaml_path, input_dir, output_dir, rules_dir, profiles_dir,
Function create_playbook
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def create_playbook(self, snippet_path, rule_id, variables,
Function choose_variable_value
has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring. Open
def choose_variable_value(self, var_id, variables, refinements):
"""
Determine value of variable based on profile refinements.
"""
if refinements and var_id in refinements:
- 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 get_data_from_snippet
has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring. Open
def get_data_from_snippet(self, snippet_yaml, variables, refinements):
"""
Extracts and resolves tasks and variables from Ansible snippet.
"""
xccdf_var_pattern = re.compile(r"\(xccdf-var\s+(\S+)\)")
- 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
Either merge this branch with the identical one on line "57" or change one of the implementations. Open
value = list(options.values())[0]
- Read upRead up
- Exclude checks
Having two branches in the same if
structure with the same implementation is at best duplicate code, and at worst a coding error. If
the same logic is truly needed for both instances, then they should be combined.
Noncompliant Code Example
if 0 <= a < 10: do_the_thing() elif 10 <= a < 20: do_the_other_thing() elif 20 <= a < 50: do_the_thing() # Noncompliant; duplicates first condition else: do_the_rest() b = 4 if a > 12 else 4
Compliant Solution
if (0 <= a < 10) or (20 <= a < 50): do_the_thing() elif 10 <= a < 20: do_the_other_thing() else: do_the_rest() b = 4
or
if 0 <= a < 10: do_the_thing() elif 10 <= a < 20: do_the_other_thing() elif 20 <= a < 50: do_the_third_thing() else: do_the_rest() b = 8 if a > 12 else 4