Vizzuality/landgriffon

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

Summary

Maintainability
F
1 wk
Test Coverage

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

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

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

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

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

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

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

          private postProcessYearIndicatorData(
            entityMap: Map<
              string,
              Map<number, ScenarioVsScenarioImpactTableRowsValues>
            >,
        Severity: Minor
        Found in api/src/modules/impact/comparison/scenario-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 getScenarioVsScenarioImpactTable has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

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

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

            private calculateIndicatorSumByYear(
              entityMap: Map<
                string,
                Map<number, ScenarioVsScenarioImpactTableRowsValues>
              >,
          Severity: Minor
          Found in api/src/modules/impact/comparison/scenario-vs-scenario.service.ts - About 1 hr to fix

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

              private populateValuesRecursively(
                entity: ScenarioVsScenarioImpactTableRows,
                entityDataMap: Map<
                  string,
                  Map<number, ScenarioVsScenarioImpactTableRowsValues>
            Severity: Minor
            Found in api/src/modules/impact/comparison/scenario-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 postProcessYearIndicatorData has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              private postProcessYearIndicatorData(
                entityMap: Map<
                  string,
                  Map<number, ScenarioVsScenarioImpactTableRowsValues>
                >,
            Severity: Minor
            Found in api/src/modules/impact/comparison/scenario-vs-scenario.service.ts - About 1 hr to fix

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

                private populateValuesRecursively(
                  entity: ScenarioVsScenarioImpactTableRows,
                  entityDataMap: Map<
                    string,
                    Map<number, ScenarioVsScenarioImpactTableRowsValues>
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 275..344

              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 buildImpactTable(
                  queryDto: GetScenarioVsScenarioImpactTableDto,
                  indicators: Indicator[],
                  dataForImpactTable: ScenarioVsScenarioImpactTableData[],
                  entityTree: ImpactTableEntityType[],
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 87..160

              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: ScenarioVsScenarioImpactTableRows[],
                  sortingYear: number,
                  sortingOrder: ORDER_BY,
                ): void {
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 382..406
              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 2 locations. Consider refactoring.
              Open

                private buildScenarioVsScenarioImpactTableRowsSkeleton(
                  entities: ImpactTableEntityType[],
                ): ScenarioVsScenarioImpactTableRows[] {
                  return entities.map((item: ImpactTableEntityType) => {
                    return {
              api/src/modules/impact/impact.service.ts on lines 379..392

              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: ScenarioVsScenarioImpactTable,
                  sortingYear: number | undefined,
                  sortingOrder: ORDER_BY | undefined = ORDER_BY.ASC,
                ): void {
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 362..378
              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 createScenarioVsScenarioImpactTableDataByIndicator(
                  indicator: Indicator,
                  groupBy: GROUP_BY_VALUES,
                ): ScenarioVsScenarioImpactTableDataByIndicator {
                  return {
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 422..434
              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: ScenarioVsScenarioImpactTableRows,
                  year: number,
                ): number {
                  const yearValue: ScenarioVsScenarioImpactTableRowsValues | undefined =
              api/src/modules/impact/comparison/actual-vs-scenario.service.ts on lines 410..420
              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