Genese complexity report

<- refactorer.model.ts
Methods : 9
Complexity index : 64.9
Cyclomatic complexity : 13
Cognitive complexity
66.7 % Correct 6/9
33.3 % Warning 3/9 (threshold : 10)
0 % Error 0/9 (threshold : 20)
Cyclomatic complexity
100 % Correct 9/9
0 % Warning 0/9 (threshold : 5)
0 % Error 0/9 (threshold : 10)
Methods of refactorer.model.ts
Complexity Index 0.6 Cyclomatic complexity 0
                            
                                
                
            
                constructor(projectService: ProjectService) { // ------- +0.2 Complexity index (+0.2 atomic)
                    this.projectService = projectService; // ----------- +0.4 Complexity index (+0.4 atomic)
                }
            
                            
                        
apply Complexity Index 14.7 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Refactor nodes if it needed
                 * apply transformers
                 * then map refactored node in refactor proposal
                 * @returns {void}
                 */
                apply(): void { // ----------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    this.nodes = this.projectService.getNodesOfKinds(this.REFACTORED_NODE_KIND) // ------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                        .filter(n => this.refactorNeeded(n)) // ------------------------------------------ +3.6 Complexity index (+0.6 atomic, +3 structural)
                        .map((n, i) => { // -------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                            this.processOriginalNode(n); // ---------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                            this.refactor(n); // --------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                            this.processRefactoredNode(n, i); // ----------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                            return n; // ----------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                        })
                    if (this.transformers) { // ---------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        this.applyTransformers(); // ----------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    }
                }
            
                            
                        
applyTransformers Complexity Index 9.8 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Apply additional tranformers to the node
                 */
                private applyTransformers(): void { // ------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    this.nodes = this.transformers.map((t: Transformer, i) => { // -------------- +3.0 Complexity index (+1.0 atomic, +2 structural)
                        const r = t.baseNode[t.nodeMethod]().transform(t.transformer); // ------- +2.9 Complexity index (+0.9 atomic, +2 structural)
                        r.formatText(); // ------------------------------------------------------ +1.2 Complexity index (+0.2 atomic, +1 structural)
                        this.refactorProposals[i].newCode = r.getFullText(); // ----------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                        this.refactorProposals[i].usedTransformer = t; // ----------------------- +0.6 Complexity index (+0.6 atomic)
                        return r; // ------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    });
                }
            
                            
                        
processRefactoredNode Complexity Index 16.2 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Compute and store information about the refactored node
                 * @param n
                 * @param i
                 */
                private processRefactoredNode(n: Node, i: number) { // -------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    this.refactorProposals[i].newComplexity = ComplexityService.getCpxFromSourceCode(n.getFullText()); // ----------------------- +2.9 Complexity index (+0.9 atomic, +2 structural)
                    const existingRefactor = this.projectService.refactorProposals.find(er => er.id === this.refactorProposals[i].id); // ------- +3.5 Complexity index (+1.5 atomic, +2 structural)
                    if (existingRefactor && existingRefactor.usedTransformer) { // -------------------------------------------------------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
                        this.refactorProposals[i].oldCode = existingRefactor.oldCode; // -------------------------------------------------------- +0.7 Complexity index (+0.7 atomic)
                        const transformer = existingRefactor.usedTransformer; // ---------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                        n = n[transformer.nodeMethod]().transform(transformer.transformer); // -------------------------------------------------- +2.8 Complexity index (+0.8 atomic, +2 structural)
                    }
                    n.formatText(); // ---------------------------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.refactorProposals[i].newCode = n.getFullText(); // --------------------------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                }
            
                            
                        
processOriginalNode Complexity Index 10.1 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Compute and store information about the original node
                 * @param n
                 */
                private processOriginalNode(n: Node): void { // ------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    n.formatText(); // ------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    this.refactorProposals.push({ // ----------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        oldCode: n.getFullText(), // ----------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                        newCode: undefined, // ----------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                        title: (n as MethodDeclaration).getStructure()['name'], // ----------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                        id: (n as MethodDeclaration).getStructure()['name'], // -------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                        oldComplexity: ComplexityService.getCpxFromSourceCode(n.getFullText()), // ------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                        newComplexity: undefined // ------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    });
                }
            
                            
                        
addTransformer Complexity Index 5.9 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Add a transformer
                 * @param transformer
                 * @returns {void}
                 */
                addTransformer(transformer: Transformer): void { // ---------- +0.4 Complexity index (+0.4 atomic)
                    if (!this.transformers) this.transformers = []; // ------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                    if (!this.transformers.includes(transformer)) { // ------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                        this.transformers.push(transformer); // -------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    }
                }
            
                            
                        
refactor Complexity Index 0.4 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Refactor a node by using the transform method
                 * @param node the node to refactor
                 * @returns {Node}
                 */
                abstract refactor(node: Node): Node; // ------------------- +0.4 Complexity index (+0.4 atomic)
            
                            
                        
refactorNeeded Complexity Index 0.3 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Check if a Node need a refacto
                 * @param node the node to check
                 * @returns {boolean}
                 */
                abstract refactorNeeded(node: Node): boolean; // ------- +0.3 Complexity index (+0.3 atomic)
            
                            
                        
wrapCurrentNode Complexity Index 6.9 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * wrap a basic node into ts-morph model
                 * use project to get source file and type checker
                 * @param node
                 * @param traversal the node to wrap
                 * @returns {Node}
                 */
                static wrapCurrentNode(node: Node, traversal: TransformTraversalControl): Node { // ------- +0.6 Complexity index (+0.6 atomic)
                    return createWrappedNode(traversal.visitChildren(), { // ------------------------------ +2.4 Complexity index (+0.4 atomic, +2 structural)
                        sourceFile: node.getSourceFile().compilerNode, // --------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        typeChecker: node.getProject().getTypeChecker().compilerObject, // ---------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                    });
                }