ministryofjustice/moj-product-dashboard

View on GitHub

Showing 322 of 322 total issues

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

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

            for _ in range(10):
                rand_sd = fake.date_time_between(
                    to_datetime(year_start),
                    to_datetime(first_half_end)
                )
    Severity: Major
    Found in dashboard/apps/dashboard/tests/test_task.py and 1 other location - About 1 day to fix
    dashboard/apps/dashboard/tests/test_task.py on lines 357..388

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

    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

            for _ in range(10):
                rand_sd = fake.date_time_between(
                    to_datetime(second_half_start),
                    to_datetime(year_end)
                )
    Severity: Major
    Found in dashboard/apps/dashboard/tests/test_task.py and 1 other location - About 1 day to fix
    dashboard/apps/dashboard/tests/test_task.py on lines 322..352

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

    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

            migrations.CreateModel(
                name='PersonCost',
                fields=[
                    ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                    ('type', models.PositiveSmallIntegerField(choices=[(1, 'One off'), (2, 'Monthly'), (3, 'Annually')], default=1)),
    Severity: Major
    Found in dashboard/apps/dashboard/migrations/0001_initial.py and 1 other location - About 1 day to fix
    dashboard/apps/dashboard/migrations/0001_initial.py on lines 192..206

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

    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

            migrations.CreateModel(
                name='Saving',
                fields=[
                    ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                    ('type', models.PositiveSmallIntegerField(choices=[(1, 'One off'), (2, 'Monthly'), (3, 'Annually')], default=1)),
    Severity: Major
    Found in dashboard/apps/dashboard/migrations/0001_initial.py and 1 other location - About 1 day to fix
    dashboard/apps/dashboard/migrations/0001_initial.py on lines 89..103

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

    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

    describe('lastQuarter', () => {
      it(`gets the first day of last quarter as startDate
           and last day of last quarter as endDate`, () => {
        const q1 = lastQuarter(moment('2016-02-29'));
        expect(q1.startDate).toEqual('2015-10-01');
    Severity: Major
    Found in dashboard/assets/js/__tests__/utils-test.js and 1 other location - About 1 day to fix
    dashboard/assets/js/__tests__/utils-test.js on lines 87..106

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

    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

    describe('thisQuarter', () => {
      it(`gets the first day of this quarter as startDate
           and last day of this quarter as endDate`, () => {
        const q1 = thisQuarter(moment('2016-02-29'));
        expect(q1.startDate).toEqual('2016-01-01');
    Severity: Major
    Found in dashboard/assets/js/__tests__/utils-test.js and 1 other location - About 1 day to fix
    dashboard/assets/js/__tests__/utils-test.js on lines 110..129

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

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

    # -*- coding: utf-8 -*-
    from datetime import date, timedelta
    from decimal import Decimal
    
    import pytest
    Severity: Major
    Found in dashboard/apps/dashboard/tests/test_product.py - About 1 day to fix

      Function insert_rows has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
      Open

      def insert_rows(ws, row_idx, cnt, above=False, copy_style=True,
                      fill_formulae=True):  # flake8: noqa  # pragma: no cover
          """Inserts new (empty) rows into worksheet at specified row index.
      
          :param row_idx: Row index specifying where to insert new rows.
      Severity: Minor
      Found in dashboard/apps/reports/forms.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 get_areas(names, as_filter=True):
          if not names:
              logging.info('areas: all')
              if as_filter:
                  return []
      Severity: Major
      Found in dashboard/apps/dashboard/management/commands/helpers.py and 1 other location - About 1 day to fix
      dashboard/apps/dashboard/management/commands/helpers.py on lines 51..64

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

      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

      def get_persons(names, as_filter=True):
          if not names:
              logging.info('people: all')
              if as_filter:
                  return []
      Severity: Major
      Found in dashboard/apps/dashboard/management/commands/helpers.py and 1 other location - About 1 day to fix
      dashboard/apps/dashboard/management/commands/helpers.py on lines 67..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 122.

      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

              migrations.CreateModel(
                  name='ProductGroupStatus',
                  fields=[
                      ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                      ('start_date', models.DateField()),
      Severity: Major
      Found in dashboard/apps/dashboard/migrations/0001_initial.py and 1 other location - About 7 hrs to fix
      dashboard/apps/dashboard/migrations/0001_initial.py on lines 165..176

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

      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

              migrations.CreateModel(
                  name='ProductStatus',
                  fields=[
                      ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                      ('start_date', models.DateField()),
      Severity: Major
      Found in dashboard/apps/dashboard/migrations/0001_initial.py and 1 other location - About 7 hrs to fix
      dashboard/apps/dashboard/migrations/0001_initial.py on lines 151..162

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

      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

          for item in data['clients']:
              useful_data = {
                  'float_id': item['client_id'],
                  'name': item['client_name'],
                  'raw_data': item,
      Severity: Major
      Found in dashboard/apps/dashboard/management/commands/sync.py and 1 other location - About 6 hrs to fix
      dashboard/apps/dashboard/management/commands/sync.py on lines 121..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 104.

      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

          for item in data:
              useful_data = {
                  'float_id': item['department_id'],
                  'name': item['department_name'],
                  'raw_data': item,
      Severity: Major
      Found in dashboard/apps/dashboard/management/commands/sync.py and 1 other location - About 6 hrs to fix
      dashboard/apps/dashboard/management/commands/sync.py on lines 100..113

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

      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 plotCumulativeSpendings has 145 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function plotCumulativeSpendings(product, showBurnDown, startDate, endDate, elem, isSmall) {
        const today = moment().format('YYYY-MM-DD');
        const keyDatesFinancials = product.keyDatesFinancials;
        const keyDates = Object.keys(keyDatesFinancials).sort();
        const pastDates = keyDates.filter(d => d <= today).sort();
      Severity: Major
      Found in dashboard/assets/js/components/cumulative-graph.js - About 5 hrs to fix

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

                    <ProductOverview
                      product={product}
                      onRangeChange={evt => this.handleTimeFrameChange(evt)}
                      selectedRange={this.state.timeFrame}
                      startDate={this.state.startDate}
        Severity: Major
        Found in dashboard/assets/js/containers/product-main.js and 1 other location - About 5 hrs to fix
        dashboard/assets/js/containers/product-main.js on lines 159..169

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

        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

                <ProductPrintMode
                  product={product}
                  onRangeChange={evt => this.handleTimeFrameChange(evt)}
                  selectedRange={this.state.timeFrame}
                  startDate={this.state.startDate}
        Severity: Major
        Found in dashboard/assets/js/containers/product-main.js and 1 other location - About 5 hrs to fix
        dashboard/assets/js/containers/product-main.js on lines 121..131

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

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

        # -*- coding: utf-8 -*-
        from collections import defaultdict
        import copy
        import os
        from decimal import Decimal
        Severity: Minor
        Found in dashboard/apps/reports/forms.py - About 5 hrs to fix

          File test_task.py has 384 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          from decimal import Decimal
          from datetime import date
          
          from django.test import TestCase
          from model_mommy import mommy
          Severity: Minor
          Found in dashboard/apps/dashboard/tests/test_task.py - About 5 hrs to fix
            Severity
            Category
            Status
            Source
            Language