betagouv/service-national-universel

View on GitHub
api/src/pdt/import/pdtImportService.ts

Summary

Maintainability
F
5 days
Test Coverage

Function validatePdtFile has a Cognitive Complexity of 220 (exceeds 5 allowed). Consider refactoring.
Open

export const validatePdtFile = async (
  filePath: string,
  cohortName: string,
  isCle: boolean,
): Promise<{
Severity: Minor
Found in api/src/pdt/import/pdtImportService.ts - About 4 days 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 validatePdtFile has 318 lines of code (exceeds 200 allowed). Consider refactoring.
Open

export const validatePdtFile = async (
  filePath: string,
  cohortName: string,
  isCle: boolean,
): Promise<{
Severity: Major
Found in api/src/pdt/import/pdtImportService.ts - About 5 hrs to fix

    Function computeImportSummary has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    export const computeImportSummary = (lines: PdtLine[]) => {
      const countPdr = getLinePdrCount(lines[0]);
      let maxPdrOnLine = 0;
      for (const line of lines.entries()) {
        const currentLinePDRCount = getLinePdrIds(line).length;
    Severity: Minor
    Found in api/src/pdt/import/pdtImportService.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

    Avoid deeply nested control flow statements.
    Open

            } else if (!["correspondance aller", "correspondance retour", "correspondance"].includes(line[`ID PDR ${pdrNumber}`]?.toLowerCase())) {
              errors[`ID PDR ${pdrNumber}`].push({ line: index, error: PDT_IMPORT_ERRORS.BAD_PDR_ID, extra: line[`ID PDR ${pdrNumber}`] });
            }
    Severity: Major
    Found in api/src/pdt/import/pdtImportService.ts - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                if (line["NUMERO DE LIGNE"] === mergedLine) {
                  found = true;
                  break;
                }
      Severity: Major
      Found in api/src/pdt/import/pdtImportService.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                  if (!pdr) {
                    errors[`ID PDR ${pdrNumber}`].push({ line: index, error: PDT_IMPORT_ERRORS.BAD_PDR_ID, extra: line[`ID PDR ${pdrNumber}`] });
                  } else if ((pdr?.department || "").toLowerCase() !== departmentLookUp[line[`N° DE DEPARTEMENT PDR ${pdrNumber}`]]?.toLowerCase()) {
                    errors[`ID PDR ${pdrNumber}`].push({ line: index, error: PDT_IMPORT_ERRORS.BAD_PDR_DEPARTEMENT, extra: line[`ID PDR ${pdrNumber}`] });
                  }
        Severity: Major
        Found in api/src/pdt/import/pdtImportService.ts - About 45 mins to fix

          There are no issues that match your filters.

          Category
          Status