Genese complexity report

<- ast-folder-report.service.ts
Methods : 12
Complexity index : 122.3
Cyclomatic complexity : 27
Cognitive complexity
58.3 % Correct 7/12
33.3 % Warning 4/12 (threshold : 10)
8.3 % Error 1/12 (threshold : 20)
Cyclomatic complexity
91.7 % Correct 11/12
8.3 % Warning 1/12 (threshold : 5)
0 % Error 0/12 (threshold : 10)
Methods of ast-folder-report.service.ts
Complexity Index 1.2 Cyclomatic complexity 0
                            
                                
                
            
            
                constructor(astFolder: AstFolder) { // ------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    this.astFolder = astFolder; // ----------------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    this.astFolderService.astFolder = this.astFolder; // ------------------------------------------------------------------------------- +0.6 Complexity index (+0.6 atomic)
                }
            
                            
                        
getFoldersArray Complexity Index 9.8 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Returns the array of subfolders with their analysis
                 * @param astFolder    // The AstFolder to analyse
                 */
                getFoldersArray(astFolder: AstFolder): RowFolderReport[] { // ----------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    let report: RowFolderReport[] = []; // ------------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    if (getPathWithSlash(this.astFolder.path) !== getPathWithSlash(Options.pathFolderToAnalyze)) { // ------- +3.9 Complexity index (+0.9 atomic, +3 structural)
                        report.push(this.addRowBackToParentFolder()); // ---------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                    }
                    return report.concat(this.getSubfoldersArray(astFolder)); // -------------------------------------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
                }
            
                            
                        
getSubfoldersArray Complexity Index 17.4 Cyclomatic complexity 7
                            
                                
                
            
            
                /**
                 * Recursion returning the array of subfolders reports
                 * @param astFolder        // The AstFolder to analyse
                 * @param isSubfolder       // True if astFolder is a subfolder (used for recursivity)
                 */
                getSubfoldersArray(astFolder: AstFolder, isSubfolder = false): RowFolderReport[] { // ------------------------ +2.7 Complexity index (+0.7 atomic, +2 recursivity)
                    let report: RowFolderReport[] = []; // ------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    for (const subfolder of astFolder.children) { // --------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        if (subfolder.relativePath !== '') { // -------------------------------------------------------------- +2.0 Complexity index (+0.5 atomic, +0.5 nesting, +1 structural)
                            const routeFromCurrentFolderBase = this.astFolderService.getRouteFromFolderToSubFolder( // ------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                                this.astFolder, // --------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                                subfolder // --------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                            );
                            const subfolderReport: RowFolderReport = { // ---------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                                complexitiesByStatus: subfolder.stats?.numberOfMethodsByStatus, // --------------------------- +0.4 Complexity index (+0.4 atomic)
                                numberOfFiles: subfolder.stats?.numberOfFiles, // -------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                                numberOfMethods: subfolder.stats?.numberOfMethods, // ---------------------------------------- +0.4 Complexity index (+0.4 atomic)
                                path: subfolder.relativePath, // ------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                                routeFromCurrentFolder: deleteLastSlash( // -------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                                    routeFromCurrentFolderBase // ------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                                ),
                            };
                            report.push(subfolderReport); // ----------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        }
                        if (!isSubfolder) { // ------------------------------------------------------------------------------- +1.7 Complexity index (+0.2 atomic, +0.5 nesting, +1 structural)
                            report = report.concat(this.getSubfoldersArray(subfolder, true)); // ----------------------------- +2.8 Complexity index (+0.8 atomic, +2 structural)
                        }
                    }
                    return report; // ---------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
addRowBackToParentFolder Complexity Index 1.3 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Adds a backLink to the parent folder
                 */
                addRowBackToParentFolder(): RowFolderReport { // ------- +0.2 Complexity index (+0.2 atomic)
                    return { // ---------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        complexitiesByStatus: undefined, // ------------ +0.2 Complexity index (+0.2 atomic)
                        numberOfFiles: undefined, // ------------------- +0.2 Complexity index (+0.2 atomic)
                        numberOfMethods: undefined, // ----------------- +0.2 Complexity index (+0.2 atomic)
                        path: '../', // -------------------------------- +0.2 Complexity index (+0.2 atomic)
                        routeFromCurrentFolder: '..' // ---------------- +0.2 Complexity index (+0.2 atomic)
            
                    };
                }
            
                            
                        
getFilesArray Complexity Index 13.9 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Returns the array of files with their analysis
                 * @param astFolder    // The AstFolder to analyse
                 */
                getFilesArray(astFolder: AstFolder): RowFileReport[] { // --------------------------- +0.5 Complexity index (+0.5 atomic)
                    let report: RowFileReport[] = []; // -------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    for (const tsFile of astFolder.astFiles) { // ----------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        for (const astMethod of tsFile.astMethods) { // ----------------------------- +1.9 Complexity index (+0.4 atomic, +0.5 nesting, +1 structural)
                            report.push({ // -------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                                cognitiveColor: astMethod.cognitiveStatus.toLowerCase(), // --------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                                cpxIndex: astMethod.cpxIndex, // ------------------------------------ +0.3 Complexity index (+0.3 atomic)
                                cyclomaticColor: astMethod.cyclomaticStatus.toLowerCase(), // ------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                                cyclomaticValue: astMethod.cyclomaticCpx, // ------------------------ +0.3 Complexity index (+0.3 atomic)
                                filename: tsFile.name, // ------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                                linkFile: this.getFileLink(tsFile), // ------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                                methodName: astMethod.name // --------------------------------------- +0.3 Complexity index (+0.3 atomic)
                            });
                        }
                    }
                    return report.sort((a, b) => b.cpxIndex - a.cpxIndex); // ----------------------- +3.1 Complexity index (+1.1 atomic, +2 structural)
                }
            
                            
                        
