Genese complexity report

<- ast-node.model.ts
Methods : 13
Complexity index : 85.8
Cyclomatic complexity : 37
Cognitive complexity
69.2 % Correct 9/13
30.8 % Warning 4/13 (threshold : 10)
0 % Error 0/13 (threshold : 20)
Cyclomatic complexity
92.3 % Correct 12/13
0 % Warning 0/13 (threshold : 5)
7.7 % Error 1/13 (threshold : 10)
Methods of ast-node.model.ts
evaluate Complexity Index 5.2 Cyclomatic complexity 2
                            
                                
                
            
            
                // ---------------------------------------------------------------------------------
                //                                  Other methods
                // ---------------------------------------------------------------------------------
            
            
                /**
                 * Evaluates the complexity factors of this AstNode and its children
                 */
                evaluate(): void { // ------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    this.calculateAndSetCpxFactors(); // ------------------------------------------------------ +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.addParentCpx(); // ------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    for (const child of this._children) { // -------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        child.evaluate(); // ------------------------------------------------------------------ +1.2 Complexity index (+0.2 atomic, +1 structural)
                    }
                }
            
                            
                        
getSon Complexity Index 0.7 Cyclomatic complexity 1
                            
                                
                
            
                /**
                 * Gets the xth son of this AstNode
                 * @param sonNumber     // The number of the son (0 for the first one)
                 */
                getSon(sonNumber: number): AstNode { // ----------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    return this.children[sonNumber]; // ----------------------------------------- +0.4 Complexity index (+0.4 atomic)
                }
            
                            
                        
calculateAndSetCpxFactors Complexity Index 11.8 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Calculates the complexity factors of the AstNode
                 */
                calculateAndSetCpxFactors(): CpxFactors { // -------------------------- +0.2 Complexity index (+0.2 atomic)
                    this.cpxFactors = new CpxFactors(); // ---------------------------- +0.5 Complexity index (+0.5 atomic)
                    this.setGeneralCaseCpxFactors(); // ------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.setFunctionStructuralCpx(); // ------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.setRecursionOrCallbackCpxFactors(); // ----------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.setElseCpxFactors(); // -------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.setRegexCpxFactors(); // ------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.setDepthCpxFactors(); // ------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.setAggregationCpxFactors(); // ------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.intrinsicNestingCpx = this.cpxFactors.totalNesting; // ------- +0.6 Complexity index (+0.6 atomic)
                    this.intrinsicDepthCpx = this.cpxFactors.totalDepth; // ----------- +0.6 Complexity index (+0.6 atomic)
                    this.forceCpxFactors(); // ---------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    return this._cpxFactors; // --------------------------------------- +0.3 Complexity index (+0.3 atomic)
                }
            
                            
                        
setGeneralCaseCpxFactors Complexity Index 3.5 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Sets the nesting and structural complexities for "usual" cases
                 */
                private setGeneralCaseCpxFactors(): void{ // ----------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    this.cpxFactors.nesting[this.factorCategory] = cpxFactors.nesting[this.factorCategory]; // --------------- +1.0 Complexity index (+1.0 atomic)
                    this.cpxFactors.structural[this.factorCategory] = cpxFactors.structural[this.factorCategory]; // --------- +1.0 Complexity index (+1.0 atomic)
                    this.cpxFactors.atomic.node = cpxFactors.atomic[this.factorCategory] ?? cpxFactors.atomic.node; // ------- +1.3 Complexity index (+1.3 atomic)
                }
            
                            
                        
setFunctionStructuralCpx Complexity Index 4.3 Cyclomatic complexity 4
                            
                                
            
                private setFunctionStructuralCpx(): void { // ------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    if (this.type === 'function' && this.parent?.kind !== SyntaxKind.MethodDeclaration) { // ------- +3.3 Complexity index (+1.3 atomic, +2 structural)
                        this.cpxFactors.structural.method = cpxFactors.structural.method; // ----------------------- +0.8 Complexity index (+0.8 atomic)
                    }
                }
            
                            
                        
forceCpxFactors Complexity Index 11.2 Cyclomatic complexity 4
                            
                                
                
            
            
                private forceCpxFactors(): void { // ----------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    if (this.cpxFactorsFromJsonAST) { // ------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        for (const category of Object.keys(this.cpxFactorsFromJsonAST)) { // ------------------------------- +3.1 Complexity index (+0.6 atomic, +0.5 nesting, +2 structural)
                            for (const factor of Object.keys(this.cpxFactorsFromJsonAST[category])) { // ------------------- +3.7 Complexity index (+0.7 atomic, +1 nesting, +2 structural)
                                this.cpxFactors[category][factor] = this.cpxFactorsFromJsonAST[category][factor]; // ------- +2.9 Complexity index (+0.9 atomic, +2 aggregation)
                            }
                        }
                    }
                }
            
                            
                        
