ministryofjustice/moj-product-dashboard

View on GitHub
dashboard/apps/dashboard/models/product.py

Summary

Maintainability
D
3 days
Test Coverage

File product.py has 784 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
from datetime import date, timedelta
from decimal import Decimal

from django.db import models
Severity: Major
Found in dashboard/apps/dashboard/models/product.py - About 1 day to fix

    Product has 33 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Product(BaseProduct, AditionalCostsMixin):
        hr_id = models.CharField(max_length=12, unique=True, null=True)
        float_id = models.CharField(max_length=128, unique=True)
        is_billable = models.BooleanField(default=True)
        area = models.ForeignKey('Area', related_name='products',
    Severity: Minor
    Found in dashboard/apps/dashboard/models/product.py - About 4 hrs to fix

      Function stats_in_time_frames has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def stats_in_time_frames(self, start_date, end_date, freq,
                                   calculation_start_date=None):
              """
              cumulative stats of time frames sliced by freq
              :param start_date: start date of time window, a date object
      Severity: Minor
      Found in dashboard/apps/dashboard/models/product.py - About 55 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

      Consider simplifying this complex logical expression.
      Open

              if self.end_date and today >= self.end_date:
                  return 'Ended'
              elif self.live_date and today >= self.live_date:
                  return 'Live'
              elif self.beta_date and today >= self.beta_date:
      Severity: Major
      Found in dashboard/apps/dashboard/models/product.py - About 40 mins to fix

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

            def people_costs(self, start_date, end_date, contractor_only=False,
        Severity: Minor
        Found in dashboard/apps/dashboard/models/product.py - About 35 mins to fix

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

              def people_costs(self, start_date, end_date, contractor_only=False,
          Severity: Minor
          Found in dashboard/apps/dashboard/models/product.py - About 35 mins to fix

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

                def phase(self):
                    today = date.today()
                    if self.end_date and today >= self.end_date:
                        return 'Ended'
                    elif self.live_date and today >= self.live_date:
            Severity: Minor
            Found in dashboard/apps/dashboard/models/product.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 last_date has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def last_date(self):
                    """
                    default end date is the date when the last spend occurs or
                    the last budget allocated to the product or the specified end date
                    it is the greatest of these dates in the product:
            Severity: Minor
            Found in dashboard/apps/dashboard/models/product.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

            Avoid too many return statements within this function.
            Open

                        return 'Not Defined'
            Severity: Major
            Found in dashboard/apps/dashboard/models/product.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return 'Discovery'
              Severity: Major
              Found in dashboard/apps/dashboard/models/product.py - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status