resource-watch/control-tower

View on GitHub

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);
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 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

    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 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
      Severity: Major
      Found in app/Gruntfile.js - About 3 hrs to fix

        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) {
        Severity: Major
        Found in app/src/app.js - About 2 hrs to fix

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

            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--;
            Severity: Major
            Found in app/src/app.js - About 2 hrs to fix

              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;
              Severity: Minor
              Found in app/src/serializers/microservice.serializer.js - About 1 hr 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 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
              Severity: Minor
              Found in app/src/services/microservice.service.js - About 1 hr 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 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({
              Severity: Minor
              Found in app/src/services/microservice.service.js - About 1 hr to fix

                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)
                Severity: Major
                Found in app/src/loader.js and 1 other location - About 1 hr to fix
                app/src/loader.js on lines 43..49

                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

                Further Reading

                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)
                Severity: Major
                Found in app/src/loader.js and 1 other location - About 1 hr to fix
                app/src/loader.js on lines 62..68

                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

                Further Reading

                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;
                Severity: Minor
                Found in app/src/loader.js - About 1 hr to fix

                  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;
                  Severity: Minor
                  Found in app/src/serializers/microservice.serializer.js - About 1 hr to fix

                    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');
                    Severity: Minor
                    Found in app/src/services/getUserFromToken.service.js - About 1 hr 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

                        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

                        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({
                        Severity: Minor
                        Found in app/src/services/microservice.service.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
                          Severity
                          Category
                          Status
                          Source
                          Language