Vizzuality/landgriffon

View on GitHub
api/src/modules/impact/comparison/actual-vs-scenario.service.ts

Summary

Maintainability
F
1 wk
Test Coverage

File actual-vs-scenario.service.ts has 358 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Injectable, Logger } from '@nestjs/common';
import {
  GetActualVsScenarioImpactTableDto,
  GROUP_BY_VALUES,
  ORDER_BY,
Severity: Minor
Found in api/src/modules/impact/comparison/actual-vs-scenario.service.ts - About 4 hrs to fix

    Function populateValuesRecursively has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private populateValuesRecursively(
        entity: ActualVsScenarioImpactTableRows,
        entityDataMap: Map<
          string,
          Map<number, ActualVsScenarioImpactTableRowsValues>
    Severity: Major
    Found in api/src/modules/impact/comparison/actual-vs-scenario.service.ts - About 2 hrs to fix

      Function postProcessYearIndicatorData has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

        private postProcessYearIndicatorData(
          entityMap: Map<string, Map<number, ActualVsScenarioImpactTableRowsValues>>,
          rangeOfYears: number[],
          lastYearWithData: number,
        ): void {
      Severity: Minor
      Found in api/src/modules/impact/comparison/actual-vs-scenario.service.ts - 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 buildActualVsScenarioImpactTable has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private buildActualVsScenarioImpactTable(
          queryDto: GetActualVsScenarioImpactTableDto,
          indicators: Indicator[],
          dataForImpactTable: ActualVsScenarioImpactTableData[],
          entityTree: ImpactTableEntityType[],
      Severity: Minor
      Found in api/src/modules/impact/comparison/actual-vs-scenario.service.ts - About 1 hr to fix

        Function calculateIndicatorSumByYear has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private calculateIndicatorSumByYear(
            entityMap: Map<string, Map<number, ActualVsScenarioImpactTableRowsValues>>,
            rangeOfYears: number[],
            lastYearWithData: number,
          ): ActualVsScenarioIndicatorSumByYear[] {
        Severity: Minor
        Found in api/src/modules/impact/comparison/actual-vs-scenario.service.ts - About 1 hr to fix

          Function postProcessYearIndicatorData has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            private postProcessYearIndicatorData(
              entityMap: Map<string, Map<number, ActualVsScenarioImpactTableRowsValues>>,
              rangeOfYears: number[],
              lastYearWithData: number,
            ): void {
          Severity: Minor
          Found in api/src/modules/impact/comparison/actual-vs-scenario.service.ts - About 1 hr to fix

            Function populateValuesRecursively has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              private populateValuesRecursively(
                entity: ActualVsScenarioImpactTableRows,
                entityDataMap: Map<
                  string,
                  Map<number, ActualVsScenarioImpactTableRowsValues>
            Severity: Minor
            Found in api/src/modules/impact/comparison/actual-vs-scenario.service.ts - 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

            Function getActualVsScenarioImpactTable has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async getActualVsScenarioImpactTable(
                dto: GetActualVsScenarioImpactTableDto,
                fetchSpecification: FetchSpecification,
              ): Promise<ActualVsScenarioPaginatedImpactTable> {
                const indicators: Indicator[] =
            Severity: Minor
            Found in api/src/modules/impact/comparison/actual-vs-scenario.service.ts - About 1 hr to fix

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

                private populateValuesRecursively(
                  entity: ActualVsScenarioImpactTableRows,
                  entityDataMap: Map<
                    string,
                    Map<number, ActualVsScenarioImpactTableRowsValues>
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 185..261

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

              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

                private buildActualVsScenarioImpactTable(
                  queryDto: GetActualVsScenarioImpactTableDto,
                  indicators: Indicator[],
                  dataForImpactTable: ActualVsScenarioImpactTableData[],
                  entityTree: ImpactTableEntityType[],
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 106..179

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

              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 3 locations. Consider refactoring.
              Open

                private sortEntitiesRecursively(
                  rows: ActualVsScenarioImpactTableRows[],
                  sortingYear: number,
                  sortingOrder: ORDER_BY,
                ): void {
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 476..500
              api/src/modules/impact/impact.service.ts on lines 455..475

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

              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 3 locations. Consider refactoring.
              Open

                private sortEntitiesByImpactOfYear(
                  impactTable: ActualVsScenarioImpactTable,
                  sortingYear: number | undefined,
                  sortingOrder: ORDER_BY | undefined = ORDER_BY.ASC,
                ): void {
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 456..472
              api/src/modules/impact/impact.service.ts on lines 435..451

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

              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 3 locations. Consider refactoring.
              Open

                private createActualVsScenarioImpactTableDataByIndicator(
                  indicator: Indicator,
                  groupBy: GROUP_BY_VALUES,
                ): ActualVsScenarioImpactTableDataByIndicator {
                  return {
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 516..528
              api/src/modules/impact/impact.service.ts on lines 487..499

              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 3 locations. Consider refactoring.
              Open

                private getYearAbsoluteDifference(
                  row: ActualVsScenarioImpactTableRows,
                  year: number,
                ): number {
                  const yearValue: ActualVsScenarioImpactTableRowsValues | undefined =
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 504..514
              api/src/modules/impact/impact.service.ts on lines 479..485

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

              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

              There are no issues that match your filters.

              Category
              Status