uktrade/lite-api

View on GitHub

Showing 522 of 528 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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

              Severity: Major
              Found in api/staticdata/f680_clearance_types/test.py and 1 other location - About 1 day to fix
              api/staticdata/decisions/test.py on lines 0..26

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 160.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

              Severity: Major
              Found in api/staticdata/decisions/test.py and 1 other location - About 1 day to fix
              api/staticdata/f680_clearance_types/test.py on lines 0..27

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 160.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              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

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                            if new_case_types != old_case_types:
                                if not old_case_types:
                                    audit_trail_service.create(
                                        actor=request.user,
                                        verb=AuditType.ADDED_LETTER_TEMPLATE_CASE_TYPES,
                Severity: Major
                Found in api/letter_templates/views.py and 1 other location - About 1 day to fix
                api/letter_templates/views.py on lines 177..197

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 136.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                            if new_decisions != old_decisions:
                                if not old_decisions:
                                    audit_trail_service.create(
                                        actor=request.user,
                                        verb=AuditType.ADDED_LETTER_TEMPLATE_DECISIONS,
                Severity: Major
                Found in api/letter_templates/views.py and 1 other location - About 1 day to fix
                api/letter_templates/views.py on lines 154..174

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 136.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                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

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                class BadRequestError(APIException):
                    status_code = status.HTTP_400_BAD_REQUEST
                    default_detail = "Invalid input."
                    default_code = "invalid"
                
                
                Severity: Major
                Found in api/core/exceptions.py and 1 other location - About 1 day to fix
                api/core/exceptions.py on lines 28..45

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 124.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                class NotFoundError(APIException):
                    status_code = status.HTTP_404_NOT_FOUND
                    default_detail = "Invalid input."
                    default_code = "invalid"
                
                
                Severity: Major
                Found in api/core/exceptions.py and 1 other location - About 1 day to fix
                api/core/exceptions.py on lines 63..80

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 124.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                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 views.py has 455 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    import logging
                    
                    from django.conf import settings
                    from django.core.exceptions import PermissionDenied, ValidationError
                    from django.db import transaction
                    Severity: Minor
                    Found in api/goods/views.py - About 6 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

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            for org in organisations_on_applications:
                                _entity_to_xml(
                                    xml_base,
                                    application_id=org["id"],
                                    id=org["organisation_id"],
                        Severity: Major
                        Found in api/cases/enforcement_check/export_xml.py and 1 other location - About 6 hrs to fix
                        api/cases/enforcement_check/export_xml.py on lines 161..172

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 105.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Severity
                        Category
                        Status
                        Source
                        Language