Genese complexity report

<- init-generation.service.ts
Methods : 4
Complexity index : 51.7
Cyclomatic complexity : 13
Cognitive complexity
75 % Correct 3/4
0 % Warning 0/4 (threshold : 10)
25 % Error 1/4 (threshold : 20)
Cyclomatic complexity
75 % Correct 3/4
25 % Warning 1/4 (threshold : 5)
0 % Error 0/4 (threshold : 10)
Methods of init-generation.service.ts
generateAll Complexity Index 4.9 Cyclomatic complexity 2
                            
                                
            
            
                /**
                 * Generates the AstFolder for a given folder
                 * The tree is generated according to the Abstract Syntax TreeNode (AST) of the folder
                 * @param  {string} path    // The path of the folder
                 * @param  {Language} language
                 * @returns JsonAstInterface
                 */
                generateAll(path: string, language: Language): JsonAstInterface { // ---------------------------- +0.6 Complexity index (+0.6 atomic)
                    if (!path) { // ----------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                        console.log('ERROR: no path.'); // ------------------------------------------------------ +1.3 Complexity index (+0.3 atomic, +1 structural)
                        return undefined; // -------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    }
                    return { // --------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        astFolder: this.generateAstFolder(path, language) // ------------------------------------ +1.5 Complexity index (+0.5 atomic, +1 structural)
                    };
                }
            
                            
                        
generateAstFolderFromString Complexity Index 2.9 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Generates the AstFolder for the given source code
                 * @param sourceCode
                 * @returns {{astFolder: {path: string, astFiles: AstFileInterface[]}}}
                 */
                generateAstFolderFromString(sourceCode: string): JsonAstInterface { // ----------- +0.4 Complexity index (+0.4 atomic)
                    sourceCode = `${sourceCode}\n` // -------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    const astFileGenerationService = new AstFileGenerationService(); // ---------- +0.4 Complexity index (+0.4 atomic)
                    return { // ------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                        astFolder: { // ---------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                            path: '', // --------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                            astFiles: [ // ------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                                astFileGenerationService.generateFromString(sourceCode) // ------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                            ]
                        }
                    }
                }
            
                            
                        
generateAstFolder Complexity Index 39.1 Cyclomatic complexity 7
                            
                                
                
            
            
                /**
                 * Generates the AstFolder corresponding to a given path and to its potential AstFolder parent
                 * @param  {string} path              // The path of the AstFolder
                 * @param  {Language} language
                 * @returns AstFolderInterface
                 */
                private generateAstFolder(path: string, language: Language): AstFolderInterface { // ----------------------- +2.6 Complexity index (+0.6 atomic, +2 recursivity)
                    let astFolder: AstFolderInterface = { // --------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        path: platformPath(path), // ----------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        astFiles: [] // ------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                    };
                    let initService; // ------------------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    switch (language) { // --------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                        case Language.JS: // ------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        case Language.TS: // ------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        case Language.JSX: // ------------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                        case Language.TSX: // ------------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                            initService = new AstFileGenerationService(); // ----------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                            break
                        case Language.JAVA: // ----------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                            initService = new AstFileGenerationJavaService(); // ------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                            break
                        default: // ---------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                            initService = new AstFileGenerationService(); // ----------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    }
                    const filesOrDirs = fs.readdirSync(path); // ----------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    let currentFile = undefined; // ------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                    try {
                        filesOrDirs.forEach((elementName: string) => { // -------------------------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                            const pathElement = path + elementName; // ----------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                            currentFile = pathElement; // ------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                            if (!Options.isIgnored(pathElement)) { // ------------------------------------------------------ +3.4 Complexity index (+0.4 atomic, +1 nesting, +2 structural)
                                if (fs.statSync(pathElement).isDirectory() && !LIMIT_GENERATIONS) { // --------------------- +6.3 Complexity index (+0.8 atomic, +1.5 nesting, +4 structural)
                                    astFolder.children = astFolder.children ?? []; // -------------------------------------- +0.6 Complexity index (+0.6 atomic)
                                    astFolder.children.push(this.generateAstFolder(`${pathElement}/`, language)); // ------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                                } else if (this.isFileToGenerate(pathElement, language)) { // ------------------------------ +2.5 Complexity index (+0.5 atomic, +2 structural)
                                    astFolder.astFiles.push(initService.generate(pathElement, astFolder)); // -------------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                                }
                            }
                        });
                    } catch (e) { // --------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                        const [err, lines] = e.message.split('!!!'); // ---------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                        if (lines) { // ------------------------------------------------------------------------------------ +1.7 Complexity index (+0.2 atomic, +0.5 nesting, +1 structural)
                            console.log(`Error in file: ${currentFile}\nAt line ${lines}`); // ----------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        }
                        const error = new Error(err); // ------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                        error.stack = e.stack; // -------------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                        throw error; // ------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                    }
                    return astFolder; // ----------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
isFileToGenerate Complexity Index 4.8 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Returns true if a path corresponds to a file to generate in JsonAst
                 * @param  {string} path  // The path of the file
                 * @param  {Language} language
                 * @returns boolean
                 */
                private isFileToGenerate(path: string, language: Language): boolean { // ------------------------------ +0.5 Complexity index (+0.5 atomic)
                    return (getFileExtension(path) === language && !LIMIT_GENERATIONS) || path === DEV_MOCK; // ------- +4.3 Complexity index (+1.3 atomic, +3 structural)
                }