uktrade/lite-forms

View on GitHub
helpers.py

Summary

Maintainability
C
1 day
Test Coverage

Function get_all_form_components has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

def get_all_form_components(form: Form):
    components = []
    for component in form.questions:
        if component and hasattr(component, "name"):
            components.append(component)
Severity: Minor
Found in helpers.py - About 3 hrs 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 insert_hidden_fields has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

def insert_hidden_fields(data: dict, form: Form):
    for key, value in data.items():
        add = True

        # Only add hidden fields if the data isn't already being passed through a component
Severity: Minor
Found in helpers.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 heading_used_as_label has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def heading_used_as_label(components):
    single_input = None

    if components:
        for component in components:
Severity: Minor
Found in helpers.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

Avoid deeply nested control flow statements.
Open

                    for _component in option.components:
                        if _component and hasattr(_component, "name"):
                            components.append(_component)

Severity: Major
Found in helpers.py - About 45 mins to fix

    Function flatten_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def flatten_data(d, parent_key="", sep="."):
        """
        Flattens dictionaries eg
        {
            'site': {
    Severity: Minor
    Found in helpers.py - About 35 mins 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 remove_unused_errors has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def remove_unused_errors(errors, form: Form):
        """
        Removes all errors that don't belong to a form's fields
        :param errors: ['errors'] children
        :param form: Form object
    Severity: Minor
    Found in helpers.py - About 35 mins 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 convert_list_to_tree has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def convert_list_to_tree(items, key="key", value="value", children="children", exclude=None):
        return_value = []
    
        for item in items:
            node = TreeNode(item[key], item[value])
    Severity: Minor
    Found in helpers.py - About 25 mins 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 nest_data has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def nest_data(sent_data):
        """
        Nests strings into dictionaries eg
        {
            'site.name': 'SITE1'
    Severity: Minor
    Found in helpers.py - About 25 mins 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

    There are no issues that match your filters.

    Category
    Status