resource-watch/control-tower

View on GitHub
app/src/routes/dispatcher.js

Summary

Maintainability
D
1 day
Test Coverage
F
58%

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);
Severity: Minor
Found in app/src/routes/dispatcher.js - About 1 day 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 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);
Severity: Major
Found in app/src/routes/dispatcher.js - About 3 hrs to fix

    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;
                }
    Severity: Minor
    Found in app/src/routes/dispatcher.js - About 35 mins 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

    Avoid too many return statements within this function.
    Open

                    return;
    Severity: Major
    Found in app/src/routes/dispatcher.js - About 30 mins to fix

      There are no issues that match your filters.

      Category
      Status