Genese complexity report

<- log.service.ts
Methods : 8
Complexity index : 92.3
Cyclomatic complexity : 22
Cognitive complexity
62.5 % Correct 5/8
25 % Warning 2/8 (threshold : 10)
12.5 % Error 1/8 (threshold : 20)
Cyclomatic complexity
87.5 % Correct 7/8
12.5 % Warning 1/8 (threshold : 5)
0 % Error 0/8 (threshold : 10)
Methods of log.service.ts
logMethod Complexity Index 13.5 Cyclomatic complexity 4
                            
                                
            
            
            
            
                // ------------------------------------------------------------------------------------------------
                // -----------------------------------------   LOG AST   ------------------------------------------
                // ------------------------------------------------------------------------------------------------
            
            
            
                /**
                 * Logs all the AST of the AstNode of a given AstMethod
                 * This method runs, but is not yet used
                 */
                static logMethod(astMethod: AstMethod, logLines = false): void { // ------------------------------------------ +0.6 Complexity index (+0.6 atomic)
                    if (!astMethod?.astNode) { // ---------------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        console.log('Method undefined'); // ------------------------------------------------------------------ +1.3 Complexity index (+0.3 atomic, +1 structural)
                        return; // ------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    }
                    console.log('------------------------------------'); // -------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    console.log('METHOD ', astMethod.name, ' : ', astMethod.cpxIndex); // ------------------------------------ +1.8 Complexity index (+0.8 atomic, +1 structural)
                    console.log('------------------------------------'); // -------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    this.logAstNode(astMethod.astNode, ''); // --------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    this.logMethodChildren(astMethod.astNode, ' '); // ------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    if (logLines) { // --------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                        this.logCodeLines(astMethod.codeLines, astMethod.astNode); // ---------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    }
                }
            
                            
                        
logMethodChildren Complexity Index 7.2 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Logs the AST of the children asts
                 * This method runs, but is not yet used
                 * @ast // The ast to print
                 * @indent // the indentation to use for the print
                 */
                private static logMethodChildren(astNode: AstNode, indent: string) { // ------- +2.5 Complexity index (+0.5 atomic, +2 recursivity)
                    for (const childAst of astNode.children) { // ----------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        this.logAstNode(childAst, indent); // --------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        const newIndent = indent + '  '; // ----------------------------------- +0.5 Complexity index (+0.5 atomic)
                        this.logMethodChildren(childAst, newIndent); // ----------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    }
                }
            
                            
                        
logAstNode Complexity Index 40.3 Cyclomatic complexity 6
                            
                                
                
            
            
                /**
                 * Logs the AST of a AstNode with its complexity factors, its context and its parent
                 * @param astNode       // The AstNode to log
                 * @param indent        // The current indentation
                 */
                static logAstNode(astNode: AstNode, indent: string): void { // -------------------------------- +0.6 Complexity index (+0.6 atomic)
                    let color = ''; // ------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                    if (astNode.cpxFactors?.total < 0.5) { // ------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        color = 'white'; // ------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    } else { // ------------------------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                        color = astNode.cpxFactors?.total > 1 ? 'red' : 'yellow'; // -------------------------- +2.5 Complexity index (+1.0 atomic, +0.5 nesting, +1 structural)
                    }
                    let logs: string[] = []; // --------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    logs.push(indent); // --------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    logs.push(chalk[color](astNode.kind)); // ------------------------------------------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
                    logs = logs.concat(LogService.addLog('line', astNode.linePos)); // ------------------------ +2.9 Complexity index (+0.9 atomic, +2 structural)
                    logs = logs.concat(LogService.addLog('atomic', astNode.atomicCpx)); // -------------------- +2.9 Complexity index (+0.9 atomic, +2 structural)
                    logs = logs.concat(LogService.addLog('structural', astNode.structuralCpx)); // ------------ +2.9 Complexity index (+0.9 atomic, +2 structural)
                    logs = logs.concat(LogService.addLog('nesting', astNode.nestingCpx)); // ------------------ +2.9 Complexity index (+0.9 atomic, +2 structural)
                    logs = logs.concat(LogService.addLog('depth', astNode.depthCpx)); // ---------------------- +2.9 Complexity index (+0.9 atomic, +2 structural)
                    logs = logs.concat(LogService.addLog('aggregation', astNode.aggregationCpx)); // ---------- +2.9 Complexity index (+0.9 atomic, +2 structural)
                    logs = logs.concat(LogService.addLog('recursivity', astNode.recursionCpx)); // ------------ +2.9 Complexity index (+0.9 atomic, +2 structural)
                    logs.push('context :'); // ---------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    logs.push(chalk.blueBright(astNode.context?.name)); // ------------------------------------ +2.7 Complexity index (+0.7 atomic, +2 structural)
                    logs.push('parent :'); // ----------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    logs.push(chalk.greenBright(astNode.parent?.kind)); // ------------------------------------ +2.7 Complexity index (+0.7 atomic, +2 structural)
                    console.log(...logs) // ------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                }
            
                            
                        
logCodeLines Complexity Index 3.4 Cyclomatic complexity 2
                            
                                
                
            
            
                static logCodeLines(codeLines: CodeLine[] = [], methodAstNode: AstNode): void { // ------- +0.7 Complexity index (+0.7 atomic)
                    for (const line of codeLines) { // --------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        this.logCodeLine(line, methodAstNode); // ---------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    }
                }
            
                            
                        
logCodeLine Complexity Index 7 Cyclomatic complexity 1
                            
                                
                
            
            
                static logCodeLine(line: CodeLine, methodAstNode: AstNode): void { // ------------------------------------------------------------------ +0.6 Complexity index (+0.6 atomic)
                    console.log('LINE ', chalk.greenBright(line.issue), line.start, '-', line.end, line.isEndingWithBlockComments, line.text) // ------- +3.6 Complexity index (+1.6 atomic, +2 structural)
                    console.log(...this.logCodeLineNode(line, methodAstNode, methodAstNode.pos)); // --------------------------------------------------- +2.8 Complexity index (+0.8 atomic, +2 structural)
                }
            
                            
                        
logCodeLineNode Complexity Index 16.1 Cyclomatic complexity 4
                            
                                
                
            
            
                private static logCodeLineNode(line: CodeLine, astNode: AstNode, methodPosition: number, logs: string[] = []): string[] { // ------- +3.1 Complexity index (+1.1 atomic, +2 recursivity)
                    if (this.isAstNodeInCodeLine(astNode.start, line)) { // ------------------------------------------------------------------------ +2.6 Complexity index (+0.6 atomic, +2 structural)
                        logs.push(chalk.blueBright(astNode.kind)); // ------------------------------------------------------------------------------ +2.6 Complexity index (+0.6 atomic, +2 structural)
                        logs.push(astNode.start.toString()) // ------------------------------------------------------------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                    }
                    for (const childAstNode of astNode.children) { // ------------------------------------------------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                        if (childAstNode.start < line.end) { // ------------------------------------------------------------------------------------ +2.1 Complexity index (+0.6 atomic, +0.5 nesting, +1 structural)
                            this.logCodeLineNode(line, childAstNode, methodPosition, logs); // ----------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        }
                    }
                    return logs; // ---------------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
isAstNodeInCodeLine Complexity Index 2.5 Cyclomatic complexity 2
                            
                                
                
            
            
                private static isAstNodeInCodeLine(astNodeStart: number, line: CodeLine): boolean { // ------- +0.4 Complexity index (+0.4 atomic)
                    return astNodeStart >= line.start && astNodeStart <= line.end; // ------------------------ +2.1 Complexity index (+1.1 atomic, +1 structural)
                }
            
                            
                        
addLog Complexity Index 2.3 Cyclomatic complexity 1
                            
                                
                
            
                /**
                 * Adds a text with its value in a console.logg if the value is positive
                 * @param text      // The text to add
                 * @param value     // The corresponding value
                 */
                private static addLog(text: string, value: number): any[] { // -------------------- +0.6 Complexity index (+0.6 atomic)
                    return value > 0 ? [text, value] : []; // ------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                }