uktrade/directory-api

View on GitHub

Showing 1,124 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

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

        def handle(self, *args, **options):
            with open('dataservices/resources/weo.csv', 'r', encoding='utf-8-sig') as f:
                data = tablib.import_set(f.read(), format='csv', headers=True)
    
                weo_resource = resources.modelresource_factory(model=WorldEconomicOutlook)()
    Severity: Major
    Found in dataservices/management/commands/import_weo_data.py and 1 other location - About 1 day to fix
    personalisation/management/commands/create_countries_of_interest.py on lines 10..23

    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 148.

    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

        @transaction.atomic
        def handle(self, *args, **options):
            with open('personalisation/management/commands/countries_of_interest.csv', 'r', encoding='utf-8-sig') as f:
                data = tablib.import_set(f.read(), format='csv', headers=True)
    
    
    dataservices/management/commands/import_weo_data.py on lines 11..22

    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 148.

    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

    Cyclomatic complexity is too high in class Command. (49)
    Open

    class Command(BaseCommand):
        help = 'Import target age groups (male/female).'
    
        def handle(self, *args, **options):
            genders = ['male', 'female']

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in method handle. (49)
    Open

        def handle(self, *args, **options):
            genders = ['male', 'female']
            population_data = []
    
            for gender in genders:

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    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

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

            def authenticate(self, request):
                auth = authentication.get_authorization_header(request).split()
                if not auth or auth[0].decode() != self.keyword:
                    return None
                if len(auth) == 1:
        Severity: Major
        Found in core/authentication.py and 1 other location - About 6 hrs to fix
        core/authentication.py on lines 23..29

        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 100.

        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

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

            def authenticate(self, request):
                auth = authentication.get_authorization_header(request).split()
                if not auth or auth[0].decode() != self.keyword:
                    return None
                if len(auth) == 1:
        Severity: Major
        Found in core/authentication.py and 1 other location - About 6 hrs to fix
        core/authentication.py on lines 60..66

        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 100.

        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 PublishedCompaniesTestAPIView(TestAPIView, RetrieveAPIView):
            serializer_class = PublishedCompaniesSerializer
            queryset = Company.objects.filter(
                Q(is_published_investment_support_directory=True) | Q(is_published_find_a_supplier=True)
            )
        Severity: Major
        Found in testapi/views.py and 1 other location - About 5 hrs to fix
        testapi/views.py on lines 138..149

        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 90.

        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 UnpublishedCompaniesTestAPIView(TestAPIView, RetrieveAPIView):
            serializer_class = PublishedCompaniesSerializer
            queryset = Company.objects.filter(
                Q(is_published_investment_support_directory=False) | Q(is_published_find_a_supplier=False)
            )
        Severity: Major
        Found in testapi/views.py and 1 other location - About 5 hrs to fix
        testapi/views.py on lines 124..135

        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 90.

        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 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

          Cyclomatic complexity is too high in method handle. (26)
          Open

              def handle(self, *args, **options):
                  given_env = options.get("env", None)
                  env = 'stage' if given_env else 'prod'
          
                  # Company supplied data

          Cyclomatic Complexity

          Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

          Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

          Construct Effect on CC Reasoning
          if +1 An if statement is a single decision.
          elif +1 The elif statement adds another decision.
          else +0 The else statement does not cause a new decision. The decision is at the if.
          for +1 There is a decision at the start of the loop.
          while +1 There is a decision at the while statement.
          except +1 Each except branch adds a new conditional path of execution.
          finally +0 The finally block is unconditionally executed.
          with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
          assert +1 The assert statement internally roughly equals a conditional statement.
          Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
          Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

          Source: http://radon.readthedocs.org/en/latest/intro.html

          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

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

              class OwnershipChangeNotification(MultiUserOwnershipBaseNotification):
                  template_id = settings.GOVNOTIFY_ACCOUNT_OWNERSHIP_TRANSFER_TEMPLATE_ID
              
                  def send_async(self):
                      notifications_client().send_email_notification(
              Severity: Major
              Found in company/email.py and 1 other location - About 4 hrs to fix
              company/email.py on lines 28..38

              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 77.

              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 CollaboratorNotification(MultiUserOwnershipBaseNotification):
                  template_id = settings.GOVNOTIFY_ACCOUNT_COLLABORATOR_TEMPLATE_ID
              
                  def send_async(self):
                      notifications_client().send_email_notification(
              Severity: Major
              Found in company/email.py and 1 other location - About 4 hrs to fix
              company/email.py on lines 13..23

              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 77.

              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 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
                Severity
                Category
                Status
                Source
                Language