Genese complexity report

<- ast-folder.service.ts
Methods : 19
Complexity index : 116
Cyclomatic complexity : 42
Cognitive complexity
89.5 % Correct 17/19
10.5 % Warning 2/19 (threshold : 10)
0 % Error 0/19 (threshold : 20)
Cyclomatic complexity
100 % Correct 19/19
0 % Warning 0/19 (threshold : 5)
0 % Error 0/19 (threshold : 10)
Methods of ast-folder.service.ts
Complexity Index 1 Cyclomatic complexity 0
                            
                                
                
            
                constructor() {
                    super(); // --------------------------------------------------------------------------------------------------------- +1.0 Complexity index (+0.0 atomic, +1 structural)
                }
            
                            
                        
calculateStats Complexity Index 8.6 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Calculates the statistics of the AstFolder
                 * @param astFolder        // The AstFolder to analyse
                 */
                calculateStats(astFolder: AstFolder): Stats { // ------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    this._stats = new Stats(); // --------------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    this._stats.subject = astFolder.relativePath === '' ? astFolder.path : astFolder.relativePath; // ------- +2.3 Complexity index (+1.3 atomic, +1 structural)
                    this._stats.numberOfFiles = astFolder.numberOfFiles; // ------------------------------------------------- +0.6 Complexity index (+0.6 atomic)
                    this._stats.numberOfMethods = astFolder.numberOfMethods; // --------------------------------------------- +0.6 Complexity index (+0.6 atomic)
                    this._stats.totalCognitiveComplexity = astFolder.cpxFactors.total; // ----------------------------------- +0.7 Complexity index (+0.7 atomic)
                    this._stats.totalCyclomaticComplexity = astFolder.cyclomaticCpx; // ------------------------------------- +0.6 Complexity index (+0.6 atomic)
                    this.calculateAstFolderCpxByStatus(astFolder); // ------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    this._stats.setPercentages(); // ------------------------------------------------------------------------ +1.3 Complexity index (+0.3 atomic, +1 structural)
                    return this._stats; // ---------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                }
            
                            
                        
calculateAstFolderCpxByStatus Complexity Index 7.8 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Calculates and sets to _stats the Complexities by Status of a given AstFolder
                 * @param astFolder        // The AstFolder to analyse
                 */
                private calculateAstFolderCpxByStatus(astFolder: AstFolder): void { // -------------------- +2.4 Complexity index (+0.4 atomic, +2 recursivity)
                    for (const astFile of astFolder.astFiles) { // ---------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        this.calculateAstFileCpxByStatus(astFile); // ------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    }
                    for (const childAstFolder of astFolder.children) { // --------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        this.calculateAstFolderCpxByStatus(childAstFolder); // ---------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    }
                }
            
                            
                        
calculateAstFileCpxByStatus Complexity Index 8 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Increments AstFolder statistics for a given astFile
                 * @param astFile       // The AstFile to analyse
                 */
                private calculateAstFileCpxByStatus(astFile: AstFile): void { // ------------------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    this.incrementMethodsByStatus(ComplexityType.COGNITIVE, astFile.stats); // ---------------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    this.incrementMethodsByStatus(ComplexityType.CYCLOMATIC, astFile.stats); // --------------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    this._stats.barChartCognitive = BarchartService.concat(this._stats.barChartCognitive, astFile.stats.barChartCognitive); // ---------- +2.2 Complexity index (+1.2 atomic, +1 structural)
                    this._stats.barChartCyclomatic = BarchartService.concat(this._stats.barChartCyclomatic, astFile.stats.barChartCyclomatic); // ------- +2.2 Complexity index (+1.2 atomic, +1 structural)
                }
            
                            
                        
incrementMethodsByStatus Complexity Index 3.6 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Increments the number of methods spread by Status (correct, warning, error) and by complexity type
                 * @param type              // The complexity type
                 * @param tsFileStats
                 */
                private incrementMethodsByStatus(type: ComplexityType, tsFileStats: Stats): void { // -------------------------------- +0.6 Complexity index (+0.6 atomic)
                    this._stats.numberOfMethodsByStatus[type].correct += tsFileStats.numberOfMethodsByStatus[type].correct; // ------- +1.0 Complexity index (+1.0 atomic)
                    this._stats.numberOfMethodsByStatus[type].error += tsFileStats.numberOfMethodsByStatus[type].error; // ----------- +1.0 Complexity index (+1.0 atomic)
                    this._stats.numberOfMethodsByStatus[type].warning += tsFileStats.numberOfMethodsByStatus[type].warning; // ------- +1.0 Complexity index (+1.0 atomic)
                }
            
                            
                        
getNameOrPath Complexity Index 1 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Returns the relative path of an AstFolder
                 */
                protected getNameOrPath(astFolder: AstFolder): void { // ------- +0.4 Complexity index (+0.4 atomic)
                    this._stats.subject = astFolder.relativePath; // ----------- +0.6 Complexity index (+0.6 atomic)
                }
            
                            
                        
getNumberOfFiles Complexity Index 4 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Returns the number of files of an astFolder and its subfolders
                 * @param astFolder     // The astFolder to analyse
                 */
                getNumberOfFiles(astFolder: AstFolder): number { // ------------------------ +0.3 Complexity index (+0.3 atomic)
                    if (!astFolder?.astFiles) { // ----------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        return 0; // ------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    }
                    let nbFiles = astFolder.astFiles.length; // ---------------------------- +0.5 Complexity index (+0.5 atomic)
                    nbFiles += this.getChildrenFoldersNumberOfFiles(astFolder); // --------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    return nbFiles; // ----------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getChildrenFoldersNumberOfFiles Complexity Index 6.2 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Returns the number of files of the subfolders of a given AstFolder
                 * @param astFolder     // The astFolder to analyse
                 */
                private getChildrenFoldersNumberOfFiles(astFolder: AstFolder): number { // -------- +2.3 Complexity index (+0.3 atomic, +2 recursivity)
                    let nbFiles = 0; // ----------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    for (const childAstFolder of astFolder.children) { // ------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        nbFiles += childAstFolder.astFiles?.length; // ---------------------------- +0.5 Complexity index (+0.5 atomic)
                        nbFiles += this.getChildrenFoldersNumberOfFiles(childAstFolder); // ------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    }
                    return nbFiles; // ------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getNumberOfMethods Complexity Index 5 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Returns the number of methods of a given AstFolder
                 * @param astFolder     // The astFolder to analyse
                 */
                getNumberOfMethods(astFolder: AstFolder): number { // ------------------------- +0.3 Complexity index (+0.3 atomic)
                    if (!astFolder?.astFiles) { // -------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        return 0; // ---------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    }
                    let nbMethods = this.getCurrentFolderNumberOfMethods(astFolder); // ------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    nbMethods += this.getChildrenFoldersNumberOfMethods(astFolder); // -------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    return nbMethods; // ------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getCurrentFolderNumberOfMethods Complexity Index 2.9 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Returns the number of methods of a given AstFolder without its subfolders
                 * @param astFolder     // The astFolder to analyse
                 */
                private getCurrentFolderNumberOfMethods(astFolder: AstFolder): number { // ------------ +0.3 Complexity index (+0.3 atomic)
                    let nbMethods = 0; // ------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    for (const astFile of astFolder.astFiles) { // ------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                        nbMethods += astFile.astMethods?.length ?? 0; // ------------------------------ +0.7 Complexity index (+0.7 atomic)
                    }
                    return nbMethods; // -------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getChildrenFoldersNumberOfMethods Complexity Index 7.2 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Returns the number of methods of the subfolders of a given AstFolder
                 * @param astFolder     // The astFolder to analyse
                 */
                private getChildrenFoldersNumberOfMethods(astFolder: AstFolder): number { // ---------- +2.3 Complexity index (+0.3 atomic, +2 recursivity)
                    let nbMethods = 0; // ------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    for (const childAstFolder of astFolder.children) { // ----------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        nbMethods += this.getCurrentFolderNumberOfMethods(childAstFolder); // --------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                        nbMethods += this.getChildrenFoldersNumberOfMethods(childAstFolder); // ------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    }
                    return nbMethods; // -------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getRelativePath Complexity Index 4.2 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Returns the route from the root ancestor to the folder of a given AstFolder
                 * @param astFolder     // The astFolder to analyse
                 */
                getRelativePath(astFolder: AstFolder): string { // -------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    return astFolder?.path?.slice(this.getRootPath(astFolder).length); // --------------- +3.8 Complexity index (+0.8 atomic, +2 structural, +1 use)
                }
            
                            
                        
getAstFolderRoot Complexity Index 5.4 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Returns the ancestor of all the astFolders
                 * @param astFolder     // The astFolder to analyse
                 */
                private getAstFolderRoot(astFolder: AstFolder): AstFolder { // ------- +2.4 Complexity index (+0.4 atomic, +2 recursivity)
                    if (!astFolder?.parent) { // ------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        return astFolder; // ----------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    }
                    return this.getAstFolderRoot(astFolder.parent); // --------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                }
            
                            
                        
getRootPath Complexity Index 1.9 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Returns the path of the ancestor of all the astFolders
                 * @param astFolder     // The astFolder to analyse
                 */
                private getRootPath(astFolder: AstFolder): string { // ------------- +0.4 Complexity index (+0.4 atomic)
                    return this.getAstFolderRoot(astFolder)?.path; // -------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                }
            
                            
                        
getRouteFromFolderToFile Complexity Index 15 Cyclomatic complexity 4
                            
                                
                
            
            
                /**
                 * Returns the path between a AstFolder's path and a AstFile's path which is inside it or inside one of its subfolders
                 * @param astFolder      // The path of the AstFolder
                 * @param astFile        // The path of the AstFile
                 */
                getRouteFromFolderToFile(astFolder: AstFolder, astFile: AstFile): string { // --------------------------------------------------- +0.6 Complexity index (+0.6 atomic)
                    if (!astFile || !astFolder) { // -------------------------------------------------------------------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                        return undefined; // ---------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    }
                    if (astFile.astFolder.path.slice(0, astFolder.path.length) !== astFolder.path) { // ----------------------------------------- +4.2 Complexity index (+1.2 atomic, +2 structural, +1 use)
                        console.log(`The file ${astFile.name} is not inside the folder ${astFolder.path}`); // ---------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        return undefined; // ---------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    } else { // ----------------------------------------------------------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                        const linkStarter = this.getLinkStarter(astFolder); // ------------------------------------------------------------------ +1.5 Complexity index (+0.5 atomic, +1 structural)
            
                        return `${linkStarter}${astFile.astFolder.path.slice( // ---------------------------------------------------------------- +2.6 Complexity index (+0.6 atomic, +1 structural, +1 use)
                            astFolder.path.length + 1 // ---------------------------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                        )}`;
            
                    }
                }
            
                            
                        
getLinkStarter Complexity Index 6.7 Cyclomatic complexity 2
                            
                                
                
            
                getLinkStarter(astFolder: AstFolder) { // ------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                    return getOS() !== OS.WINDOWS ? "./" : astFolder?.relativePath === "" ? "./" : "" // ------- +6.4 Complexity index (+1.4 atomic, +2 nesting, +3 structural)
                }
            
                            
                        
getRouteFromFolderToSubFolder Complexity Index 15.6 Cyclomatic complexity 5
                            
                                
                
            
                /**
                 * Returns the route from the folder of a AstFolder to one of its subfolders
                 * @param astFolder
                 * @param astSubfolder
                 */
                getRouteFromFolderToSubFolder(astFolder: AstFolder, astSubfolder: AstFolder): string { // ---------------- +0.6 Complexity index (+0.6 atomic)
                    if (!astFolder || !astSubfolder|| astSubfolder.path === astFolder.path ) { // ------------------------ +4.2 Complexity index (+1.2 atomic, +3 structural)
                        return undefined; // ----------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    }
                    if (astSubfolder.path.slice(0, astFolder.path.length) !== astFolder.path) { // ----------------------- +4.1 Complexity index (+1.1 atomic, +2 structural, +1 use)
                        console.log(`The folder ${astSubfolder.path} is not a subfolder of ${astFolder.path}`); // ------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        return undefined; // ----------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    } else { // ------------------------------------------------------------------------------------------ +1.1 Complexity index (+0.1 atomic, +1 structural)
            
                        const linkStarter = this.getLinkStarter(astFolder); // ------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
            
                        const finalLink = `${linkStarter}${this.linkSlicer( // ------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                            astSubfolder.path, // ------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                            astFolder.path // ---------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                        )}`;
            
                        return finalLink; // ----------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    }
                }
            
                            
                        
isSlashExist Complexity Index 3.5 Cyclomatic complexity 1
                            
                                
                
            
                isSlashExist(text: string, parentText: string) { // ------------------------------------ +0.5 Complexity index (+0.5 atomic)
                    return constructLink(text[parentText.length + 1]) === constructLink("/"); // ------- +3.0 Complexity index (+1.0 atomic, +2 structural)
                }
            
                            
                        
linkSlicer Complexity Index 8.4 Cyclomatic complexity 1
                            
                                
                
            
                linkSlicer(text: string, parentText: string): string { // ------- +0.6 Complexity index (+0.6 atomic)
                    return this.isSlashExist(text, parentText) // --------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
                        ? text.slice(parentText.length + 2) // ------------------ +2.6 Complexity index (+0.6 atomic, +1 structural, +1 use)
                        : text.slice(parentText.length + 1); // ----------------- +2.6 Complexity index (+0.6 atomic, +1 structural, +1 use)
                }