uktrade/directory-api

View on GitHub

Showing 74 of 1,128 total issues

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

import json

from django.apps import apps
from django.db.models import Sum
from django.shortcuts import get_object_or_404
Severity: Major
Found in dataservices/views.py - About 1 day to fix

    Function handle has a Cognitive Complexity of 77 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle(self, *args, **options):
            genders = ['male', 'female']
            population_data = []
    
            for gender in genders:
    Severity: Minor
    Found in dataservices/management/commands/import_target_age_groups.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 handle has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle(self, *args, **options):
            given_env = options.get("env", None)
            env = 'stage' if given_env else 'prod'
    
            # Company supplied data
    Severity: Minor
    Found in company/management/commands/update_investment_services_directory.py - About 7 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 settings.py has 469 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import os
    
    import directory_healthcheck.backends
    import dj_database_url
    import environ
    Severity: Minor
    Found in conf/settings.py - About 7 hrs to fix

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

      import abc
      
      from directory_constants import user_roles
      from django.conf import settings
      from django.db.models import BooleanField, Case, Count, Q, Value, When
      Severity: Minor
      Found in company/views.py - About 6 hrs to fix

        File urls.py has 382 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import directory_healthcheck.views
        import django
        from django.conf import settings
        from django.conf.urls import include
        from django.contrib import admin
        Severity: Minor
        Found in conf/urls.py - About 5 hrs to fix

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

          from django.core.exceptions import ValidationError
          from django.db import models
          from django.utils.translation import gettext as _
          
          from core.helpers import TimeStampedModel
          Severity: Minor
          Found in dataservices/models.py - About 4 hrs to fix

            File helpers.py has 362 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import csv
            import itertools
            import logging
            import re
            from collections import defaultdict
            Severity: Minor
            Found in company/helpers.py - About 4 hrs to fix

              File forms.py has 339 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import ast
              import csv
              import io
              import json
              import re
              Severity: Minor
              Found in company/forms.py - About 4 hrs to fix

                Function clean_csv_file has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                Open

                    def clean_csv_file(self):
                        self.created_companies = []
                        self.skipped_companies = []
                        csv_file = io.TextIOWrapper(self.cleaned_data['csv_file'].file, encoding='utf-8')
                        dialect = csv.Sniffer().sniff(csv_file.read(1024))
                Severity: Minor
                Found in company/forms.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 handle has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                Open

                    def handle(self, *args, **options):
                        empty_ep_counter = 0
                        not_empty_ep_counter = 0
                
                        no_product_and_country_no_data = 0
                Severity: Minor
                Found in exportplan/management/commands/report_export_plan.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 load_raw_files has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                Open

                    def load_raw_files(self, filenames):
                        # Loads a raw file as downloaded from comtrade on top of existing data in db
                
                        for filename in filenames:
                            self.stdout.write(self.style.SUCCESS(f'********  Loading: {filename}'))
                Severity: Minor
                Found in dataservices/management/commands/import_comtrade_data.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

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

                import directory_validators.string
                from directory_constants import choices, user_roles
                from django.conf import settings
                from django.http import QueryDict
                from django.utils.timezone import now
                Severity: Minor
                Found in company/serializers.py - About 3 hrs to fix

                  File search_filters.py has 306 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  from elasticsearch_dsl import analysis
                  
                  companies_stopwords_filter = analysis.token_filter(
                      'companies_stopwords', type='stop', stopwords=['limited', 'ltd', 'plc', 'llp', 'lp', 'rc', 'partnership', 'ngo']
                  )
                  Severity: Minor
                  Found in company/search_filters.py - About 3 hrs to fix

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

                        def update(self, instance, validated_data):
                            # This will allow partial updating to json fields during a patch update. Json fields generally represent
                            # a export plan page. we only want to update the field being sent else by nature we would wipe all the
                            # other fields
                            for field_name in validated_data.keys():
                    Severity: Minor
                    Found in exportplan/serializers.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

                    File stage_ids.py has 302 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    stage_ids = {
                        '05210891': 9285,
                        '06469178': 2054,
                        '09611823': 3762,
                        '03303852': 2918,
                    Severity: Minor
                    Found in investment_supplier_data/stage_ids.py - About 3 hrs to fix

                      Function handle has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def handle(self, *args, **options):
                              count = 0
                              for export_plan in models.CompanyExportPlan.objects.all():
                                  updated = False
                      
                      
                      Severity: Minor
                      Found in exportplan/management/commands/derive_export_quantity_end.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

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

                      import logging
                      from datetime import datetime
                      
                      import django_filters.rest_framework
                      from django.conf import settings
                      Severity: Minor
                      Found in activitystream/views.py - About 2 hrs to fix

                        Function handle has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def handle(self, *args, **options):
                                key_mapping = {'CPI score': 'cpi_score', 'Rank': 'rank'}
                        
                                with open('dataservices/resources/corruption_perception_index.csv', 'r', encoding='utf-8-sig') as f:
                                    file_reader = csv.DictReader(f)
                        Severity: Minor
                        Found in dataservices/management/commands/import_cpi_data.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 get_unique_exportplan_name has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                        Open

                        def get_unique_exportplan_name(ep_dict):
                            numbers_used = set()
                            sso_id = ep_dict.get('sso_id')
                            products = ep_dict.get('export_commodity_codes')
                            commodity_name = products[0].get('commodity_name') if products else ''
                        Severity: Minor
                        Found in exportplan/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

                        Severity
                        Category
                        Status
                        Source
                        Language