Genese complexity report

<- barchart.model.ts
Methods : 8
Complexity index : 45.1
Cyclomatic complexity : 13
Cognitive complexity
87.5 % Correct 7/8
12.5 % Warning 1/8 (threshold : 10)
0 % Error 0/8 (threshold : 20)
Cyclomatic complexity
100 % Correct 8/8
0 % Warning 0/8 (threshold : 5)
0 % Error 0/8 (threshold : 10)
Methods of barchart.model.ts
Complexity Index 0.6 Cyclomatic complexity 0
                            
                                
                
            
            
                constructor(cpxType?: ComplexityType) { // ---------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    this.cpxType = cpxType; // ---------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                }
            
                            
                        
addResult Complexity Index 8.5 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Increases the height of a bar with a given complexity
                 * @param complexity / The x abscissa
                 * @param quantity / The y value to add for the bar with x abscissa
                 */
                addResult(complexity: number, quantity = 1): Barchart { // ------------------- +0.5 Complexity index (+0.5 atomic)
                    const roundedCpx = Math.round(complexity); // ---------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    if (this.abscissaAlreadyExists(roundedCpx)) { // ------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        this.increaseOrdinate(roundedCpx, quantity); // ---------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    } else { // -------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                        this.newBar(roundedCpx, quantity); // -------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                    }
                    return this; // ---------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
abscissaAlreadyExists Complexity Index 4.2 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Checks if a bar exists on a given abscissa
                 * @param complexity / The abscissa value
                 */
                private abscissaAlreadyExists(complexity: number): boolean { // ------- +0.2 Complexity index (+0.2 atomic)
                    return this.data.map(p => p.x).includes(complexity); // ----------- +4.0 Complexity index (+1.0 atomic, +3 structural)
                }
            
                            
                        
increaseOrdinate Complexity Index 4.7 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Increases the height of an existing bar
                 * @param abscissa / The abscissa of the bar (the complexity value)
                 * @param quantity / The height to add at the bar
                 */
                private increaseOrdinate(abscissa: number, quantity = 1): void { // ---------- +0.5 Complexity index (+0.5 atomic)
                    const index = this.data.findIndex(e => e.x === abscissa); // ------------- +3.1 Complexity index (+1.1 atomic, +2 structural)
                    this.data[index].y = this.data[index].y + quantity; // ------------------- +1.1 Complexity index (+1.1 atomic)
                }
            
                            
                        
newBar Complexity Index 3.6 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Adds a bar for a given abscissa
                 * @param complexity
                 * @param quantity
                 */
                newBar(complexity: number, quantity = 1): void { // ------------------------------------------ +0.5 Complexity index (+0.5 atomic)
                    this.data.push({x: complexity, y: quantity, color: this.getColor(complexity)}); // ------- +3.1 Complexity index (+1.1 atomic, +2 structural)
                }
            
                            
                        
sort Complexity Index 3.8 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Sorts the data by abscissa value (orders the complexities by ascending sort)
                 */
                sort(): Barchart { // -------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    this.data = this.data.sort((A, B) => A.x - B.x); // ---------------------------------- +3.4 Complexity index (+1.4 atomic, +2 structural)
                    return this; // ---------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getColor Complexity Index 5.3 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Gets the color of a bar with a given abscissa
                 * @param complexity / The abscissa of the bar
                 */
                getColor(complexity: number): ChartColor { // ----------------------- +0.3 Complexity index (+0.3 atomic)
                    let color = ChartColor.WARNING; // ------------------------------ +0.4 Complexity index (+0.4 atomic)
                    const cpx = `${this.cpxType}Cpx`; // ---------------------------- +0.4 Complexity index (+0.4 atomic)
                    if (complexity <= Options[cpx].warningThreshold) { // ----------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        color = ChartColor.CORRECT; // ------------------------------ +0.4 Complexity index (+0.4 atomic)
                    } else if (complexity > Options[cpx].errorThreshold) { // ------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        color = ChartColor.ERROR; // -------------------------------- +0.4 Complexity index (+0.4 atomic)
                    }
                    return color; // ------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
plugChartHoles Complexity Index 14.4 Cyclomatic complexity 4
                            
                                
                
            
            
                /**
                 * Adds bars with height = 0 when there is no method with a given complexity value which is lower than the greatest value
                 * Returns the chart himself
                 */
                plugChartHoles(): Barchart { // ---------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    this.sort(); // ---------------------------------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    const cpxMax: number = this.data[this.data.length - 1]?.x; // ------------------------------------------------------------------ +1.0 Complexity index (+1.0 atomic)
                    const cpxMin: number = this.cpxType === ComplexityType.COGNITIVE ? 0 : 1; // --------------------------------------------------- +2.0 Complexity index (+1.0 atomic, +1 structural)
                    for (let cpx = cpxMin; cpx < cpxMax; cpx++) { // ------------------------------------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                        if (!this.data.find(e => e.x === cpx)) { // -------------------------------------------------------------------------------- +5.5 Complexity index (+1.0 atomic, +1.5 nesting, +3 structural)
                            this.addResult(cpx, 0); // --------------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        }
                    }
                    this.sort(); // ---------------------------------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    return this; // ---------------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }