Vizzuality/landgriffon

View on GitHub
api/src/modules/impact/impact.service.ts

Summary

Maintainability
F
4 days
Test Coverage
A
97%

File impact.service.ts has 377 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Injectable, Logger } from '@nestjs/common';
import {
  GetImpactTableDto,
  GetRankedImpactTableDto,
  GROUP_BY_VALUES,
Severity: Minor
Found in api/src/modules/impact/impact.service.ts - About 5 hrs to fix

    Function buildImpactTable has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private buildImpactTable(
        queryDto: GetImpactTableDto,
        indicators: Indicator[],
        dataForImpactTable: ImpactTableData[],
        entityTree: ImpactTableEntityType[],
    Severity: Minor
    Found in api/src/modules/impact/impact.service.ts - About 1 hr to fix

      Function applyRankingProcessing has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async applyRankingProcessing(
          rankedImpactTableDto: GetRankedImpactTableDto,
          impactTable: ImpactTable,
        ): Promise<ImpactTable> {
          // Since it's a TOP ranking, DESCENDENT sort will be the default if no sort option is provided
      Severity: Minor
      Found in api/src/modules/impact/impact.service.ts - About 1 hr to fix

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

          private populateValuesRecursively(
            entity: ImpactTableRows,
            entityMap: Map<string, Map<number, ImpactTableRowsValues>>,
            rangeOfYears: number[],
          ): ImpactTableRowsValues[] {
        Severity: Minor
        Found in api/src/modules/impact/impact.service.ts - About 1 hr to fix

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

            private postProcessYearIndicatorData(
              rangeOfYears: number[],
              lastYearWithData: number,
              entityMap: Map<string, Map<number, ImpactTableRowsValues>>,
            ): Map<number, number> {
          Severity: Minor
          Found in api/src/modules/impact/impact.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 getImpactTable has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async getImpactTable(
              impactTableDto: GetImpactTableDto,
              fetchSpecification: FetchSpecification,
            ): Promise<PaginatedImpactTable> {
              const indicators: Indicator[] =
          Severity: Minor
          Found in api/src/modules/impact/impact.service.ts - About 1 hr to fix

            Function getRankedImpactTable has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async getRankedImpactTable(
                rankedImpactTableDto: GetRankedImpactTableDto,
              ): Promise<ImpactTable> {
                const indicators: Indicator[] =
                  await this.indicatorService.getIndicatorsById(
            Severity: Minor
            Found in api/src/modules/impact/impact.service.ts - About 1 hr to fix

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

                private static processImpactDataWithScenario(
                  dataForImpactTableWithScenario: ImpactTableData[],
                ): ImpactTableData[] {
                  // Separate the data into different groups depending on whether data is from a scenario or not
                  const actualData: Map<string, ImpactTableData> = new Map();
              Severity: Minor
              Found in api/src/modules/impact/impact.service.ts - 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 populateValuesRecursively has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                private populateValuesRecursively(
                  entity: ImpactTableRows,
                  entityMap: Map<string, Map<number, ImpactTableRowsValues>>,
                  rangeOfYears: number[],
                ): ImpactTableRowsValues[] {
              Severity: Minor
              Found in api/src/modules/impact/impact.service.ts - About 25 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

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

                private sortEntitiesRecursively(
                  impactTableRows: ImpactTableRows[],
                  sortingYear: number,
                  sortingOrder: ORDER_BY,
                ): void {
              Severity: Major
              Found in api/src/modules/impact/impact.service.ts and 2 other locations - About 6 hrs to fix
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 382..406
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 476..500

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

                private buildImpactTableRowsSkeleton(
                  entities: ImpactTableEntityType[],
                ): ImpactTableRows[] {
                  return entities.map((item: ImpactTableEntityType) => {
                    return {
              Severity: Major
              Found in api/src/modules/impact/impact.service.ts and 1 other location - About 3 hrs to fix
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 263..276

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

              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: ImpactTable,
                  sortingYear: number | undefined,
                  sortingOrder: ORDER_BY | undefined = ORDER_BY.DESC,
                ): void {
              Severity: Major
              Found in api/src/modules/impact/impact.service.ts and 2 other locations - About 2 hrs to fix
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 362..378
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 456..472

              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 createImpactTableDataByIndicator(
                  indicator: Indicator,
                  groupBy: GROUP_BY_VALUES,
                ): ImpactTableDataByIndicator {
                  return {
              Severity: Major
              Found in api/src/modules/impact/impact.service.ts and 2 other locations - About 2 hrs to fix
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 422..434
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 516..528

              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 getYearImpact(row: ImpactTableRows, year: number): number {
                  const yearValue: ImpactTableRowsValues | undefined = row.values.find(
                    (value: ImpactTableRowsValues) => value.year === year,
                  );
              
              
              Severity: Major
              Found in api/src/modules/impact/impact.service.ts and 2 other locations - About 2 hrs to fix
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 410..420
              api/src/modules/impact/comparison/scenario-vs-scenario.service.ts on lines 504..514

              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

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

                  for (const data of scenarioData) {
                    const matchingRealData: ImpactTableData | undefined = actualData.get(
                      BaseImpactService.getImpactTableDataKey(data),
                    );
              
              
              Severity: Major
              Found in api/src/modules/impact/impact.service.ts and 1 other location - About 1 hr to fix
              api/src/modules/impact/base-impact.service.ts on lines 473..482

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

              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