Genese complexity report

<- json.service.ts
Methods : 9
Complexity index : 76.2
Cyclomatic complexity : 15
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 json.service.ts
prettifyJson Complexity Index 7.1 Cyclomatic complexity 1
                            
                                
            
            
                /**
                 * Converts a javascript object into a prettified Json with break lines
                 * @param obj               // The javascript object
                 * @param indent            // The initial indentation of the object
                 */
                static prettifyJson(obj: object, indent = ''): string { // ----------------------- +0.5 Complexity index (+0.5 atomic)
                    const indentation = `${indent}\t`; // ---------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    let json = `{\n`; // --------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    obj = JsonService.deleteUndefinedProperties(obj); // ------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    json = JsonService.addProperties(obj, indentation, json); // ----------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                    json = `${json}${indentation.slice(0, -1)}}`; // ----------------------------- +2.7 Complexity index (+0.7 atomic, +1 structural, +1 use)
                    return json; // -------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
addProperties Complexity Index 18.9 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Adds properties to a json object
                 * @param obj               // The javascript object
                 * @param indentation       // The previous indentation
                 * @param json              // The initial json object
                 */
                private static addProperties(obj: object, indentation: string, json: string): string { // ------- +0.7 Complexity index (+0.7 atomic)
                    for (const key of Object.keys(obj)) { // ---------------------------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                        json = `${json}${indentation}"${key}": `; // -------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                        switch (typeof obj[key]) { // ----------------------------------------------------------- +1.8 Complexity index (+0.3 atomic, +0.5 nesting, +1 structural)
                            case 'number': // ------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                            case 'bigint': // ------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                            case 'boolean': // ------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                                json = `${json}${obj[key]}${JsonService.comma(obj, key)}\n`; // ----------------- +1.9 Complexity index (+0.9 atomic, +1 structural)
                                break;
                            case 'string': // ------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                                json = JsonService.getStringProperty(obj, key, json) // ------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                                break;
                            case 'object': // ------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                                obj[key] = JsonService.deleteUndefinedProperties(obj[key]); // ------------------ +1.7 Complexity index (+0.7 atomic, +1 structural)
                                json = Array.isArray(obj[key]) // ----------------------------------------------- +3.7 Complexity index (+0.7 atomic, +1 nesting, +2 structural)
                                    ? JsonService.jsonArray(obj, key, indentation, json) // --------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                                    : JsonService.jsonObject(obj, key, indentation, json); // ------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                                break;
                        }
                    }
            
                    return json; // ----------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
deleteUndefinedProperties Complexity Index 5.1 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Removes all properties with undefined values
                 * @param obj       // The object to clean
                 */
                private static deleteUndefinedProperties(obj: object): object { // ------- +0.2 Complexity index (+0.2 atomic)
                    for (const key of Object.keys(obj)) { // ----------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                        if (obj[key] === undefined) { // --------------------------------- +2.0 Complexity index (+0.5 atomic, +0.5 nesting, +1 structural)
                            delete obj[key]; // ------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                        }
                    }
            
                    return obj; // ------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getStringProperty Complexity Index 5.6 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Returns the Json property value when this property os a string
                 * In the case of this property is called "text", we know that this property contains source code, so we return it by taking car of the quotes and the break lines
                 * @param obj       // The ts object
                 * @param key       // The key of this object
                 * @param json      // The corresponding json object
                 */
                private static getStringProperty(obj: object, key: string, json: string): string { // --------------------------------------------------------------------------------------- +0.7 Complexity index (+0.7 atomic)
                    const text = key === 'text' ? JsonService.convertCodeToString(obj[key]) : obj[key]; // ---------------------------------------------------------------------------------- +3.2 Complexity index (+1.2 atomic, +2 structural)
                    return `${json}"${text}"${JsonService.comma(obj, key)}\n`; // ----------------------------------------------------------------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                }
            
                            
                        
convertCodeToString Complexity Index 4.9 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Replaces the special chars in source code which could be problematic when inserting this code in a json property (`"`, `\`)
                 * @param text      // The source code
                 */
                private static convertCodeToString(text: string): string { // --------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    let stringified: string = JSON.stringify({ 'text': text }); // ---------------------------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                    stringified = stringified.slice(9, -2); // ------------------------------------------------------------------------------------------ +2.6 Complexity index (+0.6 atomic, +1 structural, +1 use)
                    return stringified; // -------------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
comma Complexity Index 3.2 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Returns a comma at the end of a line if this line is the last one of a given object
                 * @param key       // The key to check if it's the last one
                 * @param obj       // The object to check
                 */
                private static comma(obj: object, key: string): string { // ------------------------------------- +0.5 Complexity index (+0.5 atomic)
                    return isLastKey(key, obj) ? '' : ','; // --------------------------------------------------- +2.7 Complexity index (+0.7 atomic, +2 structural)
                }
            
                            
                        
jsonArray Complexity Index 11.2 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * If a property of a given object is an array, it adds to the corresponding json all the lines corresponding to the elements of this array
                 * @param obj           // The object with a key which is an array
                 * @param key           // The key where obj[key] is an array
                 * @param indentation   // The current indentation of the json object
                 * @param json          // The corresponding json object
                 */
                private static jsonArray(obj: object, key: string, indentation: string, json: string): string { // --------------------------------------------------- +0.9 Complexity index (+0.9 atomic)
                    json = `${json}[\n`; // -------------------------------------------------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    for (let i = 0; i < obj[key].length; i++) { // --------------------------------------------------------------------------------------------------- +1.9 Complexity index (+0.9 atomic, +1 structural)
                        json = `${json}${indentation}\t${JsonService.prettifyJson(obj[key][i], `${indentation}\t`)}`; // --------------------------------------------- +3.0 Complexity index (+1.0 atomic, +1 aggregation, +1 structural)
                        json = isLastIndex(i, obj[key]) ? `${json}\n` : `${json},\n`; // ----------------------------------------------------------------------------- +3.4 Complexity index (+0.9 atomic, +0.5 nesting, +2 structural)
                    }
                    return `${json}${indentation}]${JsonService.comma(obj, key)}\n`; // ------------------------------------------------------------------------------ +1.7 Complexity index (+0.7 atomic, +1 structural)
                }
            
                            
                        
jsonObject Complexity Index 4 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * If a property of a given object is an object, it adds to the corresponding json all the lines corresponding to the elements of this object
                 * @param obj          // The object with a key which is an object
                 * @param key           // The key where obj[key] is an object
                 * @param indentation   // The current indentation of the json object
                 * @param json          // The corresponding json object
                 */
                private static jsonObject(obj: object, key: string, indentation: string, json: string): string { // ---------------------------------------------------- +0.9 Complexity index (+0.9 atomic)
                    return `${json}${JsonService.prettifyJson(obj[key], indentation)}${JsonService.comma(obj, key)}\n`; // --------------------------------------------- +3.1 Complexity index (+1.1 atomic, +2 structural)
                }
            
                            
                        
astPropertyNames Complexity Index 16.2 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * If ths property name is specific to Ts, we rename it in the corresponding jsonAst property name
                 * In this case, this method returns the renamed property. If not, it returns the original property name.
                 * @param obj       // The object to analyse
                 */
                static astPropertyNames(obj: object): object { // ------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    for (const key of Object.keys(obj)) { // ------------------------------------------------------------------------------ +2.5 Complexity index (+0.5 atomic, +2 structural)
                        switch (key) { // ------------------------------------------------------------------------------------------------- +1.7 Complexity index (+0.2 atomic, +0.5 nesting, +1 structural)
                            case 'tsFiles': // -------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                                obj['astFiles'] = JsonService.astPropertyNames(obj[key]); // ---------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                                delete obj[key]; // --------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                                break;
                            case 'tsNode': // --------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                                obj['astNode'] = JsonService.astPropertyNames(obj[key]); // ----------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
                                delete obj[key]; // --------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                                break;
                            default: // --------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                                if (key !== 'parent') { // -------------------------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +1 nesting, +1 structural)
                                    obj[key] = typeof obj[key] === 'object' ? JsonService.astPropertyNames(obj[key]) : obj[key]; // ------- +4.9 Complexity index (+1.4 atomic, +1.5 nesting, +2 structural)
                                }
                        }
                    }
                    return obj; // -------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }