gfw-api/gfw-subscription-api

View on GitHub

Showing 129 of 129 total issues

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

Function getGeostoreIdByParams has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static async getGeostoreIdByParams(params) {
        try {
            let uri = '/geostore';
            if (params.use && params.useid) {
                uri += `/use/${params.use}/${params.useid}`;
Severity: Minor
Found in app/src/services/datasetService.js - About 1 hr to fix

    Function checkUpdated has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static async checkUpdated(dataset) {
            logger.info(`Checking if dataset ${dataset} was updated`);
            try {
                const result = await ctRegisterMicroservice.requestToMicroservice({
                    uri: `/${dataset}/latest`,
    Severity: Minor
    Found in app/src/services/updateService.js - About 1 hr to fix

      Function getGeostoreIdByParams has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          static async getGeostoreIdByParams(params) {
              try {
                  let uri = '/geostore';
                  if (params.use && params.useid) {
                      uri += `/use/${params.use}/${params.useid}`;
      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 execute has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async execute(subscription, layerSlug, begin, end, forSubscription) {
      
              logger.info('Executing analysis for', layerSlug, begin, end);
      
              const period = `${formatDate(begin)},${formatDate(end)}`;
      Severity: Minor
      Found in app/src/services/analysisService.js - About 1 hr to fix

        Function generate has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static generate(subscription, layer, begin, end) {
                const diffInDays = moment(begin).diff(moment(end), 'days');
        
                const queryForUrl = {
                    lang: subscription.language || 'en',
        Severity: Minor
        Found in app/src/services/alertUrlService.js - About 1 hr to fix

          Function infoSubscriptions has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

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

            Consider simplifying this complex logical expression.
            Open

                            if (
                                !data[i].params.iso
                                && !data[i].params.id1
                                && !data[i].params.wdpaid
                                && !data[i].params.use
            Severity: Critical
            Found in app/src/migrate/migrate.js - About 1 hr to fix

              Function transform has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static async transform(results, layer, subscription, begin, end) {
                      EmailHelpersService.updateMonthTranslations();
                      moment.locale(subscription.language || 'en');
              
                      try {
              Severity: Minor
              Found in app/src/presenters/viirsPresenter.js - About 1 hr to fix

                Function transform has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    static async transform(results, layer, subscription, begin, end) {
                        EmailHelpersService.updateMonthTranslations();
                        moment.locale(subscription.language || 'en');
                
                        try {
                Severity: Minor
                Found in app/src/presenters/gladPresenter.js - About 1 hr to fix

                  Function loadAPI has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      const loadAPI = (app, path = routersPath, pathApi) => {
                          const routesFiles = fs.readdirSync(path);
                          let existIndexRouter = false;
                          routesFiles.forEach((file) => {
                              const newPath = path ? (`${path}/${file}`) : file;
                  Severity: Minor
                  Found in app/src/loader.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).middleware()));
                                } else {
                                    app.use(require(newPath).middleware());
                                }
                    Severity: Major
                    Found in app/src/loader.js and 1 other location - About 1 hr to fix
                    app/src/loader.js on lines 22..26

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

                    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 mongoUri = process.env.MONGO_URI || `mongodb://${config.get('mongodb.host')}:${config.get('mongodb.port')}/${config.get('mongodb.database')}`;
                    Severity: Major
                    Found in app/src/migrate/migrate.js and 1 other location - About 1 hr to fix
                    app/src/app.js on lines 17..17

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

                    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 mongoUri = process.env.MONGO_URI || `mongodb://${config.get('mongodb.host')}:${config.get('mongodb.port')}/${config.get('mongodb.database')}`;
                    Severity: Major
                    Found in app/src/app.js and 1 other location - About 1 hr to fix
                    app/src/migrate/migrate.js on lines 12..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 60.

                    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).middleware()));
                                            } else {
                                                app.use(require(newPath).middleware());
                                            }
                    Severity: Major
                    Found in app/src/loader.js and 1 other location - About 1 hr to fix
                    app/src/loader.js on lines 39..43

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

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

                        async overviewImage(subscription, slug, begin, end) {
                            const query = await getQuery(subscription);
                            if (!query) {
                                return null;
                            }
                    Severity: Minor
                    Found in app/src/services/imageService.js - About 1 hr to fix

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

                                              data[dat].countries[sub.params.iso.country] = data[dat].countries[sub.params.iso.country] + 1;
                      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 164..164

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

                      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

                                              data[dat].regions[sub.params.iso.region] = data[dat].regions[sub.params.iso.region] + 1;
                      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 175..175

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

                      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 processMessage has a Cognitive Complexity of 10 (exceeds 5 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: Minor
                      Found in app/src/queues/alert.queue.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 decorateWithArea has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                      const decorateWithArea = (results, subscription) => {
                          const params = subscription.params || {};
                      
                          if (params.iso && params.iso.country) {
                              results.selected_area = `ISO Code: ${params.iso.country}`;
                      Severity: Minor
                      Found in app/src/presenters/analysisResultsPresenter.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

                      Severity
                      Category
                      Status
                      Source
                      Language