gfw-api/gfw-subscription-api

View on GitHub

Showing 76 of 129 total issues

Function getBBoxQuery has a Cognitive Complexity of 9 (exceeds 5 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 55 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 transform has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    static async transform(results, layer, subscription, begin, end) {
        const alerts = await analysisService.execute(subscription, layer.slug, begin, end, true);
        if (alerts && alerts.length && alerts.length > 0) {
            const alertsFormat = [];
            let length = 10;
Severity: Minor
Found in app/src/presenters/formaPresenter.js - About 55 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 getQuery has a Cognitive Complexity of 9 (exceeds 5 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 55 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 exports has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = (() => {
    const loadAPI = (app, path = routersPath, pathApi) => {
        const routesFiles = fs.readdirSync(path);
        let existIndexRouter = false;
        routesFiles.forEach((file) => {
Severity: Minor
Found in app/src/loader.js - About 55 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 deeply nested control flow statements.
Open

                                    if (res && res.statusCode < 400) {
                                        logger.info(`Successfully POSTed to subscription web-hook with status code ${res.statusCode}:`, subscription, body);
                                        return;
                                    }
Severity: Major
Found in app/src/services/datasetService.js - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        if (!data[i].params.geom) {
                            // eslint-disable-next-line no-continue
                            continue;
                        }
    Severity: Major
    Found in app/src/migrate/migrate.js - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if (!geostore.body.data) {
                              logger.error('Is not correct');
                              logger.error(data[i].params.geom);
                              // eslint-disable-next-line no-continue
                              continue;
      Severity: Major
      Found in app/src/migrate/migrate.js - About 45 mins to fix

        Function getGeostoreIdFromSubscriptionParams has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            static async getGeostoreIdFromSubscriptionParams(params) {
                if (params.geostore) {
                    return params.geostore;
                }
        
        
        Severity: Minor
        Found in app/src/services/geostoreService.js - About 45 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 deeply nested control flow statements.
        Open

                                        if (subscription.env && subscription.env !== 'production') {
                                            template += `-${subscription.env}`;
                                        }
        Severity: Major
        Found in app/src/services/datasetService.js - About 45 mins to fix

          Consider simplifying this complex logical expression.
          Open

              if (
                  task.dataset !== 'viirs-active-fires'
                  && task.dataset !== 'story'
                  && task.dataset !== 'forma-alerts'
                  && task.dataset !== 'forma250GFW'
          Severity: Major
          Found in app/src/cronLoader.js - About 40 mins to fix

            Consider simplifying this complex logical expression.
            Open

                                    if (result.data && result.data.length === 1 && result.data[0].value && result.data[0].value > 0) {
                                        // getting metadata first
                                        const metadata = await DatasetService.getMetadata(datasetQuery.id, subscription.application, subscription.language);
                                        const areaName = subscription.params.area ? await DatasetService.getAreaName(subscription.params.area) : '';
                                        const datasetName = metadata[0].attributes.info.name || dataset.attributes.name || dataset.name;
            Severity: Major
            Found in app/src/services/datasetService.js - About 40 mins to fix

              Function getTask has a Cognitive Complexity of 7 (exceeds 5 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 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 subscriptionExists has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              const subscriptionExists = (isForUser) => async (ctx, next) => {
                  const { id } = ctx.params;
              
                  if (!mongoose.Types.ObjectId.isValid(id)) {
                      ctx.throw(400, 'ID is not valid');
              Severity: Minor
              Found in app/src/routes/api/v1/subscription.router.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 transform has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  static async transform(results, layer, subscription, begin, end) {
              
                      results.alert_count_degradation = 0;
                      results.alert_count_deforestation = 0;
                      if (results.value) {
              Severity: Minor
              Found in app/src/presenters/imazonPresenter.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 getAllSubscriptions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  static async getAllSubscriptions(
                      link,
                      application = undefined,
                      env = undefined,
                      page = 1,
              Severity: Minor
              Found in app/src/services/subscriptionService.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 transform has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  transform() {
                      const stories = [];
                      if (this.results && this.results.length > 0) {
                          for (let i = 0, { length } = this.results; i < length; i++) {
                              stories.push({
              Severity: Minor
              Found in app/src/adapters/storyAdapter.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 null;
              Severity: Major
              Found in app/src/routes/api/v1/subscription.router.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return `/wdpa/${params.wdpaid}`;
                Severity: Major
                Found in app/src/services/analysisClassifier.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return null;
                  Severity: Major
                  Found in app/src/services/imageService.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return data.rows[0].bbox;
                    Severity: Major
                    Found in app/src/services/imageService.js - About 30 mins to fix
                      Severity
                      Category
                      Status
                      Source
                      Language