uktrade/lite-api

View on GitHub

Showing 282 of 537 total issues

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

import logging

from django.core.exceptions import PermissionDenied
from django.db import transaction
from django.http.response import JsonResponse, HttpResponse
Severity: Major
Found in api/cases/views/views.py - About 2 days to fix

    File clients.py has 864 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import random
    import timeit
    import uuid
    import sys
    from django.utils import timezone
    Severity: Major
    Found in test_helpers/clients.py - About 2 days to fix

      File serializers.py has 828 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      from rest_framework import serializers
      from rest_framework.relations import PrimaryKeyRelatedField
      
      from api.core.helpers import str_to_bool
      from api.core.serializers import KeyValueChoiceField, ControlListEntryField, GoodControlReviewSerializer
      Severity: Major
      Found in api/goods/serializers.py - About 1 day to fix

        File context_generator.py has 777 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        from collections import defaultdict
        from datetime import timedelta
        
        from django.contrib.humanize.templatetags.humanize import intcomma
        from django.db.models import Q
        Severity: Major
        Found in api/letter_templates/context_generator.py - About 1 day to fix

          File applications.py has 730 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          from copy import deepcopy
          from uuid import UUID
          
          from django.db import transaction
          from django.db.models import F, Q
          Severity: Major
          Found in api/applications/views/applications.py - About 1 day to fix

            File serializers.py has 645 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            from django.contrib.contenttypes.models import ContentType
            from django.core.exceptions import ValidationError
            from django.utils import timezone
            from rest_framework import serializers
            
            
            Severity: Major
            Found in api/cases/serializers.py - About 1 day to fix

              Function prefetch_generic_relations has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
              Open

              def prefetch_generic_relations(qs):  # noqa
                  """
                  Prefetches the models attributed to all generic fields in a queryset
              
                  From https://djangosnippets.org/snippets/2492/ with some tweaks.
              Severity: Minor
              Found in api/common/models.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

              File models.py has 551 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import logging
              import uuid
              from collections import defaultdict
              from typing import Optional
              
              
              Severity: Major
              Found in api/cases/models.py - About 1 day to fix

                Function search has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
                Open

                    def search(  # noqa
                        self,
                        queue_id=None,
                        is_work_queue=None,
                        user=None,
                Severity: Minor
                Found in api/cases/managers.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

                File managers.py has 474 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                from datetime import datetime
                from typing import List
                
                from django.apps import apps
                from django.db import models, transaction
                Severity: Minor
                Found in api/cases/managers.py - About 7 hrs to fix

                  DataTestClient has 50 functions (exceeds 20 allowed). Consider refactoring.
                  Open

                  class DataTestClient(APITestCase, URLPatternsTestCase):
                      """
                      Test client which creates seeds the database with system data and sets up an initial organisation and user
                      """
                  
                  
                  Severity: Minor
                  Found in test_helpers/clients.py - About 7 hrs to fix

                    File models.py has 441 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    import uuid
                    
                    from django.contrib.contenttypes.fields import GenericRelation
                    from django.contrib.postgres.fields import ArrayField
                    from django.db import models
                    Severity: Minor
                    Found in api/applications/models.py - About 6 hrs to fix

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

                      import logging
                      
                      from django.conf import settings
                      from django.core.exceptions import PermissionDenied
                      from django.db import transaction
                      Severity: Minor
                      Found in api/goods/views.py - About 6 hrs to fix

                        CaseQuerySet has 45 functions (exceeds 20 allowed). Consider refactoring.
                        Open

                        class CaseQuerySet(models.QuerySet):
                            """
                            Custom queryset for the Case model. This allows us to chain application specific
                            filtering logic in a reusable way.
                        
                        
                        Severity: Minor
                        Found in api/cases/managers.py - About 6 hrs to fix

                          Function search has 49 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              def search(  # noqa
                          Severity: Major
                          Found in api/cases/managers.py - About 6 hrs to fix

                            File serializers.py has 415 lines of code (exceeds 250 allowed). Consider refactoring.
                            Open

                            import re
                            
                            from django.db import transaction
                            from django.utils import timezone
                            from phonenumber_field.serializerfields import PhoneNumberField
                            Severity: Minor
                            Found in api/organisations/serializers.py - About 5 hrs to fix

                              File settings.py has 397 lines of code (exceeds 250 allowed). Consider refactoring.
                              Open

                              import logging
                              import os
                              import sys
                              from pathlib import Path
                              from urllib.parse import urlencode
                              Severity: Minor
                              Found in api/conf/settings.py - About 5 hrs to fix

                                File good.py has 357 lines of code (exceeds 250 allowed). Consider refactoring.
                                Open

                                from rest_framework import serializers
                                from rest_framework.fields import DecimalField, ChoiceField, BooleanField
                                from rest_framework.relations import PrimaryKeyRelatedField
                                
                                from django.forms.models import model_to_dict
                                Severity: Minor
                                Found in api/applications/serializers/good.py - About 4 hrs to fix

                                  Function _get_refused_goods_type_context has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  def _get_refused_goods_type_context(case_pk, goods_types, refused_goods_type_on_country_decisions):
                                      # Refused goods types on country from GoodCountryDecisions
                                      context = {}
                                      if refused_goods_type_on_country_decisions:
                                          for decision in refused_goods_type_on_country_decisions:
                                  Severity: Minor
                                  Found in api/letter_templates/context_generator.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

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

                                      def __init__(self, *args, **kwargs):
                                          super().__init__(*args, **kwargs)
                                  
                                          if hasattr(self, "initial_data"):
                                              if not self.initial_data.get("control_list_entries") and not self.partial:
                                  Severity: Minor
                                  Found in api/goods/serializers.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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language