gfw-api/gfw-subscription-api

View on GitHub

Showing 129 of 129 total issues

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

    static async transform(results) {
        results.alert_count = results.value;
        let uri = `/query${results.downloadUrls.csv.split('download')[1]}`;
        uri = uri.replace('ORDER BY year, day', ' ORDER BY day DESC, year DESC LIMIT 10').replace(/&format=(csv|json|xml)/g, '');

Severity: Minor
Found in app/src/presenters/terraiPresenter.js - About 1 hr to fix

    Function findAllSubscriptions has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static async findAllSubscriptions(ctx) {
            logger.info(`[SubscriptionsRouter] Getting ALL subscriptions`);
    
            const page = ctx.query.page && ctx.query.page.number ? parseInt(ctx.query.page.number, 10) : 1;
            const limit = ctx.query.page && ctx.query.page.size ? parseInt(ctx.query.page.size, 10) : 10;
    Severity: Minor
    Found in app/src/routes/api/v1/subscription.router.js - About 1 hr to fix

      Function transform has 26 lines of code (exceeds 25 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 1 hr to fix

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

                const page = ctx.query.page && ctx.query.page.number ? parseInt(ctx.query.page.number, 10) : 1;
        Severity: Minor
        Found in app/src/routes/api/v1/subscription.router.js and 1 other location - About 55 mins to fix
        app/src/routes/api/v1/subscription.router.js on lines 288..288

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

        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

                const limit = ctx.query.page && ctx.query.page.size ? parseInt(ctx.query.page.size, 10) : 10;
        Severity: Minor
        Found in app/src/routes/api/v1/subscription.router.js and 1 other location - About 55 mins to fix
        app/src/routes/api/v1/subscription.router.js on lines 287..287

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

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

        function getBBoxOfGeojson(geojson) {
            const points = explode(geojson);
            let minx = 360;
            let
                miny = 360;
        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 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

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

        class GenericAdapter {
        
            constructor(results) {
                this.results = results;
            }
        Severity: Minor
        Found in app/src/adapters/genericAdapter.js and 1 other location - About 50 mins to fix
        app/src/adapters/forma250Adapter.js on lines 1..13

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

        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 Forma250Adapter {
        
            constructor(results) {
                this.results = results;
            }
        Severity: Minor
        Found in app/src/adapters/forma250Adapter.js and 1 other location - About 50 mins to fix
        app/src/adapters/genericAdapter.js on lines 1..13

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

        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

        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

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

                      const result = await ctRegisterMicroservice.requestToMicroservice({
                          uri: `/geostore/${subscription.params.geostore}`,
                          method: 'GET',
                          json: true
                      });
          Severity: Minor
          Found in app/src/services/imageService.js and 1 other location - About 45 mins to fix
          app/src/services/imageService.js on lines 53..57

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

          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

          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

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

                            const result = await ctRegisterMicroservice.requestToMicroservice({
                                uri: `/geostore/${subscription.params.geostore}`,
                                method: 'GET',
                                json: true
                            });
                Severity: Minor
                Found in app/src/services/imageService.js and 1 other location - About 45 mins to fix
                app/src/services/imageService.js on lines 111..115

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

                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 (
                        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
                  Severity
                  Category
                  Status
                  Source
                  Language