Genese complexity report

<- binary-expression.ts
Methods : 7
Complexity index : 119.3
Cyclomatic complexity : 24
Cognitive complexity
0 % Correct 0/7
71.4 % Warning 5/7 (threshold : 10)
28.6 % Error 2/7 (threshold : 20)
Cyclomatic complexity
100 % Correct 7/7
0 % Warning 0/7 (threshold : 5)
0 % Error 0/7 (threshold : 10)
Methods of binary-expression.ts
run Complexity Index 17 Cyclomatic complexity 5
                            
                                
            
            
            // @ts-ignore
            export function run(cstNode: BinaryExpression, children: BinaryExpressionChildren): any { // ---------------- +0.6 Complexity index (+0.6 atomic)
                const unaryExpressions = children.unaryExpression; // --------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                const binaryOperators = children.BinaryOperator; // ----------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                const less = children.Less; // -------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                const greater = children.Greater; // -------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
            
                const assignmentOperator = children.AssignmentOperator; // ---------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                const unaryExpressionsAst = [...[].concat(...unaryExpressions.map(e => cstToAst(e)))]; // --------------- +4.9 Complexity index (+0.9 atomic, +4 structural)
                if (binaryOperators || less || greater) { // ------------------------------------------------------------ +3.8 Complexity index (+0.8 atomic, +3 structural)
                    return binaryOperatorsCase(binaryOperators, less, greater, unaryExpressionsAst); // ----------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                } else if (assignmentOperator) { // --------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    return assignmentOperatorCase(cstNode, children, unaryExpressionsAst, assignmentOperator); // ------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                } else { // --------------------------------------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                    return [ // ----------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        ...unaryExpressionsAst, // ---------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    ];
                }
            }
            
                            
                        
binaryOperatorsCase Complexity Index 12.9 Cyclomatic complexity 2
                            
                                
            
            
            function binaryOperatorsCase(binaryOperators, less, greater, unaryExpressionsAst) { // -------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                let binaryOperatorsAst = constructBinaryOperatorsAst(binaryOperators, less, greater); // -------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                const alternate = []; // ------------------------------------------------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                for (let i = 0; i < binaryOperatorsAst.length; i++) { // ---------------------------------------------------------------------------------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    alternate.push(unaryExpressionsAst[i], binaryOperatorsAst[i]); // --------------------------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                }
                alternate.push(...unaryExpressionsAst.slice(binaryOperatorsAst.length), ...binaryOperatorsAst.slice(binaryOperatorsAst.length)); // ------- +4.0 Complexity index (+1.0 atomic, +3 structural)
                const separatedExps = splitExpression(alternate); // -------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                return toBinaryExpression(separatedExps.op, separatedExps.left, separatedExps.right); // -------------------------------------------------- +1.8 Complexity index (+0.8 atomic, +1 structural)
            }
            
                            
                        
constructBinaryOperatorsAst Complexity Index 24 Cyclomatic complexity 2
                            
                                
            
            
            function constructBinaryOperatorsAst(binaryOperators, less, greater) { // ----------------------------- +0.4 Complexity index (+0.4 atomic)
                let binaryOperatorsAst = binaryOperators?.map(e => cstToAst(e, 'binaryOperator')) ?? []; // ------- +4.0 Complexity index (+1.0 atomic, +3 structural)
                const lessAndGreaterAst = []; // ------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                lessAndGreaterAst.push(...reconstructOperators(less)); // ----------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                lessAndGreaterAst.push(...reconstructOperators(greater)); // -------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                lessAndGreaterAst.forEach(op => { // -------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                    binaryOperatorsAst.push({ // ------------------------------------------------------------------ +1.2 Complexity index (+0.2 atomic, +1 structural)
                        kind: getBinaryOperatorName(op.map(e => e.image).join('')), // ---------------------------- +6.0 Complexity index (+1.0 atomic, +1 nesting, +4 structural)
                        start: op[0].startOffset, // -------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                        end: op[op.length - 1].endOffset, // ------------------------------------------------------ +0.7 Complexity index (+0.7 atomic)
                        pos: op[0].startOffset // ----------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    });
                });
                binaryOperatorsAst = binaryOperatorsAst.sort((a, b) => { // --------------------------------------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                    return a.start - b.start; // ------------------------------------------------------------------ +0.6 Complexity index (+0.6 atomic)
                });
                return binaryOperatorsAst; // --------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
            }
            
                            
                        
