Genese complexity report

<- ast.service.ts
Methods : 16
Complexity index : 51.1
Cyclomatic complexity : 58
Cognitive complexity
93.8 % Correct 15/16
6.3 % Warning 1/16 (threshold : 10)
0 % Error 0/16 (threshold : 20)
Cyclomatic complexity
81.3 % Correct 13/16
18.8 % Warning 3/16 (threshold : 5)
0 % Error 0/16 (threshold : 10)
Methods of ast.service.ts
mayDefineContext Complexity Index 3.1 Cyclomatic complexity 1
                            
                                
            
            
            
            
                /**
                 * Checks if an AstNode may define context
                 * @param astNode
                 */
                static mayDefineContext(astNode: AstNode): boolean { // --------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    return Object.values(AstMayDefineContext).includes(astNode.kind as unknown as string); // ------- +2.8 Complexity index (+0.8 atomic, +2 structural)
                }
            
                            
                        
isArrayIndex Complexity Index 2.7 Cyclomatic complexity 5
                            
                                
                
            
            
                // ------------------------------------------------------------------------------------------------
                // -------------------------------------   TYPE CHECKS   ------------------------------------------
                // ------------------------------------------------------------------------------------------------
            
            
                /**
                 * Checks if an AST node is an index of an array, ie if it's a Node which is the second son of an ELEMENT_ACCESS_EXPRESSION
                 * @param astNode      // The node to analyse
                 */
                static isArrayIndex(astNode: AstNode): boolean { // ---------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    return(astNode?.parent?.kind === SyntaxKind.ElementAccessExpression && astNode?.parent.secondSon === astNode); // ---------------- +2.4 Complexity index (+1.4 atomic, +1 structural)
                }
            
                            
                        
isArrayOfArray Complexity Index 4.5 Cyclomatic complexity 8
                            
                                
                
            
            
                /**
                 * Checks if an AST node is an array of array, ie if it's an ELEMENT_ACCESS_EXPRESSION which is the first son of another ELEMENT_ACCESS_EXPRESSION
                 * @param astNode      // The node to analyse
                 */
                static isArrayOfArray(astNode: AstNode): boolean { // ------------------------------------------------------------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                    return(astNode?.parent?.kind === SyntaxKind.ElementAccessExpression && astNode?.kind === SyntaxKind.ElementAccessExpression && astNode?.pos === astNode.parent?.pos); // ------- +4.2 Complexity index (+2.2 atomic, +2 structural)
                }
            
                            
                        
isBinary Complexity Index 1.1 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Checks if an AST node is a BinaryExpression
                 * @param astNode // The AST node
                 */
                static isBinary(astNode: AstNode): boolean { // ----------------------------- +0.3 Complexity index (+0.3 atomic)
                    return astNode?.kind === SyntaxKind.BinaryExpression ?? false; // ------- +0.8 Complexity index (+0.8 atomic)
                }
            
                            
                        
isBlock Complexity Index 0.9 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Checks if an AST node is a Block which is a "else"
                 * @param astNode      // The node to analyse
                 */
                static isBlock(astNode: AstNode): boolean { // ----------------- +0.3 Complexity index (+0.3 atomic)
                    return (astNode?.kind === SyntaxKind.Block); // ------------ +0.6 Complexity index (+0.6 atomic)
                }
            
                            
                        
isCallExpression Complexity Index 1.1 Cyclomatic complexity 2
                            
                                
            
            
                /**
                 * Checks if an AST node is a Parameter
                 * @param astNode // The AST node
                 */
                static isCallExpression(astNode: AstNode): boolean { // ------------------- +0.3 Complexity index (+0.3 atomic)
                    return astNode?.kind === SyntaxKind.CallExpression ?? false; // ------- +0.8 Complexity index (+0.8 atomic)
                }
            
                            
                        
