Genese complexity report

<- tools.service.ts
Methods : 7
Complexity index : 48.8
Cyclomatic complexity : 16
Cognitive complexity
85.7 % Correct 6/7
0 % Warning 0/7 (threshold : 10)
14.3 % Error 1/7 (threshold : 20)
Cyclomatic complexity
85.7 % Correct 6/7
14.3 % Warning 1/7 (threshold : 5)
0 % Error 0/7 (threshold : 10)
Methods of tools.service.ts
capitalize Complexity Index 5.2 Cyclomatic complexity 1
                            
                                
            
            
            
            /**
             * Sets in capitals the first letter of a text
             * @param text
             */
            export function capitalize(text: string): string { // -------------------------- +0.4 Complexity index (+0.4 atomic)
                return `${text.charAt(0).toUpperCase()}${text.slice(1)}`; // --------------- +4.8 Complexity index (+0.8 atomic, +3 structural, +1 use)
            }
            
                            
                        
incrementIdentifierDuration Complexity Index 2.5 Cyclomatic complexity 1
                            
                                
            
            export function incrementIdentifierDuration(dt: number, v: string) { // ------- +0.4 Complexity index (+0.4 atomic)
                duration[v] = duration[v] ? duration[v] + dt : dt; // --------------------- +2.1 Complexity index (+1.1 atomic, +1 structural)
            }
            
                            
                        
percent Complexity Index 3.7 Cyclomatic complexity 2
                            
                                
            
            
            
            /**
             * Returns the result of a fraction in percentage with 2 decimals
             * @param numerator         // The numerator of the fraction
             * @param denominator       // The denominator of the fraction
             */
            export function percent(numerator: number, denominator: number): number { // ------- +0.3 Complexity index (+0.3 atomic)
                if (!denominator) { // --------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    return 0; // --------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
                return  Math.round(numerator * 1000 / denominator) / 10; // -------------------- +2.0 Complexity index (+1.0 atomic, +1 structural)
            }
            
                            
                        
addObjects Complexity Index 24.7 Cyclomatic complexity 8
                            
                                
            
            
            
            /**
             * Adds two objects with properties which have numeric values
             * Returns the result of the addition with the same type (if given) of the two objects
             * @param first             // The first object
             * @param second            // The second object
             * @param tConstructor      // The class of the objects
             */
            export function addObjects<T>(first: T, second: T, tConstructor?: TConstructor<T>): T { // --------------- +3.0 Complexity index (+1.0 atomic, +2 recursivity)
                if (!(typeof first === 'object') || !(typeof second === 'object')) { // ------------------------------ +2.9 Complexity index (+0.9 atomic, +2 structural)
                    return first; // --------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
                const t = tConstructor ? new tConstructor() : {}; // ------------------------------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                for (const key of Object.keys(first)) { // ----------------------------------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                    if (!second[key]) { // --------------------------------------------------------------------------- +1.8 Complexity index (+0.3 atomic, +0.5 nesting, +1 structural)
                        t[key] = first[key]; // ---------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    }
                    if (typeof first[key] === 'number') { // --------------------------------------------------------- +2.0 Complexity index (+0.5 atomic, +0.5 nesting, +1 structural)
                        t[key] = (typeof second[key] === 'number') ? first[key] + second[key] : first[key]; // ------- +3.5 Complexity index (+1.5 atomic, +1 nesting, +1 structural)
                    } else if (typeof first[key] === 'object' && typeof second[key] === 'object') { // --------------- +3.1 Complexity index (+1.1 atomic, +2 structural)
                        t[key] = addObjects(first[key], second[key]); // --------------------------------------------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    } else { // -------------------------------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                        t[key] = undefined; // ----------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    }
                }
                return t as T; // ------------------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
            }
            
                            
                        
isLastKey Complexity Index 4.3 Cyclomatic complexity 1
                            
                                
            
            
            
            /**
             * Checks if a key is the last one of a given object
             * @param key       // The key of the object
             * @param obj       // The object
             */
            export function isLastKey(key: string, obj: object): boolean { // ------- +0.4 Complexity index (+0.4 atomic)
                return (key === Object.keys(obj).slice(-1)[0]); // ------------------ +3.9 Complexity index (+0.9 atomic, +2 structural, +1 use)
            }
            
                            
                        
isLastIndex Complexity Index 1.2 Cyclomatic complexity 1
                            
                                
            
            
            
            /**
             * Checks if a number is the last index of a given array
             * @param i         // The index
             * @param arr       // The array
             */
            export function isLastIndex(i: number, arr: any[]): boolean { // ------- +0.5 Complexity index (+0.5 atomic)
                return (i === arr.length - 1); // ---------------------------------- +0.7 Complexity index (+0.7 atomic)
            }
            
                            
                        
randomString Complexity Index 7.2 Cyclomatic complexity 2
                            
                                
            
            
            export function randomString(length): string { // ------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                let result           = ''; // ----------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                const characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; // ------- +0.3 Complexity index (+0.3 atomic)
                const charactersLength = characters.length; // ------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                for ( let i = 0; i < length; i++ ) { // ------------------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                    result += characters.charAt(Math.floor(Math.random() * charactersLength)); // ------------------- +4.0 Complexity index (+1.0 atomic, +3 structural)
                }
                return result; // ----------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
            }