resource-watch/control-tower

View on GitHub
app/src/services/dispatcher.service.js

Summary

Maintainability
C
1 day
Test Coverage
A
94%

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);
Severity: Minor
Found in app/src/services/dispatcher.service.js - About 7 hrs to fix

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);
Severity: Major
Found in app/src/services/dispatcher.service.js - About 4 hrs to fix

    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];
    Severity: Major
    Found in app/src/services/dispatcher.service.js - About 45 mins to fix

      There are no issues that match your filters.

      Category
      Status