Showing 19 of 21 total issues
Function dispatch
has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring. Open
static async dispatch(ctx) {
logger.info(`Dispatch url ${ctx.request.url} and method ${ctx.request.method}`);
try {
logger.debug('Obtaining config request');
const infoRequest = await DispatcherService.getRequest(ctx);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getRequest
has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring. Open
static async getRequest(ctx) {
logger.info(`[DispatcherService - getRequest] Searching endpoint where redirect url ${ctx.request.url}
and method ${ctx.request.method}`);
const parsedUrl = url.parse(ctx.request.url);
const endpoint = await Dispatcher.getEndpoint(parsedUrl.pathname, ctx.request.method);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getRequest
has 106 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async getRequest(ctx) {
logger.info(`[DispatcherService - getRequest] Searching endpoint where redirect url ${ctx.request.url}
and method ${ctx.request.method}`);
const parsedUrl = url.parse(ctx.request.url);
const endpoint = await Dispatcher.getEndpoint(parsedUrl.pathname, ctx.request.method);
Function dispatch
has 92 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async dispatch(ctx) {
logger.info(`Dispatch url ${ctx.request.url} and method ${ctx.request.method}`);
try {
logger.debug('Obtaining config request');
const infoRequest = await DispatcherService.getRequest(ctx);
Function exports
has 91 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = (grunt) => {
grunt.file.setBase('..');
// eslint-disable-next-line import/no-extraneous-dependencies
Function init
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
async function init() {
return new Promise((resolve, reject) => {
async function onDbReady(err) {
if (err) {
if (retries >= 0) {
Function onDbReady
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
async function onDbReady(err) {
if (err) {
if (retries >= 0) {
// eslint-disable-next-line no-plusplus
retries--;
Function saveEndpoint
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async saveEndpoint(endpoint, microservice) {
logger.info(`[MicroserviceService] Saving endpoint ${endpoint.path}`);
logger.debug(`[MicroserviceService] Searching if path ${endpoint.path} exists in endpoints`);
endpoint.redirect.url = microservice.url;
// searching
Function saveEndpoint
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
static async saveEndpoint(endpoint, microservice) {
logger.info(`[MicroserviceService] Saving endpoint ${endpoint.path}`);
logger.debug(`[MicroserviceService] Searching if path ${endpoint.path} exists in endpoints`);
endpoint.redirect.url = microservice.url;
// searching
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function serialize
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
static serialize(data, link = null) {
const result = {};
if (data && Array.isArray(data) && data.length === 0) {
result.data = [];
return result;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function register
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async register(name, url, endpoints) {
try {
logger.info(`[MicroserviceRouter] Registering new microservice with name ${name} and url ${url}`);
logger.debug('[MicroserviceRouter] Search if microservice already exist');
const existingMicroservice = await MicroserviceModel.findOne({
Function loadAPI
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
function loadAPI(app, routersPath, pathApi) {
const routesFiles = fs.readdirSync(routersPath);
let existIndexRouter = false;
routesFiles.forEach((file) => {
const newPath = routersPath ? `${routersPath}/${file}` : file;
Function serialize
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
static serialize(data, link = null) {
const result = {};
if (data && Array.isArray(data) && data.length === 0) {
result.data = [];
return result;
Function getLoggedUser
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
const getLoggedUser = async (ctx, next) => {
logger.debug('[getLoggedUser] Obtaining loggedUser for token');
if (!ctx.request.header.authorization) {
logger.debug('[getLoggedUser] No authorization header found, returning');
ctx.throw(401, 'Not authenticated');
Avoid deeply nested control flow statements. Open
if (configRequest.body[key] !== null && configRequest.body[key] !== undefined) {
if (typeof configRequest.body[key] === 'object') {
body[key] = JSON.stringify(configRequest.body[key]);
} else {
body[key] = configRequest.body[key];
Function register
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
static async register(name, url, endpoints) {
try {
logger.info(`[MicroserviceRouter] Registering new microservice with name ${name} and url ${url}`);
logger.debug('[MicroserviceRouter] Search if microservice already exist');
const existingMicroservice = await MicroserviceModel.findOne({
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getLoggedUser
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
static getLoggedUser(ctx) {
if (ctx.state) {
if (ctx.state.user) {
return ctx.state.user;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return;
Function loadAPI
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function loadAPI(app, routersPath, pathApi) {
const routesFiles = fs.readdirSync(routersPath);
let existIndexRouter = false;
routesFiles.forEach((file) => {
const newPath = routersPath ? `${routersPath}/${file}` : file;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"