isDifferentLogicDoor Complexity Index 11.4 Cyclomatic complexity 5
                            
                                
                
            
            
                /**
                 * Returns true when the AST node is a logic door succeeding to a different logic door
                 * a && b && c => returns false
                 * a && b || c => returns true
                 * (a && b) || c => returns false because of the brackets
                 * @param astNode      // The node to analyse
                 */
                static isDifferentLogicDoor(astNode: AstNode): boolean { // ------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    if (Ast.isBinary(astNode) && Ast.isLogicDoor(astNode.secondSon)) { // ----------------------- +5.0 Complexity index (+1.0 atomic, +4 structural)
                        if (Ast.isBinary(astNode.parent) // ----------------------------------------------------- +3.1 Complexity index (+0.6 atomic, +0.5 nesting, +2 structural)
                            && !Ast.isSameOperatorToken(astNode, astNode.parent) // ----------------------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
                        ) {
                            return true; // --------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                        }
                    }
                    return false; // ---------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
isElseIfStatement Complexity Index 2.7 Cyclomatic complexity 5
                            
                                
                
            
            
                /**
                 * Checks if an AST node is a IfStatement which is an "else if"
                 * @param astNode      // The node to analyse
                 */
                static isElseIfStatement(astNode: AstNode): boolean { // ------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                    return (astNode?.kind === SyntaxKind.IfStatement && astNode?.parent?.kind === SyntaxKind.IfStatement); // ------- +2.4 Complexity index (+1.4 atomic, +1 structural)
                }
            
                            
                        
isElseStatement Complexity Index 6.3 Cyclomatic complexity 6
                            
                                
                
            
            
                /**
                 * Checks if an AST node is a Block which is a "else"
                 * @param astNode      // The node to analyse
                 */
                static isElseStatement(astNode: AstNode): boolean { // --------------- +0.3 Complexity index (+0.3 atomic)
                    return (Ast.isBlock(astNode) // ---------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        && astNode?.parent?.kind === SyntaxKind.IfStatement // ------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                        && astNode?.parent.getSon(2) === astNode) // ----------------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                }
            
                            
                        
isFunctionOrMethod Complexity Index 5.6 Cyclomatic complexity 7
                            
                                
                
            
            
                /**
                 * Checks if an AST node is a function or a method
                 * @param astNode
                 */
                static isFunctionOrMethod(astNode: AstNode): boolean { // ------------- +0.3 Complexity index (+0.3 atomic)
                    return astNode?.kind === SyntaxKind.MethodDeclaration || // ------- +2.0 Complexity index (+1.0 atomic, +1 structural)
                        astNode?.kind === SyntaxKind.FunctionDeclaration || // -------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        astNode?.kind === SyntaxKind.Constructor || // ---------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        false; // ----------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                }
            
                            
                        
isIdentifier Complexity Index 0.9 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Checks if an AST node is a function or a method
                 * @param astNode
                 */
                static isIdentifier(astNode: AstNode): boolean { // ---------- +0.3 Complexity index (+0.3 atomic)
                    return astNode?.kind === SyntaxKind.Identifier; // ------- +0.6 Complexity index (+0.6 atomic)
                }
            
                            
                        
isLogicDoor Complexity Index 2.8 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Checks if an AST node is a logic door (ie : || or &&)
                 * @param astNode // The AST node to check
                 */
                static isLogicDoor(astNode: AstNode): boolean { // ----------------------- +0.3 Complexity index (+0.3 atomic)
                    return (astNode.kind === SyntaxKind.AmpersandAmpersandToken // ------- +0.8 Complexity index (+0.8 atomic)
                        || astNode.kind === SyntaxKind.BarBarToken) // ------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        ?? false; // ----------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                }
            
                            
                        
isCallIdentifier Complexity Index 4.3 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Checks if an AST node is an index of an array, ie if it's a Node which is the second son of an ELEMENT_ACCESS_EXPRESSION
                 * @param astNode      // The node to analyse
                 */
                static isCallIdentifier(astNode: AstNode): boolean { // ------------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                    return(Ast.isCallExpression(astNode.parent) && Ast.isIdentifier(astNode)); // ---------------------------------------------------- +4.0 Complexity index (+1.0 atomic, +3 structural)
                }
            
                            
                        
isParam Complexity Index 1.1 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Checks if an AST node is a Parameter
                 * @param astNode // The AST node
                 */
                static isParam(astNode: AstNode): boolean { // ----------------------- +0.3 Complexity index (+0.3 atomic)
                    return astNode?.kind === SyntaxKind.Parameter ?? false; // ------- +0.8 Complexity index (+0.8 atomic)
                }
            
                            
                        
isPropertyAccessExpression Complexity Index 1.1 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Checks if an AST node is a PropertyAccessExpression
                 * @param astNode // The AST node
                 */
                static isPropertyAccessExpression(astNode: AstNode): boolean { // ------------------- +0.3 Complexity index (+0.3 atomic)
                    return astNode?.kind === SyntaxKind.PropertyAccessExpression ?? false; // ------- +0.8 Complexity index (+0.8 atomic)
                }
            
                            
                        
isSameOperatorToken Complexity Index 1.5 Cyclomatic complexity 5
                            
                                
                
            
            
                /**
                 * Checks if two AST nodes have the same type
                 * @param firstNode   // The first AST node
                 * @param secondNode  // The second AST node
                 */
                static isSameOperatorToken(firstNode: AstNode, secondNode: AstNode): boolean { // -------- +0.5 Complexity index (+0.5 atomic)
                    return firstNode?.secondSon?.kind === secondNode?.secondSon?.kind ?? false; // ------- +1.0 Complexity index (+1.0 atomic)
                }