Genese complexity report

<- file.service.ts
Methods : 20
Complexity index : 144.9
Cyclomatic complexity : 43
Cognitive complexity
80 % Correct 16/20
20 % Warning 4/20 (threshold : 10)
0 % Error 0/20 (threshold : 20)
Cyclomatic complexity
100 % Correct 20/20
0 % Warning 0/20 (threshold : 5)
0 % Error 0/20 (threshold : 10)
Methods of file.service.ts
getFilename Complexity Index 2.5 Cyclomatic complexity 1
                            
                                
            
            
            /**
             * Tools about files or folders
             */
            
            
            /**
             * Returns the name of the file at a given path
             * @param pathFile      // The path of the file
             */
            export function getFilename(pathFile = ''): string { // -------------- +0.4 Complexity index (+0.4 atomic)
                const splittedPath = pathFile.split('/'); // --------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                return splittedPath[splittedPath.length - 1]; // ----------------- +0.6 Complexity index (+0.6 atomic)
            }
            
                            
                        
getAllFiles Complexity Index 17.7 Cyclomatic complexity 3
                            
                                
            
            
            
            /**
             * Returns the array of files included in a given folder and its subfolders
             * The files are returned as strings
             * @param dirPath           // The path of the folder
             * @param arrayOfFiles      // Recursion parameter
             */
            export function getAllFiles(dirPath: string, arrayOfFiles?: string[]): string[] { // ------- +0.8 Complexity index (+0.8 atomic)
                const files = fs.readdirSync(dirPath) // ----------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                arrayOfFiles = arrayOfFiles || []; // -------------------------------------------------- +3.5 Complexity index (+0.5 atomic, +2 aggregation, +1 structural)
                files.forEach(function(file) { // ------------------------------------------------------ +2.4 Complexity index (+0.4 atomic, +2 structural)
                    if (fs.statSync(dirPath + "/" + file).isDirectory()) { // -------------------------- +4.9 Complexity index (+0.9 atomic, +1 nesting, +3 structural)
                        arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles); // ------------- +1.9 Complexity index (+0.9 atomic, +1 structural)
                    } else { // ------------------------------------------------------------------------ +1.1 Complexity index (+0.1 atomic, +1 structural)
                        arrayOfFiles.push(`${dirPath}/${file}`); // ------------------------------------ +1.4 Complexity index (+0.4 atomic, +1 structural)
                    }
                });
                return arrayOfFiles; // ---------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
            }
            
                            
                        
