Showing 21 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 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 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 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 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 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({
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (pathApi) {
app.use(mount(pathApi, require(newPath)
.routes())); // eslint-disable-line global-require,max-len
} else {
app.use(require(newPath)
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 64.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (pathApi) {
app.use(mount(pathApi, require(newPath)
.routes())); // eslint-disable-line global-require,max-len
} else {
app.use(require(newPath)
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 64.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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 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
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
Avoid too many return
statements within this function. Open
return;