Genese complexity report

<- bigIfElse.refactorer.ts
Methods : 7
Complexity index : 119.9
Cyclomatic complexity : 19
Cognitive complexity
14.3 % Correct 1/7
71.4 % Warning 5/7 (threshold : 10)
14.3 % Error 1/7 (threshold : 20)
Cyclomatic complexity
100 % Correct 7/7
0 % Warning 0/7 (threshold : 5)
0 % Error 0/7 (threshold : 10)
Methods of bigIfElse.refactorer.ts
refactorNeeded Complexity Index 10.3 Cyclomatic complexity 1
                            
                                
                
            
                refactorNeeded(node: Node): boolean { // ------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    const IF_STATEMENTS = node.getDescendantsOfKind(SyntaxKind.IfStatement); // ---------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    return IF_STATEMENTS.some((i: IfStatement) => { // ----------------------------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
                        const BLOCKS = i.getDescendantsOfKind(SyntaxKind.Block); // ---------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        return BLOCKS.some((b: Block) => b.compilerNode.statements.length > 5); // ------- +4.2 Complexity index (+1.2 atomic, +1 nesting, +2 structural)
                    });
                }
            
                            
                        
refactor Complexity Index 48.5 Cyclomatic complexity 2
                            
                                
                
            
                /**
                 * Copy current method then transform the copy to get refctored method
                 * Put refactored method on current method object
                 * @param method the current method
                 * @returns {void}
                 */
                refactor(node: Node): Node { // ------------------------------------------------------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    let methods = []; // ------------------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    let parameters: Input[] = []; // ------------------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    let inputs: Input[] = []; // ----------------------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    const NODE = node.transform((traversal: TransformTraversalControl) => { // ------------------------------------------------------------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                        let currentNode: Node = Refactorer.wrapCurrentNode(node, traversal); // ------------------------------------------------------------ +1.7 Complexity index (+0.7 atomic, +1 structural)
                        this.catchInputs(currentNode, inputs); // ------------------------------------------------------------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                        if (this.isConditionnedBlock(currentNode)) { // ------------------------------------------------------------------------------------ +3.4 Complexity index (+0.4 atomic, +1 nesting, +2 structural)
                            currentNode.getDescendantsOfKind(SyntaxKind.VariableStatement).forEach((s) => { // --------------------------------------------- +5.2 Complexity index (+0.7 atomic, +1.5 nesting, +3 structural)
                                const IDENTIFIER: string = s.getFirstDescendantByKind(SyntaxKind.Identifier).getFullText(); // ----------------------------- +2.8 Complexity index (+0.8 atomic, +2 structural)
                                inputs = inputs.filter((i) => i.identifier !== IDENTIFIER); // ------------------------------------------------------------- +5.5 Complexity index (+1.0 atomic, +2.5 nesting, +2 structural)
                            });
            
                            this.keepOnlyParameters(currentNode, inputs, parameters); // ------------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
            
                            const METHOD_NAME = `methodToRename${methods.length}`; // ---------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                            const PARAMETERS = parameters.map(({ identifier, type }) => RefactorerUtils.createSimpleParameter(identifier, type)); // ------- +5.6 Complexity index (+1.1 atomic, +1.5 nesting, +3 structural)
                            const NEW_METHOD = RefactorerUtils.createSimpleMethod(METHOD_NAME, currentNode.compilerNode, PARAMETERS); // ------------------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                            methods.push(NEW_METHOD); // --------------------------------------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
            
                            const CONTAIN_RETURN = currentNode.compilerNode.statements.find((s) => s.kind === ts.SyntaxKind.ReturnStatement); // ----------- +4.9 Complexity index (+1.4 atomic, +1.5 nesting, +2 structural)
                            const METHOD_CALL: any = RefactorerUtils.createMethodCall(METHOD_NAME, []); // ------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
            
                            return ts.createBlock(CONTAIN_RETURN ? [ts.createReturn(METHOD_CALL)] : [METHOD_CALL]); // ------------------------------------- +5.4 Complexity index (+0.9 atomic, +1.5 nesting, +3 structural)
                        }
                        return currentNode.compilerNode; // ------------------------------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                    });
            
                    this.addMethodToClass(NODE, methods); // ----------------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    return NODE; // ------------------------------------------------------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
