Genese complexity report

<- primary.ts
Methods : 12
Complexity index : 170.9
Cyclomatic complexity : 56
Cognitive complexity
8.3 % Correct 1/12
75 % Warning 9/12 (threshold : 10)
16.7 % Error 2/12 (threshold : 20)
Cyclomatic complexity
66.7 % Correct 8/12
33.3 % Warning 4/12 (threshold : 5)
0 % Error 0/12 (threshold : 10)
Methods of primary.ts
run Complexity Index 12.9 Cyclomatic complexity 3
                            
                                
            
            
            
            export function run(cstNode: Primary, children: PrimaryChildren): any { // ---------------------- +0.6 Complexity index (+0.6 atomic)
                const primaryPrefix = children.primaryPrefix; // -------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                const primarySuffix = children.primarySuffix; // -------------------------------------------- +0.4 Complexity index (+0.4 atomic)
            
                const primaryPrefixAst = [].concat(...primaryPrefix?.map(e => cstToAst(e)) ?? []); // ------- +5.0 Complexity index (+1.0 atomic, +4 structural)
                const primarySuffixAst = [].concat(...primarySuffix?.map(e => cstToAst(e)) ?? []); // ------- +5.0 Complexity index (+1.0 atomic, +4 structural)
            
                return process(cstNode, primaryPrefixAst, primarySuffixAst); // ----------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
            }
            
                            
                        
