Genese complexity report

<- uselessElse.refactorer.ts
Methods : 2
Complexity index : 46.2
Cyclomatic complexity : 13
Cognitive complexity
0 % Correct 0/2
50 % Warning 1/2 (threshold : 10)
50 % Error 1/2 (threshold : 20)
Cyclomatic complexity
50 % Correct 1/2
50 % Warning 1/2 (threshold : 5)
0 % Error 0/2 (threshold : 10)
Methods of uselessElse.refactorer.ts
refactorNeeded Complexity Index 12.3 Cyclomatic complexity 8
                            
                                
                
            
                /**
                 * Check method structure to know if it needs refacto
                 * if true refactor the method
                 * @returns {void}
                 * @param node
                 */
                refactorNeeded(node: Node): boolean { // ---------------------------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    const FIRST_BLOCK = node.getFirstChildByKind(SyntaxKind.Block); // ---------------------------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    const IF_STATEMENT = FIRST_BLOCK?.getChildrenOfKind(SyntaxKind.IfStatement)[0]; // ------------------------------------------------------ +1.7 Complexity index (+0.7 atomic, +1 structural)
                    const HAS_ELSE_STATEMENT = IF_STATEMENT?.getChildrenOfKind(SyntaxKind.Block)?.length === 2; // ------------------------------------------ +1.9 Complexity index (+0.9 atomic, +1 structural)
                    const HAS_RETURN_ON_IF = IF_STATEMENT?.getFirstChildByKind(SyntaxKind.Block)?.getFirstChildByKind(SyntaxKind.ReturnStatement); // ------- +2.9 Complexity index (+0.9 atomic, +2 structural)
                    return Boolean(IF_STATEMENT && HAS_ELSE_STATEMENT && HAS_RETURN_ON_IF); // -------------------------------------------------------------- +3.9 Complexity index (+0.9 atomic, +3 structural)
                }
            
                            
                        
refactor Complexity Index 33.9 Cyclomatic complexity 5
                            
                                
                
            
                /**
                 * Copy current method then transform the copy to get refctored method
                 * Put refactored method on current method object
                 * @returns {void}
                 * @param node
                 */
                refactor(node: Node): Node { // ------------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    let elseStatements: string[] = []; // --------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    node.transform((traversal: TransformTraversalControl) => { // --------------------------------------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                        const currentNode = Refactorer.wrapCurrentNode(node, traversal); // ----------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        if (Node.isIfStatement(currentNode) && currentNode.getElseStatement()) { // --------------------------------------------- +5.8 Complexity index (+0.8 atomic, +1 nesting, +4 structural)
                            elseStatements = currentNode.getElseStatement().getChildren().map(s => s.getFullText()) // -------------------------- +7.5 Complexity index (+1.0 atomic, +1.5 nesting, +5 structural)
                            elseStatements = elseStatements.slice(1, elseStatements.length - 1); // --------------------------------------------- +2.9 Complexity index (+0.9 atomic, +1 structural, +1 use)
                            if (elseStatements[0]) elseStatements[0] = elseStatements[0].replace(/\n/, ''); // ---------------------------------- +5.8 Complexity index (+1.1 atomic, +0.2 aggregation, +1.5 nesting, +3 structural)
                            return ts.createIf(currentNode.getExpression().compilerNode, currentNode.getThenStatement().compilerNode); // ------- +3.9 Complexity index (+0.9 atomic, +3 structural)
                        }
                        return currentNode.compilerNode; // ------------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    });
                    node.getFirstDescendantByKind(SyntaxKind.Block)?.addStatements(elseStatements); // ------------------------------------------ +2.6 Complexity index (+0.6 atomic, +2 structural)
                    return node; // ------------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }