uktrade/lite-forms

View on GitHub

Showing 32 of 39 total issues

File components.py has 566 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from enum import Enum
from typing import List, Optional, Dict, Set

from lite_forms.styles import ButtonStyle

Severity: Major
Found in components.py - About 1 day to fix

    Function submit_paged_form has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
    Open

    def submit_paged_form(  # noqa
        request, form_group: FormGroup, action: Callable, object_pk=None, inject_data=None, additional_context: dict = None,
    ):
        """
        Function to handle the submission of the data from one form in a sequence of forms (a FormGroup).
    Severity: Minor
    Found in submitters.py - About 1 day 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 key_in_array has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    def key_in_array(data, key):
        if data is None:
            return False
    
        if isinstance(data, str):
    Severity: Minor
    Found in templatetags/custom_tags.py - About 4 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

    File views.py has 338 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import copy
    from abc import ABC
    from typing import List
    
    from django.contrib import messages
    Severity: Minor
    Found in views.py - About 4 hrs to fix

      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 get_next_form_page has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_next_form_page(self, form_pk, action, request, post_errors):
              form = copy.deepcopy(next(form for form in self.get_forms().forms if str(form.pk) == form_pk))
      
              # Add form fields to validated_data if they dont exist
              for component in get_all_form_components(form):
      Severity: Minor
      Found in views.py - About 2 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 date_join has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def date_join(data, prefix):
          if data:
              date = dict()
              prefix_length = len(prefix)
              for key, value in data.items():
      Severity: Minor
      Found in templatetags/custom_tags.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 item_with_rating_exists has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def item_with_rating_exists(items, rating):
          if not items:
              return
      
          for item in items:
      Severity: Minor
      Found in templatetags/custom_tags.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

      Function _post has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _post(self, request, **kwargs):
              self.init(request, **kwargs)
              self._validated_data = request.POST.copy()
              self._validated_data = handle_lists(self._validated_data)
      
      
      Severity: Minor
      Found in views.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 prettify_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def prettify_data(self, data):
              """
              Takes the data to be presented on the summary list and manipulates it
              to be human readable
              """
      Severity: Minor
      Found in views.py - About 55 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 dispatch has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def dispatch(self, request, *args, **kwargs):
              forms = [4]
              self.request.upload_handlers.insert(0, FormS3FileUploadHandler(forms, request))
      
              if request.method.lower() in self.http_method_names:
      Severity: Minor
      Found in views.py - About 55 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

      Avoid deeply nested control flow statements.
      Open

                          for sub_value in value:
                              current_form.questions.insert(0, HiddenField(key + "[]", sub_value))
                      else:
      Severity: Major
      Found in submitters.py - About 45 mins to fix

        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

          Avoid deeply nested control flow statements.
          Open

                              if question.prefix in key:
                                  exists = True
                                  continue
                          elif hasattr(question, "name"):
          Severity: Major
          Found in submitters.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if question.name == key:
                                    exists = True
                                    continue
            
            
            Severity: Major
            Found in submitters.py - About 45 mins to fix

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

                  def __init__(
                      self,
                      title=None,
                      description=None,
                      questions=None,
              Severity: Minor
              Found in components.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 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

              Severity
              Category
              Status
              Source
              Language