process Complexity Index 19.4 Cyclomatic complexity 5
                            
                                
            
            
            function process(cstNode: any, prefix: any, suffix: any): any { // ------------------------------------- +0.8 Complexity index (+0.8 atomic)
                const methodInvocationSuffix = suffix.filter(e => e.kind === 'MethodInvocationSuffix'); // --------- +3.0 Complexity index (+1.0 atomic, +2 structural)
                const arrayAccessSuffix = suffix.filter(e => e.kind === 'ArrayAccessSuffix'); // ------------------- +3.0 Complexity index (+1.0 atomic, +2 structural)
            
                if (Array.isArray(arrayAccessSuffix) && arrayAccessSuffix.length > 0) { // ------------------------- +4.0 Complexity index (+1.0 atomic, +3 structural)
                    return createElementAccess(cstNode, prefix, suffix, arrayAccessSuffix); // --------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                }
                if (Array.isArray(methodInvocationSuffix) && methodInvocationSuffix.length > 0) { // --------------- +4.0 Complexity index (+1.0 atomic, +3 structural)
                    return handleMethodInvocationSuffix(cstNode, prefix, suffix, methodInvocationSuffix); // ------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                }
                return handleNoMethodInvocationSuffix(prefix, suffix); // ------------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
            }
            
                            
                        
handleNoMethodInvocationSuffix Complexity Index 24.6 Cyclomatic complexity 8
                            
                                
            
            
            /**
             * @param  {any} primaryPrefixAst
             * @param  {any} primarySuffixAst
             */
            function handleNoMethodInvocationSuffix(primaryPrefixAst: any, primarySuffixAst: any) { // --------------------------------------- +0.5 Complexity index (+0.5 atomic)
                if (primarySuffixAst.length === 1 && primarySuffixAst[0].kind === 'ClassLiteralSuffix') { // --------------------------------- +3.2 Complexity index (+1.2 atomic, +2 structural)
                    primaryPrefixAst.push(...primarySuffixAst.pop().children) // ------------------------------------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                }
                if (primaryPrefixAst.length > 1) { // ---------------------------------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    return [ // -------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        toPropertyAccessExpression(primaryPrefixAst, false, []), // ---------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        ...primarySuffixAst // ----------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    ];
                }
                if (primaryPrefixAst.length === 1 && primaryPrefixAst[0].kind === 'ThisKeyword') { // ---------------------------------------- +3.2 Complexity index (+1.2 atomic, +2 structural)
                    return [ // -------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        toPropertyAccessExpression([...primaryPrefixAst, ...primarySuffixAst], false, []), // -------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    ];
                }
                if (primarySuffixAst.every(e => e.kind === 'Identifier') && primarySuffixAst.every(e => e.kind === 'Identifier')) { // ------- +8.9 Complexity index (+1.9 atomic, +1 nesting, +6 structural)
                    return [ // -------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        toPropertyAccessExpression([...primaryPrefixAst, ...primarySuffixAst], false, []), // -------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    ];
                }
                return [ // ------------------------------------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                    ...primaryPrefixAst, // -------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    ...primarySuffixAst // --------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                ];
            }
            
                            
                        
handleMethodInvocationSuffix Complexity Index 12.9 Cyclomatic complexity 2
                            
                                
            
            
            /**
             * @param  {any} cstNode
             * @param  {any} primaryPrefixAst
             * @param  {any} primarySuffixAst
             * @param  {any} methodInvocationSuffix
             */
            function handleMethodInvocationSuffix(cstNode: any, primaryPrefixAst: any, primarySuffixAst: any, methodInvocationSuffix: any) { // ------- +0.9 Complexity index (+0.9 atomic)
                const identifierSuffix = primarySuffixAst.filter(e => e.kind === 'Identifier'); // ---------------------------------------------------- +3.0 Complexity index (+1.0 atomic, +2 structural)
                const thisKeyword = primaryPrefixAst.find(e => e.kind === 'ThisKeyword'); // ---------------------------------------------------------- +3.0 Complexity index (+1.0 atomic, +2 structural)
                let obj = { // ------------------------------------------------------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    kind: 'CallExpression', // -------------------------------------------------------------------------------------------------------- +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)
                };
                if (thisKeyword) { // ----------------------------------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    return getThisKeywordChildren(methodInvocationSuffix, thisKeyword, identifierSuffix, obj); // ------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                }
                return getOtherCasesChildren(primaryPrefixAst, primarySuffixAst, methodInvocationSuffix, obj); // ------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
            }
            
                            
                        
getThisKeywordChildren Complexity Index 5.2 Cyclomatic complexity 1
                            
                                
            
            
            /**
             * @param  {any} methodInvocationSuffix
             * @param  {any} thisKeyword
             * @param  {any} identifierSuffix
             * @param  {any} obj
             * @returns any
             */
            function getThisKeywordChildren(methodInvocationSuffix: any, thisKeyword: any, identifierSuffix: any, obj: any): any[] { // ------- +1.1 Complexity index (+1.1 atomic)
                return { // ------------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    ...obj, // ---------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    children: [ // ------------------------------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                        toPropertyAccessExpression([ // --------------------------------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                            thisKeyword, // --------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                            ...identifierSuffix, // ------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        ], true, clone(methodInvocationSuffix)), // --------------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        ...getMethodInvocationSuffixChildren(methodInvocationSuffix), // ------------------------------------------------------ +1.2 Complexity index (+0.2 atomic, +1 structural)
                    ]
                };
            }
            
                            
                        
getOtherCasesChildren Complexity Index 14.6 Cyclomatic complexity 1
                            
                                
            
            
            
            /**
             * @param  {any} primaryPrefixAst
             * @param  {any} primarySuffixAst
             * @param methodInvocationSuffix
             * @param  {any} obj
             * @returns any
             */
            function getOtherCasesChildren(primaryPrefixAst: any, primarySuffixAst: any, methodInvocationSuffix: any, obj: any): any[] { // ------- +1.1 Complexity index (+1.1 atomic)
                return { // ----------------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    ...obj, // -------------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    children: [ // ---------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        toPropertyAccessExpression([ // ------------------------------------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                            ...getNewExpression(primaryPrefixAst), // ----------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                            ...primaryPrefixAst.filter(e => e.kind === 'Identifier'), // ---------------------------------------------------------- +2.8 Complexity index (+0.8 atomic, +2 structural)
                            ...primarySuffixAst.filter(e => e.kind === 'Identifier') // ----------------------------------------------------------- +2.8 Complexity index (+0.8 atomic, +2 structural)
                        ], true, clone(methodInvocationSuffix)), // ------------------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        ...primarySuffixAst.filter(e => e.kind === 'ClassLiteralSuffix'), // ------------------------------------------------------ +2.8 Complexity index (+0.8 atomic, +2 structural)
                        ...getMethodInvocationSuffixChildren(methodInvocationSuffix), // ---------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    ]
                };
            }
            
                            
                        
getMethodInvocationSuffixChildren Complexity Index 13 Cyclomatic complexity 4
                            
                                
            
            
            /** Get all MethodInvocationSuffix with children
             * @param  {} methodInvocationSuffixList
             */
            function getMethodInvocationSuffixChildren(methodInvocationSuffixList) { // ---------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                let childrenList = []; // -------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                if (Array.isArray(methodInvocationSuffixList)) { // ------------------------------------------------------------------ +2.4 Complexity index (+0.4 atomic, +2 structural)
                    methodInvocationSuffixList.forEach(methodInvocationSuffix => { // ------------------------------------------------ +2.9 Complexity index (+0.4 atomic, +0.5 nesting, +2 structural)
                        if (Array.isArray(methodInvocationSuffix.children) && methodInvocationSuffix.children.length > 0) { // ------- +5.7 Complexity index (+1.2 atomic, +1.5 nesting, +3 structural)
                            childrenList.push(...methodInvocationSuffix.children); // ------------------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                        }
                    });
                }
                return childrenList; // ---------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
            }
            
                            
                        
getNewExpression Complexity Index 10.9 Cyclomatic complexity 3
                            
                                
            
            
            /** Get newExpression Ast node
             * @param  {any} primaryPrefixAst
             * @returns any
             */
            function getNewExpression(primaryPrefixAst: any): any[] { // --------------------------------- +0.5 Complexity index (+0.5 atomic)
                const newExpression = primaryPrefixAst.filter(e => e.kind === 'NewExpression'); // ------- +3.0 Complexity index (+1.0 atomic, +2 structural)
                if (Array.isArray(newExpression) && newExpression.length) { // --------------------------- +3.8 Complexity index (+0.8 atomic, +3 structural)
                    return [ // -------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        ...primaryPrefixAst.find(e => e.kind === 'NewExpression').children // ------------ +3.4 Complexity index (+0.9 atomic, +0.5 nesting, +2 structural)
                    ];
                }
                return []; // ---------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
            }
            
                            
                        
createElementAccess Complexity Index 14.6 Cyclomatic complexity 7
                            
                                
            
            
            /**
             * @param  {} primaryPrefixAst
             * @param primarySuffixAst
             * @param  {} arrayAccessSuffixList
             * @returns any
             */
            function createElementAccess(cstNode, primaryPrefixAst, primarySuffixAst, arrayAccessSuffixList): any { // ----------- +2.6 Complexity index (+0.6 atomic, +2 recursivity)
                if (arrayAccessSuffixList.length === 1) { // --------------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    return singleAccessCase(cstNode, primaryPrefixAst, primarySuffixAst, arrayAccessSuffixList); // -------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                }
                const arrayAccessSuffix = arrayAccessSuffixList.pop(); // -------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                const last = arrayAccessSuffix.children?.find(e => e.kind === 'Identifier' || 'Literal'); // --------------------- +4.4 Complexity index (+1.4 atomic, +3 structural)
                return { // ------------------------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                    kind: 'ElementAccessExpression', // -------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    start: primaryPrefixAst[0]?.start, // ------------------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    pos: primaryPrefixAst[0]?.pos, // ---------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    end: arrayAccessSuffix?.end, // ------------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
                    children: [ // ----------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        {
                            ...createElementAccess(cstNode, primaryPrefixAst, primarySuffixAst, arrayAccessSuffixList), // ------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                        },
                        last // -------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    ]
                };
            }
            
                            
                        
singleAccessCase Complexity Index 10.1 Cyclomatic complexity 5
                            
                                
            
            
            function singleAccessCase(cstNode, primaryPrefixAst, primarySuffixAst, arrayAccessSuffixList) { // ---------- +0.5 Complexity index (+0.5 atomic)
                primarySuffixAst.pop(); // ------------------------------------------------------------------------------ +1.2 Complexity index (+0.2 atomic, +1 structural)
                return { // --------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    kind: 'ElementAccessExpression', // ----------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    start: primaryPrefixAst[0]?.start, // --------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    end: arrayAccessSuffixList[0]?.end, // -------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    pos: primaryPrefixAst[0]?.pos, // ------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    children: [ // -------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        ...[].concat(...[process(cstNode, primaryPrefixAst, primarySuffixAst)]), // --------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                        ...arrayAccessSuffixList[0].children.filter(e => e.kind === 'Identifier' || 'Literal') // ------- +4.3 Complexity index (+1.3 atomic, +3 structural)
                    ]
                };
            }
            
                            
                        
toPropertyAccessExpression Complexity Index 20.9 Cyclomatic complexity 10
                            
                                
            
            
            /**
             * @param  {any[]} identifiers
             * @param  {} isFunctionCall=false
             * @param  {any[]} methodInvocationSuffix
             * @returns any
             */
            function toPropertyAccessExpression(identifiers: any[], isFunctionCall = false, methodInvocationSuffix: any[]): any { // ------- +3.0 Complexity index (+1.0 atomic, +2 recursivity)
                if (!identifiers || identifiers.length === 0) return undefined; // --------------------------------------------------------- +3.0 Complexity index (+1.0 atomic, +2 structural)
            
                if (identifiers.length === 1 && methodInvocationSuffix.length === 0) { // -------------------------------------------------- +3.1 Complexity index (+1.1 atomic, +2 structural)
                    return identifiers[0]; // ---------------------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                }
                if (identifiers.length === 1) { // ----------------------------------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    return {type: 'function', ...identifiers[0]}; // ----------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                }
                const last = identifiers.pop(); // ----------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
            
                if (isFunctionCall) { // --------------------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    return isFunctionCallCase(identifiers, last, methodInvocationSuffix); // ----------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                }
                return { // ---------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    kind: 'PropertyAccessExpression', // ----------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    start: identifiers[0]?.start, // --------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    end: last?.end, // ----------------------------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    pos: identifiers[0]?.pos, // ------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    children: [ // --------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        toPropertyAccessExpression(identifiers, false, methodInvocationSuffix), // ----------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        last // ------------------------------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                    ].filter(e => e) // ---------------------------------------------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                };
            }
            
                            
                        
isFunctionCallCase Complexity Index 11.8 Cyclomatic complexity 7
                            
                                
            
            
            function isFunctionCallCase(identifiers, last, methodInvocationSuffix) { // ---------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                methodInvocationSuffix.pop(); // ------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
            
                let start: number, pos: number; // ----------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                if (identifiers.length === 0) { // ----------------------------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    start = last?.start; // ------------------------------------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    pos = last?.pos; // ---------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                } else { // ---------------------------------------------------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                    start = identifiers[0]?.start; // -------------------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    pos = identifiers[0]?.pos; // ------------------------------------------------------------------------------------ +0.5 Complexity index (+0.5 atomic)
                }
            
                return { // ---------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    kind: 'PropertyAccessExpression', // ----------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    start: start, // ------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    end: last?.end, // ----------------------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    pos: pos, // ----------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    children: [ // --------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        toPropertyAccessExpression(identifiers, methodInvocationSuffix.length > 0, methodInvocationSuffix), // ------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                        {...last, type: 'function'} // ------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    ].filter(e => e) // ---------------------------------------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                };
            }