assignmentOperatorCase Complexity Index 11.2 Cyclomatic complexity 3
                            
                                
            
            
            function assignmentOperatorCase(cstNode, children, unaryExpressionsAst, assignmentOperator) { // ------- +0.5 Complexity index (+0.5 atomic)
                const expression = children.expression; // --------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                return { // ---------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    kind: 'BinaryExpression', // ------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    start: cstNode.location.startOffset, // -------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    end: cstNode.location.endOffset, // ------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    pos: cstNode.location.startOffset, // ---------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    children: [ // --------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        ...unaryExpressionsAst, // ----------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        ...assignmentOperator?.map(e => cstToAst(e, 'assignmentOperator')) ?? [], // --------------- +3.8 Complexity index (+0.8 atomic, +3 structural)
                        ...[].concat(...expression?.map(e => cstToAst(e)) ?? []) // -------------------------------- +4.8 Complexity index (+0.8 atomic, +4 structural)
                    ]
                };
            }
            
                            
                        
reconstructOperators Complexity Index 19 Cyclomatic complexity 5
                            
                                
            
            
            function reconstructOperators(elements: any[]): any { // ------------------------------------ +0.5 Complexity index (+0.5 atomic)
                if (!elements || elements.length === 0) return []; // ----------------------------------- +2.9 Complexity index (+0.9 atomic, +2 structural)
                const result = []; // ------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                const indexes = elements.map((e, i) => { // --------------------------------------------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                    return e?.startOffset + 1 === elements[i + 1]?.startOffset ? null : i + 1; // ------- +3.5 Complexity index (+1.5 atomic, +1 nesting, +1 structural)
                }).filter(e => e); // ------------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                indexes.forEach((i, index) => { // ------------------------------------------------------ +2.5 Complexity index (+0.5 atomic, +2 structural)
                    result.push(elements.slice(indexes[index - 1] ?? 0, i)); // ------------------------- +4.1 Complexity index (+1.1 atomic, +2 structural, +1 use)
                });
                return result; // ----------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
            }
            
                            
                        
splitExpression Complexity Index 22.8 Cyclomatic complexity 4
                            
                                
            
            
            function splitExpression(list) { // ---------------------------------------------------------- +2.2 Complexity index (+0.2 atomic, +2 recursivity)
                if (list.length === 1) { // -------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    return list[0]; // ------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                }
                const result = { // ---------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    op: undefined, // -------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    left: undefined, // ------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    right: undefined // ------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                };
                binaryOperatorsPrecedence.forEach(ops => { // -------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                    const index = list.findIndex(e => ops.includes(e.kind)); // -------------------------- +5.0 Complexity index (+1.0 atomic, +1 nesting, +3 structural)
                    if (index !== -1 && !result.op) { // ------------------------------------------------- +3.8 Complexity index (+0.8 atomic, +1 nesting, +2 structural)
                        result.op = list[index]; // ------------------------------------------------------ +0.5 Complexity index (+0.5 atomic)
                        result.left = splitExpression(list.slice(0, index)); // -------------------------- +2.8 Complexity index (+0.8 atomic, +2 structural)
                        result.right = splitExpression(list.slice(index + 1, list.length + 1)); // ------- +3.3 Complexity index (+1.3 atomic, +2 structural)
                    }
                });
                return result; // ------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
            }
            
                            
                        
toBinaryExpression Complexity Index 12.4 Cyclomatic complexity 3
                            
                                
            
            
            function toBinaryExpression(op, left, right): any { // ------------------------------------- +0.5 Complexity index (+0.5 atomic)
                const children = [ // ------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    left.op ? toBinaryExpression(left.op, left.left, left.right) : left, // ------------ +3.1 Complexity index (+1.1 atomic, +2 structural)
                    op, // ----------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    right.op ? toBinaryExpression(right.op, right.left, right.right) : right, // ------- +3.1 Complexity index (+1.1 atomic, +2 structural)
                ];
                let mostLeft = left; // ---------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                while (mostLeft.left) { // ------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    mostLeft = mostLeft.left; // ------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                }
                let mostRight = right; // -------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                while (mostRight.right) { // ----------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    mostRight = mostRight.right; // ---------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                }
                return { // ---------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    kind: 'BinaryExpression', // ------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    start: mostLeft.start, // ---------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    end: mostRight.end, // ------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    pos: mostLeft.pos, // -------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    children: children // -------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                };
            }