setDepthCpxFactors Complexity Index 3.4 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Sets depth complexity factor
                 * Example : array in array, like a[b[c]]
                 */
                private setDepthCpxFactors(): void { // ---------------------------- +0.2 Complexity index (+0.2 atomic)
                    if (Ast.isArrayIndex(this)) { // ------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        this.cpxFactors.depth.arr = cpxFactors.depth.arr; // ------- +0.8 Complexity index (+0.8 atomic)
                    }
                }
            
                            
                        
setAggregationCpxFactors Complexity Index 6.6 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Sets aggregation complexity factor
                 */
                private setAggregationCpxFactors(): void { // ---------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    if (Ast.isArrayOfArray(this)) { // ----------------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        this.cpxFactors.aggregation.arr = cpxFactors.aggregation.arr; // ------------------------------------- +0.8 Complexity index (+0.8 atomic)
                    } else if (Ast.isDifferentLogicDoor(this)) { // ---------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        this.cpxFactors.aggregation.differentLogicDoor = cpxFactors.aggregation.differentLogicDoor; // ------- +0.8 Complexity index (+0.8 atomic)
                    }
                }
            
                            
                        
setElseCpxFactors Complexity Index 6.4 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Sets complexity factor for "else" case
                 */
                private setElseCpxFactors(): void { // ------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    if (Ast.isElseStatement(this)) { // ------------------------------------------------------ +2.4 Complexity index (+0.4 atomic, +2 structural)
                        this.cpxFactors.structural.conditional = cpxFactors.structural.conditional; // ------- +0.8 Complexity index (+0.8 atomic)
                    }
                    if (Ast.isElseIfStatement(this)) { // ---------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        this.cpxFactors.nesting.conditional = 0; // ------------------------------------------ +0.6 Complexity index (+0.6 atomic)
                    }
                }
            
                            
                        
setRecursionOrCallbackCpxFactors Complexity Index 4.6 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Sets complexity factor for callbacks and recursions
                 */
                private setRecursionOrCallbackCpxFactors(): void { // --------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    this.cpxFactors.recursion.recursivity = this.isRecursiveMethod ? cpxFactors.recursion.recursivity : 0; // ------- +2.2 Complexity index (+1.2 atomic, +1 structural)
                    this.cpxFactors.recursion.callback = this.isCallback ? cpxFactors.recursion.callback : 0; // -------------------- +2.2 Complexity index (+1.2 atomic, +1 structural)
                }
            
                            
                        
setRegexCpxFactors Complexity Index 4.4 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Sets complexity factor for regex
                 */
                private setRegexCpxFactors(): void { // -------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    if (this.factorCategory === NodeFeature.REGEX) { // ---------------------------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        this.cpxFactors.aggregation.regex = +((this['text'].length - 2) * cpxFactors.aggregation.regex).toFixed(2); // ------- +2.6 Complexity index (+1.6 atomic, +1 structural)
                    }
                }
            
                            
                        
addParentCpx Complexity Index 13.1 Cyclomatic complexity 12
                            
                                
                
            
            
                /**
                 * Sets the global nesting cpx of the node (the cpx from the node itself and from its parents)
                 */
                private addParentCpx(): void { // ------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    if (this && this.parent && this.parent?.cpxFactors?.nesting) { // ------------------------------------------- +4.2 Complexity index (+1.2 atomic, +3 structural)
                        this.cpxFactors.nesting = addObjects(this.parent.cpxFactors.nesting, this.cpxFactors.nesting); // ------- +2.2 Complexity index (+1.2 atomic, +1 structural)
                    }
                    if (this && this.parent?.parent && this.parent?.cpxFactors?.depth) { // ------------------------------------- +4.3 Complexity index (+1.3 atomic, +3 structural)
                        this.cpxFactors.depth = addObjects(this.parent.cpxFactors.depth, this.cpxFactors.depth); // ------------- +2.2 Complexity index (+1.2 atomic, +1 structural)
                    }
                }
            
                            
                        
logg Complexity Index 10.6 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Logs the main information about the AstNode
                 * @param message
                 */
                logg(message?: string): void { // ------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    console.log('-----------------------------'); // ----------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    console.log(chalk.yellowBright(message ?? 'AST NODE')); // ------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                    console.log(this.kind, this.name); // ---------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    console.log('-----------------------------'); // ----------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    console.log('pos', this.pos, 'end', this.end); // ---------------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    console.log('text', this.text); // ------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                }