getMethodsArraySortedByDecreasingCognitiveCpx Complexity Index 3.4 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Returns the array of methods sorted by decreasing cognitive complexity
                 * @param astFolder    // The AstFolder to analyse
                 */
                getMethodsArraySortedByDecreasingCognitiveCpx(astFolder: AstFolder): RowFileReport[] { // ------- +0.5 Complexity index (+0.5 atomic)
                    const report = this.getMethodsArray(astFolder); // ------------------------------------------ +1.5 Complexity index (+0.5 atomic, +1 structural)
                    return this.sortByDecreasingCognitiveCpx(report); // ---------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                }
            
                            
                        
getMethodsArray Complexity Index 18.1 Cyclomatic complexity 4
                            
                                
                
            
            
                /**
                 * Recursion returning the array of methods reports of each subfolder
                 * @param astFolder    // The AstFolder to analyse
                 */
                getMethodsArray(astFolder: AstFolder): RowFileReport[] { // ----------------------------- +2.5 Complexity index (+0.5 atomic, +2 recursivity)
                    let report: RowFileReport[] = []; // ------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    for (const subfolder of astFolder.children) { // ------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                        for (const tsFile of subfolder.astFiles) { // ----------------------------------- +1.9 Complexity index (+0.4 atomic, +0.5 nesting, +1 structural)
                            for (const astMethod of tsFile.astMethods) { // ----------------------------- +2.4 Complexity index (+0.4 atomic, +1 nesting, +1 structural)
                                report.push({ // -------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                                    cognitiveColor: astMethod.cognitiveStatus.toLowerCase(), // --------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                                    cpxIndex: astMethod.cpxIndex, // ------------------------------------ +0.3 Complexity index (+0.3 atomic)
                                    cyclomaticColor: astMethod.cyclomaticStatus.toLowerCase(), // ------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                                    cyclomaticValue: astMethod.cyclomaticCpx, // ------------------------ +0.3 Complexity index (+0.3 atomic)
                                    filename: tsFile.name, // ------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                                    linkFile: this.getFileLink(tsFile), // ------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                                    methodName: astMethod.name // --------------------------------------- +0.3 Complexity index (+0.3 atomic)
                                })
                            }
                        }
                        report = report.concat(this.getMethodsArray(subfolder)); // --------------------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                    }
                    return report; // ------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
sortByDecreasingCognitiveCpx Complexity Index 3.7 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * The method sorting the rows of the methods report by decreasing cognitive complexity
                 * @param methodsReport     // The array to sort
                 */
                sortByDecreasingCognitiveCpx(methodsReport: MethodReport[]): MethodReport[] { // ----------------- +0.6 Complexity index (+0.6 atomic)
                    return methodsReport.sort((a, b) => b.cpxIndex - a.cpxIndex); // ----------------------------- +3.1 Complexity index (+1.1 atomic, +2 structural)
                }
            
                            
                        
generateReport Complexity Index 22.9 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Generates the folder's report
                 */
                generateReport(): void { // ---------------------------------------------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    const parentFolder: AstFolder = new AstFolder(); // ------------------------------------------------------------------------------------------------------------------ +0.5 Complexity index (+0.5 atomic)
                    parentFolder.children.push(this.astFolder); // ----------------------------------------------------------------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    this.relativeRootReports = getRouteToRoot(this.astFolder.relativePath); // ------------------------------------------------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                    this.filesArray = this.getFilesArray(this.astFolder); // ------------------------------------------------------------------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                    this.foldersArray = this.getFoldersArray(parentFolder); // ----------------------------------------------------------------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    this.methodsArray = this.getMethodsArraySortedByDecreasingCognitiveCpx(parentFolder); // ----------------------------------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    this.registerPartial("cognitiveBarchartScript", 'cognitive-barchart'); // -------------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    this.registerPartial("cyclomaticBarchartScript", 'cyclomatic-barchart'); // ------------------------------------------------------------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                    this.registerPartial("cognitiveDoughnutScript", 'cognitive-doughnut'); // -------------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    this.registerPartial("cyclomaticDoughnutScript", 'cyclomatic-doughnut'); // ------------------------------------------------------------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                    this.registerPartial("rowFolder", 'row-folders'); // ----------------------------------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    this.registerPartial("rowFile", 'row-files'); // --------------------------------------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    const reportTemplate = eol.auto(fs.readFileSync(`${Options.pathGeneseNodeJs}/json-ast-to-reports/templates/handlebars/folder-report.handlebars`, 'utf-8')); // ------- +2.9 Complexity index (+0.9 atomic, +2 structural)
                    this.template = Handlebars.compile(reportTemplate); // --------------------------------------------------------------------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    this.writeReport(); // ----------------------------------------------------------------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                }
            
                            
                        
writeReport Complexity Index 17.6 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Fills the HandleBar's template
                 */
                private writeReport() { // --------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    const template = this.template({ // -------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        colors: Options.colors, // ------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        filesArray: this.filesArray, // -------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        foldersArray: this.foldersArray, // ---------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        isRootFolder: this.isRootFolder, // ---------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        methodsArray: this.methodsArray, // ---------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        relativeRootReports: this.relativeRootReports, // -------------------------- +0.3 Complexity index (+0.3 atomic)
                        stats: this.astFolder.stats, // -------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                        thresholds: Options.getThresholds() // ------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    });
                    if (this.astFolder.relativePath) { // ------------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                        createRelativeDir(this.astFolder.relativePath); // ------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    }
                    const pathOutDir = constructLink(Options.pathOutDir); // ----------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    const relativePath = constructLink(this.astFolder.relativePath); // ------------ +1.6 Complexity index (+0.6 atomic, +1 structural)
                    const pathReport = `${deleteLastSlash(pathOutDir)}/${deleteLastSlash( // ------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                        relativePath // ------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                    )}/folder-report.html`;
                    try {
                        fs.writeFileSync(pathReport, template, { encoding: "utf-8" }); // ---------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    } catch (err) { // ------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                        console.log(err); // ------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    }
                }
            
                            
                        
registerPartial Complexity Index 5 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Registers a HandleBar's partial
                 * @param partialName
                 * @param filename
                 */
                private registerPartial(partialName: string, filename: string): void { // --------------------------------------------------------------------------------------- +0.6 Complexity index (+0.6 atomic)
                    const partial = eol.auto(fs.readFileSync(`${Options.pathGeneseNodeJs}/json-ast-to-reports/templates/handlebars/${filename}.handlebars`, 'utf-8')); // ------- +3.0 Complexity index (+1.0 atomic, +2 structural)
                    Handlebars.registerPartial(partialName, partial); // -------------------------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                }