addMethodToClass Complexity Index 11.8 Cyclomatic complexity 2
                            
                                
                
            
                private addMethodToClass(node: Node, methods): void { // --------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    this.addTransformer({ // ------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                        baseNode: node, // --------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                        nodeMethod: 'getParent', // ------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                        transformer: (traversal: TransformTraversalControl) => { // ---------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                            const NODE = traversal.visitChildren(); // ----------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                            if (ts.isClassDeclaration(NODE)) { // ---------------------------------------------- +3.4 Complexity index (+0.4 atomic, +1 nesting, +2 structural)
                                const METHODS = ts.createNodeArray([...NODE.members, ...methods]); // ---------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                                return ts.createClassDeclaration([], [], NODE.name, [], [], METHODS); // ------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                            }
                            return NODE; // -------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                        },
                    });
                }
            
                            
                        
keepOnlyParameters Complexity Index 16.7 Cyclomatic complexity 3
                            
                                
                
            
                private keepOnlyParameters(node: Node, inputs: Input[], parameters: Input[]): void { // ------------------- +1.0 Complexity index (+1.0 atomic)
                    node.getDescendantsOfKind(SyntaxKind.Identifier).forEach((d: Identifier) => { // ---------------------- +3.8 Complexity index (+0.8 atomic, +3 structural)
                        inputs.forEach((i: Input) => { // ----------------------------------------------------------------- +3.5 Complexity index (+0.5 atomic, +1 nesting, +2 structural)
                            if (i.identifier === d.getFullText() && !parameters.includes(i)) parameters.push(i); // ------- +8.4 Complexity index (+1.4 atomic, +2 nesting, +5 structural)
                        });
                    });
                }
            
                            
                        
catchInputs Complexity Index 13.8 Cyclomatic complexity 4
                            
                                
                
            
                private catchInputs(node: Node, inputs: Input[]): void { // ------------------------------------------------------------------------------------- +0.7 Complexity index (+0.7 atomic)
                    if (this.isInputs(node)) { // --------------------------------------------------------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        const IDENTIFIER: string = node.getFirstDescendantByKind(SyntaxKind.Identifier).getFullText(); // --------------------------------------- +2.8 Complexity index (+0.8 atomic, +2 structural)
                        const TYPE: ts.TypeNode = node?.compilerNode.type; // ----------------------------------------------------------------------------------- +0.7 Complexity index (+0.7 atomic)
                        if (!inputs.find((i) => i.identifier === IDENTIFIER)) inputs.push({ identifier: IDENTIFIER, type: TYPE, isParameter: false }); // ------- +7.2 Complexity index (+1.7 atomic, +1.5 nesting, +4 structural)
                    }
                }
            
                            
                        
isConditionnedBlock Complexity Index 10.6 Cyclomatic complexity 4
                            
                                
                
            
                private isConditionnedBlock(node: Node): node is Block { // ---------------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    return node.getParent() && Node.isIfStatement(node.getParent()) && Node.isBlock(node) && node.getStatements().length > 5; // ------- +10.1 Complexity index (+2.1 atomic, +8 structural)
                }
            
                            
                        
isInputs Complexity Index 8.2 Cyclomatic complexity 3
                            
                                
                
            
                private isInputs(node: Node): node is ParameterDeclaration | VariableDeclaration { // --------------------------------------------------- +0.7 Complexity index (+0.7 atomic)
                    return (Node.isParameterDeclaration(node) && !Node.isArrowFunction(node.getParent())) || Node.isVariableDeclaration(node); // ------- +7.5 Complexity index (+1.5 atomic, +6 structural)
                }