getArrayOfPathsWithDotSlash Complexity Index 7.5 Cyclomatic complexity 3
                            
                                
            
            
            
            /**
             * Returns an array of paths with a ./ at the beginning
             * @param paths         // The array of paths
             */
            export function getArrayOfPathsWithDotSlash(paths: string[]): string[] { // ------- +0.6 Complexity index (+0.6 atomic)
                if (!Array.isArray(paths)) { // ----------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                    return undefined; // ------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                }
                const pathsWithDotSlash: string[] = []; // ------------------------------------ +0.4 Complexity index (+0.4 atomic)
                for (const path of paths) { // ------------------------------------------------ +1.3 Complexity index (+0.3 atomic, +1 structural)
                    pathsWithDotSlash.push(getPathWithDotSlash(path)); // --------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                }
                return pathsWithDotSlash; // -------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
            }
            
                            
                        
getPathWithDotSlash Complexity Index 8.9 Cyclomatic complexity 5
                            
                                
            
            
            
            /**
             * Returns a path with a ./ at the beginning
             * @param path      // The path to analyse
             */
            export function getPathWithDotSlash(path: string): string { // ------- +0.4 Complexity index (+0.4 atomic)
                let pathWithDotSlash = path; // ---------------------------------- +0.3 Complexity index (+0.3 atomic)
                if (path?.slice(0, 1) === '/') { // ------------------------------ +3.7 Complexity index (+0.7 atomic, +2 structural, +1 use)
                    pathWithDotSlash = `.${pathWithDotSlash}`; // ---------------- +0.3 Complexity index (+0.3 atomic)
                } else if (path?.slice(0, 2) !== './') { // ---------------------- +3.7 Complexity index (+0.7 atomic, +2 structural, +1 use)
                    pathWithDotSlash = `./${path}`; // --------------------------- +0.3 Complexity index (+0.3 atomic)
                }
                return pathWithDotSlash; // -------------------------------------- +0.2 Complexity index (+0.2 atomic)
            }
            
                            
                        
getPathWithSlash Complexity Index 4.3 Cyclomatic complexity 2
                            
                                
            
            
            
            /**
             * Returns a path with a ./ at the beginning
             * @param path      // The path to analyse
             */
            export function getPathWithSlash(path: string): string { // ------- +0.4 Complexity index (+0.4 atomic)
                return path?.slice(-1) !== '/' ? `${path}/` : path; // -------- +3.9 Complexity index (+0.9 atomic, +2 structural, +1 use)
            }
            
                            
                        
getRouteToRoot Complexity Index 14 Cyclomatic complexity 4
                            
                                
            
            
            
            /**
             * Returns the path between a subfolder and its root
             * For example, if relativePath = 'my/relative/path', it will return '../../..
             * @param relativePath      // The path to analyse
             */
            export function getRouteToRoot(relativePath: string): string { // ----------------------- +0.4 Complexity index (+0.4 atomic)
                if (!relativePath) { // ------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    return ''; // ------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
                let relativeRoot = '/..'; // -------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                for (let i = 0; i < relativePath.length; i++) { // ---------------------------------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    relativeRoot = // --------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                        relativePath.charAt(i) === constructLink("/") && // ------------------------- +5.4 Complexity index (+0.9 atomic, +0.5 nesting, +4 structural)
                            i !== relativePath.length - 1 // ---------------------------------------- +0.6 Complexity index (+0.6 atomic)
                            ? constructLink("/") + `..${relativeRoot}` // --------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                            : relativeRoot; // ------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                }
                return relativeRoot.slice(1); // ---------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +1 structural, +1 use)
            }
            
                            
                        
getFileExtension Complexity Index 4.2 Cyclomatic complexity 1
                            
                                
            
            
            
            /**
             * Returns the extension of a file
             * @param filename      // The name of the file
             */
            export function getFileExtension(filename: string): string { // ------- +0.4 Complexity index (+0.4 atomic)
                return filename ? filename.split('.').pop() : ''; // -------------- +3.8 Complexity index (+0.8 atomic, +3 structural)
            }
            
                            
                        
getFilenameWithoutExtension Complexity Index 8.9 Cyclomatic complexity 2
                            
                                
            
            
            
            /**
             * Returns the filename without its extension
             * @param filename      // The name of the file
             */
            export function getFilenameWithoutExtension(path: string): string { // ------- +0.4 Complexity index (+0.4 atomic)
                if (!path) { // ---------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    return ''; // -------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
                const filename = path.substring(path.lastIndexOf('/') + 1); // ----------- +2.9 Complexity index (+0.9 atomic, +2 structural)
            
                const extensionLength = getFileExtension(filename).length; // ------------ +1.5 Complexity index (+0.5 atomic, +1 structural)
                return filename.slice(0, -(extensionLength + 1)); // --------------------- +2.7 Complexity index (+0.7 atomic, +1 structural, +1 use)
            }
            
                            
                        
getLanguageExtensions Complexity Index 3.8 Cyclomatic complexity 1
                            
                                
            
            
            
            export function getLanguageExtensions(language: string): string[] { // ------- +0.5 Complexity index (+0.5 atomic)
                switch (language) { // --------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                    case 'java': // ------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                        return ['java']; // ---------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    case 'json': // ------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                        return ['json']; // ---------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    case 'php': // ------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                        return ['php']; // ----------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    case 'typescript': // ------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    case 'ts': // -------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                        return ['ts']; // ------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    default: // ---------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        return ['json']; // ---------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            }
            
                            
                        
createRelativeDir Complexity Index 7 Cyclomatic complexity 2
                            
                                
            
            
            
            /**
             * Creates a subFolder of the outDir folder
             * @param relativePath      // The relative path of the subfolder compared to the outDir path
             */
            export function createRelativeDir(relativePath: string): void { // ------------------------------------- +0.4 Complexity index (+0.4 atomic)
                const path = `${Options.pathOutDir}/${relativePath}`; // ------------------------------------------- +0.5 Complexity index (+0.5 atomic)
                if (fs.existsSync(path)) { // ---------------------------------------------------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                    fs.emptyDirSync(path); // ---------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                } else { // ---------------------------------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                    fs.mkdirsSync(path); // ------------------------------------------------------------------------ +1.3 Complexity index (+0.3 atomic, +1 structural)
                }
            }
            
                            
                        
createOutDir Complexity Index 6.6 Cyclomatic complexity 2
                            
                                
            
            
            
            /**
             * Creates the outDir folder
             */
            export function createOutDir(): void { // ------------- +0.2 Complexity index (+0.2 atomic)
                if (fs.existsSync(Options.pathOutDir)) { // ------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                    fs.emptyDirSync(Options.pathOutDir); // ------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                } else { // --------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                    fs.mkdirsSync(Options.pathOutDir); // --------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                }
            }
            
                            
                        
deleteFile Complexity Index 4.1 Cyclomatic complexity 2
                            
                                
            
            
            export function deleteFile(fileName: string): void { // ------- +0.4 Complexity index (+0.4 atomic)
                if (fs.existsSync(fileName)) { // ------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                    fs.unlinkSync(fileName); // --------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                }
            }
            
                            
                        
copyFile Complexity Index 4.2 Cyclomatic complexity 1
                            
                                
            
            
            
            /**
             * Copy a file from a path to another one
             * @param originPath        // The origin's path
             * @param targetPath        // The target's path
             */
            export function copyFile(originPath: string, targetPath: string): void { // --------- +0.6 Complexity index (+0.6 atomic)
                fs.copyFileSync(constructLink(originPath), constructLink(targetPath)); // ------- +3.6 Complexity index (+0.6 atomic, +3 structural)
            }
            
                            
                        
platformPath Complexity Index 8.3 Cyclomatic complexity 1
                            
                                
            
            
            
            export function platformPath(path: string): string { // ----------------------------- +0.4 Complexity index (+0.4 atomic)
                const modifiedPath = path.split('/').filter(e => e !== '.').join('/'); // ------- +5.3 Complexity index (+1.3 atomic, +4 structural)
                return WINDOWS ? windowsPath(modifiedPath) : modifiedPath; // ------------------- +2.6 Complexity index (+0.6 atomic, +2 structural)
            }
            
                            
                        
windowsPath Complexity Index 5.8 Cyclomatic complexity 1
                            
                                
            
            
            
            export function windowsPath(path: string): string { // --------------- +0.4 Complexity index (+0.4 atomic)
                return path.replace(/\//g, '\\').replace(/\\/g, '\\\\') // ------- +5.4 Complexity index (+0.8 atomic, +0.6 aggregation, +4 structural)
            }
            
                            
                        
createFile Complexity Index 2.2 Cyclomatic complexity 1
                            
                                
            
            
            
            /**
             * Copy a file from a path to another one
             * @param path
             * @param content
             */
            export function createFile(path: string, content: string): void { // ------- +0.6 Complexity index (+0.6 atomic)
                fs.writeFileSync(path, content, { encoding: "utf-8" }); // ------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
            }
            
                            
                        
getOS Complexity Index 16.1 Cyclomatic complexity 5
                            
                                
            
            
            /**
             * Get the current OS
             * @returns {OS}
             */
            export function getOS(): OS { // --------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                let platform = process.platform; // -------------------------------------------- +0.4 Complexity index (+0.4 atomic)
            
                let macosPlatforms = ["MACINTOSH", "MACINTEL", "MACPPC", "MAC68K"]; // --------- +0.6 Complexity index (+0.6 atomic)
                let windowsPlatforms = ["WIN32", "WIN64", "WINDOWS", "WINCE"]; // -------------- +0.6 Complexity index (+0.6 atomic)
                let os = null; // -------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
            
                if (macosPlatforms.indexOf(platform.toUpperCase()) !== -1) { // ---------------- +3.7 Complexity index (+0.7 atomic, +3 structural)
                    os = OS.MACOS; // ---------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                } else if (windowsPlatforms.indexOf(platform.toUpperCase()) !== -1) { // ------- +3.7 Complexity index (+0.7 atomic, +3 structural)
                    os = OS.WINDOWS; // -------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                } else if (!os && /Linux/.test(platform)) { // --------------------------------- +5.3 Complexity index (+0.7 atomic, +0.6 aggregation, +4 structural)
                    os = OS.LINUX; // ---------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                }
            
                return os; // ------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
            }
            
                            
                        
antislash Complexity Index 3 Cyclomatic complexity 1
                            
                                
            
            
            /**
             * Replace a slash by an antislash
             * @param text
             * @returns {string}
             */
            export function antislash(text: string): string { // ------- +0.4 Complexity index (+0.4 atomic)
                return text.split("/").join("\\"); // ------------------ +2.6 Complexity index (+0.6 atomic, +2 structural)
            }
            
                            
                        
deleteLastSlash Complexity Index 11.5 Cyclomatic complexity 4
                            
                                
            
            
            /**
             * Delete the last slash in a string
             * @param text
             * @returns {string}
             */
            export function deleteLastSlash(text: string): string { // ------------------ +0.4 Complexity index (+0.4 atomic)
                const TEXT_REWORK = (text && constructLink(text)) || ""; // ------------- +4.0 Complexity index (+1.0 atomic, +3 structural)
            
                return TEXT_REWORK && // ------------------------------------------------ +2.5 Complexity index (+0.5 atomic, +2 structural)
                    TEXT_REWORK[TEXT_REWORK.length - 1] === constructLink("/") // ------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    ? TEXT_REWORK.slice(0, TEXT_REWORK.length - 1) // ------------------- +2.7 Complexity index (+0.7 atomic, +1 structural, +1 use)
                    : TEXT_REWORK; // --------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
            }