uktrade/directory-api

View on GitHub

Showing 74 of 1,128 total issues

Avoid deeply nested control flow statements.
Open

                        if value:
                            population_data.append(
                                PopulationUrbanRural(country=country, year=year, urban_rural=urban_rural, value=value)
                            )

Severity: Major
Found in dataservices/management/commands/import_population_urbanrural.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                                    if user.exists():
                                        user.update(**cleaned_row)
                                        company = user.first().company
                                        company.mobile_number = cleaned_row["mobile_number"]
                                        company.save()
    Severity: Major
    Found in company/management/commands/update_investment_services_directory.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if country_iso3 and uk_or_world:
                                  written = written + 1
                                  report = ComtradeReport(
                                      country_iso3=country_iso3,
                                      year=row.get('Year'),
      Severity: Major
      Found in dataservices/management/commands/import_comtrade_data.py - About 45 mins to fix

        Function process_view has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def process_view(self, request, view_func, view_args, view_kwarg):
                if request.user is not None:
                    if request.resolver_match.namespace == 'admin' or request.path_info.startswith('/admin/login'):
                        if not request.user.is_staff and request.user.is_authenticated:
                            return HttpResponse(self.SSO_UNAUTHORISED_ACCESS_MESSAGE, status=401)
        Severity: Minor
        Found in core/middleware.py - About 45 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 do_import_markets has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def do_import_markets(self, *args, **options):
                try:
                    with open(self.DEFAULT_FILENAME) as f:
                        data = json.load(f)
                except Exception as e:
        Severity: Minor
        Found in dataservices/management/commands/import_markets_countries_territories.py - About 45 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

                                        if investment_company.exists():
                                            # This will update the object
                                            address_added = self.fetch_companies_house_data(switch_envs)
                                            adjust_types = self.adjust_field_types(address_added)
                                            investment_company.update(**adjust_types)
        Severity: Major
        Found in company/management/commands/update_investment_services_directory.py - About 45 mins to fix

          Function adjust_field_types has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def adjust_field_types(self, row: dict) -> dict:
                  json_fields = [
                      "expertise_products_services",
                  ]
                  lists = ["expertise_industries", "expertise_regions", "expertise_languages"]
          Severity: Minor
          Found in company/management/commands/update_investment_services_directory.py - About 45 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 k2, v2 in v.items():
                                      if not field_value.get(k):
                                          # First time this key is being set, default to empty dict so we don't get index error
                                          field_value[k] = {}
                                      field_value[k][k2] = v2
          Severity: Major
          Found in exportplan/serializers.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                            if investment_company.exists():
                                                # This will update the object
                                                address_added = self.fetch_companies_house_data(cleaned_row)
                                                adjust_types = self.adjust_field_types(address_added)
                                                investment_company.update(**adjust_types)
            Severity: Major
            Found in company/management/commands/update_investment_services_directory.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if partner_iso3 == 'WLD' and flow == 'Import':
                                          uk_or_world = partner_iso3
                                          country_iso3 = reporter_iso3
                                      if country_iso3 and uk_or_world:
              Severity: Major
              Found in dataservices/management/commands/import_comtrade_data.py - About 45 mins to fix

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

                    def clean_csv_file(self):
                        self.update_errors = []
                        self.updated_companies = []
                
                        csv_file = io.TextIOWrapper(self.cleaned_data['csv_file'].file, encoding='utf-8')
                Severity: Minor
                Found in company/forms.py - About 45 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 should_ingestion_run has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def should_ingestion_run(self, view_name, table_name):
                        dataflow_metadata = self.get_dataflow_metadata(table_name)
                        swapped_date = dataflow_metadata.loc[:, 'dataflow_swapped_tables_utc'][0].to_pydatetime().date()
                        great_metadata = self.get_view_metadata(view_name)
                        great_metadata_date = None
                Severity: Minor
                Found in dataservices/management/commands/helpers.py - About 45 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

                                        if reporter_iso3 == 'GBR' and flow == 'Export':
                                            uk_or_world = reporter_iso3
                                            country_iso3 = partner_iso3
                                        if partner_iso3 == 'WLD' and flow == 'Import':
                Severity: Major
                Found in dataservices/management/commands/import_comtrade_data.py - About 45 mins to fix

                  Function before_import has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def before_import(self, dataset, using_transactions, dry_run, **kwargs):
                  Severity: Minor
                  Found in dataservices/management/commands/import_countries.py - About 35 mins to fix

                    Function send_account_ownership_transfer_notification has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    def send_account_ownership_transfer_notification(sender, instance, created, *args, **kwargs):
                    Severity: Minor
                    Found in company/signals.py - About 35 mins to fix

                      Function get_multiple_serialized_instance_from_model has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      def get_multiple_serialized_instance_from_model(model_class, serializer_class, filter_args, section_key, latest_only):
                      Severity: Minor
                      Found in dataservices/helpers.py - About 35 mins to fix

                        Function send_new_invite_collaboration_notification has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        def send_new_invite_collaboration_notification(sender, instance, created, *args, **kwargs):
                        Severity: Minor
                        Found in company/signals.py - About 35 mins to fix

                          Function send_account_collaborator_notification has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          def send_account_collaborator_notification(sender, instance, created, *args, **kwargs):
                          Severity: Minor
                          Found in company/signals.py - About 35 mins to fix

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

                                def bucket_by_country(self, filters, barriers_data):
                                    bucked_data = {k: {'barriers': []} for (k) in filters.get('locations').keys()}
                                    for iso_2, name in filters.get('locations', {}).items():
                                        for barrier in barriers_data:
                                            if barrier['country']['name'] == name:
                            Severity: Minor
                            Found in dataservices/core/client_api.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 handle has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def handle(self, *args, **options):
                                    response = requests.get(
                                        'https://raw.githubusercontent.com/iancoleman/cia_world_factbook_api/master/data/factbook.json'
                                    )
                                    data = response.json()
                            Severity: Minor
                            Found in dataservices/management/commands/import_cia_factbook_data.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