gfw-api/gfw-subscription-api

View on GitHub

Showing 129 of 129 total issues

Function processMessage has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static async processMessage(channel, message) {
        logger.info('[AlertQueue] Processing alert message');
        logger.debug(`[AlertQueue] Processing alert message: ${message}`);

        if (JSON.parse(message).layer_slug === 'dataset') {
Severity: Major
Found in app/src/queues/alert.queue.js - About 2 hrs to fix

    Function exports has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports = (grunt) => {
    
        grunt.file.setBase('..');
        // eslint-disable-next-line import/no-extraneous-dependencies
        require('load-grunt-tasks')(grunt);
    Severity: Major
    Found in app/Gruntfile.js - About 2 hrs to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      class GladAdapter {
      
          constructor(results) {
              this.results = results;
          }
      Severity: Major
      Found in app/src/adapters/gladAdapter.js and 1 other location - About 2 hrs to fix
      app/src/adapters/viirsAdapter.js on lines 1..12

      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 76.

      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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      class ViirsAdapter {
      
          constructor(results) {
              this.results = results;
          }
      Severity: Major
      Found in app/src/adapters/viirsAdapter.js and 1 other location - About 2 hrs to fix
      app/src/adapters/gladAdapter.js on lines 1..12

      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 76.

      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

      Consider simplifying this complex logical expression.
      Open

                  if (data[i].confirmed) {
                      //  logger.debug('Saving data', data[i]);
                      let userId = null;
                      if (data[i].user_id) {
                          userId = await obtainNewUserId(data[i].user_id);
      Severity: Critical
      Found in app/src/migrate/migrate.js - About 2 hrs to fix

        Function getGeostoreIdByArea has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async getGeostoreIdByArea(idArea) {
                try {
                    logger.info('Obtaining area with id: ', idArea);
                    const areaResult = await ctRegisterMicroservice.requestToMicroservice({
                        uri: `/area/${idArea}`,
        Severity: Minor
        Found in app/src/services/datasetService.js - About 1 hr to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              static async getGeostoreFromISOCountryCode(countryCode) {
                  const uri = `/v2/geostore/admin/${countryCode}`;
                  const response = await ctRegisterMicroservice.requestToMicroservice({
                      uri,
                      method: 'GET',
          Severity: Major
          Found in app/src/services/geostoreService.js and 1 other location - About 1 hr to fix
          app/src/services/geostoreService.js on lines 68..77

          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 74.

          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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              static async getGeostoreFromWDPAID(wdpaId) {
                  const uri = `/v2/geostore/wdpa/${wdpaId}`;
                  const response = await ctRegisterMicroservice.requestToMicroservice({
                      uri,
                      method: 'GET',
          Severity: Major
          Found in app/src/services/geostoreService.js and 1 other location - About 1 hr to fix
          app/src/services/geostoreService.js on lines 35..44

          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 74.

          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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              static getURLInPeriodForGeostore(startDate, endDate, geostoreId) {
                  const sql = `SELECT * FROM data WHERE alert__date > '${startDate}' AND alert__date <= '${endDate}' `
                      + `AND geostore__id = '${geostoreId}' ORDER BY alert__date`;
                  return `/query/${config.get('datasets.viirsGeostoreDataset')}?sql=${sql}`;
              }
          Severity: Major
          Found in app/src/services/viirsAlertsService.js and 1 other location - About 1 hr to fix
          app/src/services/gladAlertsService.js on lines 66..70

          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 72.

          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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              static getURLInPeriodForGeostore(startDate, endDate, geostoreId) {
                  const sql = `SELECT * FROM data WHERE alert__date > '${startDate}' AND alert__date <= '${endDate}' `
                      + `AND geostore__id = '${geostoreId}' ORDER BY alert__date`;
                  return `/query/${config.get('datasets.gladGeostoreDataset')}?sql=${sql}`;
              }
          Severity: Major
          Found in app/src/services/gladAlertsService.js and 1 other location - About 1 hr to fix
          app/src/services/viirsAlertsService.js on lines 65..69

          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 72.

          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 getBBoxQuery has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          async function getBBoxQuery(client, subscription) {
              if (subscription.params.iso && subscription.params.iso.country) {
                  if (!subscription.params.iso.region) {
          
                      const data = await executeThunk(client, geoQuery.ISO_BBOX, {
          Severity: Minor
          Found in app/src/services/imageService.js - About 1 hr to fix

            Function translateFrequency has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static translateFrequency(status, lang = 'en') {
                    const translationsMap = {
                        en: {
                            'unusually high': 'unusually high',
                            high: 'high',
            Severity: Minor
            Found in app/src/services/emailHelpersService.js - About 1 hr to fix

              Function getQuery has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              async function getQuery(subscription) {
                  if (subscription.params.iso && subscription.params.iso.country) {
                      if (!subscription.params.iso.region) {
                          return Mustache.render(geoQuery.ISO, {
                              iso: subscription.params.iso.country
              Severity: Minor
              Found in app/src/services/imageService.js - About 1 hr to fix

                Function getGeostoreIdByArea has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    static async getGeostoreIdByArea(idArea) {
                        try {
                            logger.info('Obtaining area with id: ', idArea);
                            const areaResult = await ctRegisterMicroservice.requestToMicroservice({
                                uri: `/area/${idArea}`,
                Severity: Minor
                Found in app/src/services/datasetService.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 getTask has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                const getTask = async (task) => {
                    logger.info(`[cronLoader] Publishing ${task.dataset}`);
                    if (task.dataset === 'dataset') {
                        redisClient.publish(CHANNEL, JSON.stringify({
                            layer_slug: task.dataset
                Severity: Minor
                Found in app/src/cronLoader.js - About 1 hr to fix

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                          logger.debug(SubscriptionModel.aggregate([
                              { $match: { application: { $eq: application } } },
                              { $group: { _id: '$userId' } },
                              {
                                  $group: {
                  Severity: Major
                  Found in app/src/services/statisticsService.js and 1 other location - About 1 hr to fix
                  app/src/services/statisticsService.js on lines 223..231

                  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 66.

                  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

                          const usersWithSubscriptionResult = await SubscriptionModel.aggregate([
                              { $match: { application: { $eq: application } } },
                              { $group: { _id: '$userId' } },
                              {
                                  $group: {
                  Severity: Major
                  Found in app/src/services/statisticsService.js and 1 other location - About 1 hr to fix
                  app/src/services/statisticsService.js on lines 212..222

                  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 66.

                  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 getTopSubscriptions has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      static async getTopSubscriptions(startDate, endDate, application) {
                          logger.debug(`Obtaining getTopSubscriptions with startDate ${startDate}, endDate ${endDate} and application ${application}`);
                          const topSubs = {};
                          const defaultFilter = {
                              createdAt: { $gte: startDate, $lt: endDate },
                  Severity: Minor
                  Found in app/src/services/statisticsService.js - About 1 hr to fix

                    Function pathFor has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        static pathFor(subscription, layerSlug) {
                            const params = subscription.params || {};
                    
                            if (layerSlug === 'story') {
                                if (params.iso && params.iso.country) {
                    Severity: Minor
                    Found in app/src/services/analysisClassifier.js - About 1 hr to fix

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                                              if (!data[dat].countries[sub.params.iso.country]) {
                                                  data[dat].countries[sub.params.iso.country] = 0;
                                              }
                      Severity: Major
                      Found in app/src/services/statisticsService.js and 1 other location - About 1 hr to fix
                      app/src/services/statisticsService.js on lines 161..163

                      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

                      Severity
                      Category
                      Status
                      Source
                      Language