Genese complexity report

<- init.service.ts
Methods : 9
Complexity index : 91.2
Cyclomatic complexity : 29
Cognitive complexity
55.6 % Correct 5/9
44.4 % Warning 4/9 (threshold : 10)
0 % Error 0/9 (threshold : 20)
Cyclomatic complexity
88.9 % Correct 8/9
11.1 % Warning 1/9 (threshold : 5)
0 % Error 0/9 (threshold : 10)
Methods of init.service.ts
generateAllFromJsonAst Complexity Index 13.4 Cyclomatic complexity 5
                            
                                
                
            
            
                /**
                 * Generates the AstFolder for a given folder
                 * The tree is generated according to the Abstract Syntax Tree (AST) of the folder
                 * @param jsonAst
                 */
                generateAllFromJsonAst(jsonAst: JsonAst): JsonAst { // ------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    const newJsonAst = new JsonAst(); // -------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    const astFolder = new AstFolder(); // ------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    astFolder.path = this.getPathFromJsonAstFolder(jsonAst.astFolder); // ----------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                    astFolder.astFiles = this.generateAstFiles(jsonAst.astFolder, astFolder); // ---------------------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    if (Array.isArray(jsonAst.astFolder?.children)) { // ---------------------------------------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
                        for (const child of jsonAst.astFolder?.children) { // ----------------------------------------- +2.0 Complexity index (+0.5 atomic, +0.5 nesting, +1 structural)
                            const newChild = this.generateChildrenAstFolder(child, astFolder); // --------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                            newChild.parent = jsonAst.astFolder; // --------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                            astFolder.children.push(newChild); // ----------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        }
                    }
                    newJsonAst.astFolder = astFolder; // -------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    return newJsonAst; // ----------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
generateChildrenAstFolder Complexity Index 11.1 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Generates the children of a given AstFolder with the property "children" of the JsonAst object
                 * @param astFolderFromJsonAst      // An element of the "children" property of the JsonAst (this property is an array). The first direct ancestor of this property which is not called "children" is the astFolder property at the root of the Json object
                 * @param parentAstFolder           // The parent AstFolder
                 */
                private generateChildrenAstFolder(astFolderFromJsonAst: any, parentAstFolder: AstFolder): AstFolder { // ------------------------------------------------------------------------------------------------------------------------------------------------------------- +2.6 Complexity index (+0.6 atomic, +2 recursivity)
                    const newAstFolder = new AstFolder(); // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    newAstFolder.path = this.getPathFromJsonAstFolder(astFolderFromJsonAst); // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    newAstFolder.parent = parentAstFolder; // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    newAstFolder.astFiles = this.generateAstFiles(astFolderFromJsonAst, newAstFolder); // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                    for (const childFolderFromJsonAst of astFolderFromJsonAst.children ?? []) { // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                        newAstFolder.children.push(this.generateChildrenAstFolder(childFolderFromJsonAst, newAstFolder)); // --------------------------------------------------------------------------------------------------------------------------------------------------------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                    }
                    return newAstFolder; // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
generateAstFiles Complexity Index 5.3 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Generates the AstFiles corresponding to a property "astFiles" in the JsonAst object
                 * @param astFolderFromJsonAst      // The father of the astFiles property in the JsonAst object
                 * @param astFolder                 // The AstFolder containing the astFiles
                 */
                private generateAstFiles(astFolderFromJsonAst: any, astFolder: AstFolder): AstFile[] { // ----------------- +0.7 Complexity index (+0.7 atomic)
                    const astFiles: AstFile[] = []; // -------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    for (const astFileFromJsonAst of astFolderFromJsonAst.astFiles) { // ---------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        astFiles.push(this.generateAstFile(astFileFromJsonAst, astFolder)); // ---------------------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
                    }
                    return astFiles; // ----------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
generateAstFile Complexity Index 19 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Generates the AstFile corresponding to an element of the array astFiles in the JsonAst object
                 * @param astFileFromJsonAst        // The element in the astFiles array in the JsonAst object
                 * @param astFolder                 // The astFolder containing the AstFile
                 */
                private generateAstFile(astFileFromJsonAst: any, astFolder: AstFolder): AstFile { // ---------------------------------------------------------- +0.6 Complexity index (+0.6 atomic)
                    if (!astFileFromJsonAst?.astNode) { // ---------------------------------------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        console.warn(astFileFromJsonAst.name ? `No AstNode for this file : ${astFileFromJsonAst.name}` : `AstFile without AstNode`); // ------- +3.2 Complexity index (+0.7 atomic, +0.5 nesting, +2 structural)
                        return undefined; // ------------------------------------------------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    }
                    const newAstFile = new AstFile(); // ------------------------------------------------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    newAstFile.name = astFileFromJsonAst.name; // --------------------------------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstFile.astFolder = astFolder; // ------------------------------------------------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    newAstFile.code = CodeService.getCode(astFileFromJsonAst.text); // ------------------------------------------------------------------------ +1.7 Complexity index (+0.7 atomic, +1 structural)
                    newAstFile.astNode = this.getFileAstNode(astFileFromJsonAst.astNode, newAstFile); // ------------------------------------------------------ +1.8 Complexity index (+0.8 atomic, +1 structural)
                    newAstFile.astNodes = this.astNodeService.flatMapAstNodes(newAstFile.astNode, [newAstFile.astNode]); // ----------------------------------- +2.0 Complexity index (+1.0 atomic, +1 structural)
                    newAstFile.astMethods = newAstFile.astNodes // -------------------------------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                        .filter(e => { // --------------------------------------------------------------------------------------------------------------------- +2.3 Complexity index (+0.3 atomic, +2 structural)
                            return Ast.isFunctionOrMethod(e) // ----------------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        })
                        .map(e => e.astMethod); // ------------------------------------------------------------------------------------------------------------ +2.5 Complexity index (+0.5 atomic, +2 structural)
                    return newAstFile; // --------------------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getFileAstNode Complexity Index 5.3 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Generates the AstNode of a given AstFile with the astNode property in the JsonAst object
                 * @param astNodeFromJsonAst        // The astNode property in the JsonAst object
                 * @param astFile                   // The AstFile corresponding to the returned astNode
                 */
                private getFileAstNode(astNodeFromJsonAst: any, astFile: AstFile): AstNode { // ---------------------- +0.6 Complexity index (+0.6 atomic)
                    const newAstNode = new AstNode(); // ------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    newAstNode.pos = 0; // --------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    newAstNode.end = astNodeFromJsonAst.end; // ------------------------------------------------------ +0.5 Complexity index (+0.5 atomic)
                    newAstNode.kind = SyntaxKind.SourceFile; // ------------------------------------------------------ +0.5 Complexity index (+0.5 atomic)
                    newAstNode.name = astNodeFromJsonAst.name; // ---------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstNode.astFile = astFile; // ----------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    newAstNode.children = this.generateAstNodes(astNodeFromJsonAst.children, newAstNode); // --------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    return newAstNode; // ---------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
generateAstNodes Complexity Index 7.8 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Generates the AstNodes which are the children of a given AstNode with the "children" property in the JsonAst object
                 * @param astNodesFromJsonAst       // The astNode property in the JsonAst object which have some children
                 * @param astParentNode             // The AstNode which contains the returned AstNode children
                 */
                private generateAstNodes(astNodesFromJsonAst: any[], astParentNode: AstNode): AstNode[] { // ------------------------------------ +0.8 Complexity index (+0.8 atomic)
                    if (!Array.isArray(astNodesFromJsonAst)) { // ------------------------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        return []; // ----------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    }
                    const newAstNodes: AstNode[] = []; // --------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    for (const astNodeFromJsonAst of astNodesFromJsonAst) { // ------------------------------------------------------------------ +1.3 Complexity index (+0.3 atomic, +1 structural)
                        newAstNodes.push(this.generateAstNode(astNodeFromJsonAst, astParentNode)); // ------------------------------------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
                    }
                    return newAstNodes; // ------------------------------------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
generateAstNode Complexity Index 17.8 Cyclomatic complexity 6
                            
                                
                
            
            
                /**
                 * Generates the AstNode corresponding to an astNode property in the JsonAst object
                 * @param astNodeFromJsonAst        // The astNode property in the JsonAst object
                 * @param astParentNode             // The AstNode parent of the AstNode to return
                 */
                private generateAstNode(astNodeFromJsonAst: any, astParentNode: AstNode): AstNode { // ------------- +0.6 Complexity index (+0.6 atomic)
                    const newAstNode = new AstNode(); // ----------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    newAstNode.astFile = astParentNode.astFile; // ------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstNode.cpxFactorsFromJsonAST = astNodeFromJsonAst.cpxFactors; // --------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstNode.end = astNodeFromJsonAst.end; // ---------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstNode.kind = astNodeFromJsonAst.kind; // -------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstNode.name = astNodeFromJsonAst.name; // -------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstNode.parent = astParentNode; // ---------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    newAstNode.pos = astNodeFromJsonAst.pos; // ---------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstNode.start = astNodeFromJsonAst.start; // ------------------------------------------------ +0.5 Complexity index (+0.5 atomic)
                    newAstNode.text = astNodeFromJsonAst.text; // -------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstNode.type = astNodeFromJsonAst.type; // -------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    newAstNode.children = this.generateAstNodes(astNodeFromJsonAst.children, newAstNode); // ------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    if (Ast.isFunctionOrMethod(astNodeFromJsonAst)) { // ------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        if (!newAstNode.name && newAstNode.firstSon?.kind === SyntaxKind.Identifier) { // ---------- +3.6 Complexity index (+1.1 atomic, +0.5 nesting, +2 structural)
                            newAstNode.name = newAstNode.children[0].name; // -------------------------------------- +0.7 Complexity index (+0.7 atomic)
                        }
                        newAstNode.astMethod = this.generateAstMethod(newAstNode); // ------------------------------ +1.6 Complexity index (+0.6 atomic, +1 structural)
                    } else { // ------------------------------------------------------------------------------------ +1.1 Complexity index (+0.1 atomic, +1 structural)
                        newAstNode.astMethod = astParentNode?.astMethod; // ---------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    }
                    return newAstNode; // -------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
generateAstMethod Complexity Index 6.6 Cyclomatic complexity 4
                            
                                
                
            
            
                /**
                 * Generates the AstMethod corresponding to an AstNode with kind corresponding to a FunctionDeclaration or a MethodDeclaration
                 * @param astMethodNode     // The AstNode which corresponds to a FunctionDeclaration or a MethodDeclaration
                 */
                private generateAstMethod(astMethodNode: AstNode): AstMethod { // ----------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    const astMethod = new AstMethod(); // ----------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    astMethod.astNode = astMethodNode; // ----------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    astMethod.astNode.text = this.astNodeService.getCode(astMethodNode); // ------------------------------------------------------------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    astMethod.codeLines = astMethodNode.astFile?.code?.lines?.slice(astMethodNode.linePos - 1, astMethodNode.lineEnd); // --------------- +3.4 Complexity index (+1.4 atomic, +1 structural, +1 use)
                    return astMethod; // ---------------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getPathFromJsonAstFolder Complexity Index 4.9 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Returns the path without slash corresponding to the "path" property of the JsonAst object
                 * @param jsonAstFolder
                 */
                private getPathFromJsonAstFolder(jsonAstFolder: any): string { // -------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    return jsonAstFolder?.path?.slice(-1) === '/' ? jsonAstFolder.path.slice(0, -1) : jsonAstFolder.path; // ------- +4.5 Complexity index (+1.5 atomic, +3 structural)
                }