gfw-api/gfw-geostore-api

View on GitHub

Showing 114 of 114 total issues

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

    static bboxToPolygon(bbox) {
        return turf.polygon([[[bbox[2], bbox[3]], [bbox[2], bbox[1]],
            [bbox[0], bbox[1]], [bbox[0], bbox[3]],
            [bbox[2], bbox[3]]]]);
    }
Severity: Major
Found in app/src/services/geoStoreService.js and 1 other location - About 2 hrs to fix
app/src/services/geoStoreServiceV2.js on lines 177..181

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

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 intersectWdpa(ctx) {
        logger.info(`Calculating intersect with wdpa ${ctx.params.id}`);
        const result = await CoverageService.getWdpa(ctx.params.id);

        ctx.body = CoverageSerializer.serialize({
Severity: Major
Found in app/src/routes/api/v1/coverage.router.js and 1 other location - About 2 hrs to fix
app/src/routes/api/v2/coverage.router.js on lines 53..61

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

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

    static bboxToPolygon(bbox) {
        return turf.polygon([[[bbox[2], bbox[3]], [bbox[2], bbox[1]],
            [bbox[0], bbox[1]], [bbox[0], bbox[3]],
            [bbox[2], bbox[3]]]]);
    }
Severity: Major
Found in app/src/services/geoStoreServiceV2.js and 1 other location - About 2 hrs to fix
app/src/services/geoStoreService.js on lines 185..189

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

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 intersectWdpa(ctx) {
        logger.info(`Calculating intersect with wdpa ${ctx.params.id}`);
        const result = await CoverageServiceV2.getWdpa(ctx.params.id);

        ctx.body = CoverageSerializer.serialize({
Severity: Major
Found in app/src/routes/api/v2/coverage.router.js and 1 other location - About 2 hrs to fix
app/src/routes/api/v1/coverage.router.js on lines 53..61

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

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

        async function onDbReady(mongoConnectionError) {
            if (mongoConnectionError) {
                if (retries >= 0) {
                    retries--;
                    logger.error(`Failed to connect to MongoDB uri ${mongoUri}, retrying...`);
Severity: Major
Found in app/src/app.js - About 2 hrs to fix

    Function exports has 64 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

      File geoStoreService.js has 273 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      const logger = require('logger');
      const GeoStore = require('models/geoStore');
      const GeoJSONConverter = require('converters/geoJSONConverter');
      const md5 = require('md5');
      const CartoDB = require('cartodb');
      Severity: Minor
      Found in app/src/services/geoStoreService.js - About 2 hrs to fix

        File cartoDBServiceV2.js has 271 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        const logger = require('logger');
        const config = require('config');
        const CartoDB = require('cartodb');
        const Mustache = require('mustache');
        const GeoStoreServiceV2 = require('services/geoStoreServiceV2');
        Severity: Minor
        Found in app/src/services/cartoDBServiceV2.js - About 2 hrs to fix

          Function saveGeostore has 61 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static async saveGeostore(geojson, data) {
                  const geoStore = {
                      geojson
                  };
          
          
          Severity: Major
          Found in app/src/services/geoStoreService.js - About 2 hrs to fix

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

                    if (thresh && typeof thresh === Number && (thresh > 1 || thresh <= 0)) {
                        ctx.throw(404, 'Bad threshold for simplify. Must be in range 0-1.');
                    } else if (thresh && typeof thresh === Boolean && thresh !== true) {
                        ctx.throw(404, 'Bad syntax for simplify. Must be "true".');
                    }
            Severity: Major
            Found in app/src/routes/api/v2/geoStore.router.js and 2 other locations - About 2 hrs to fix
            app/src/routes/api/v2/geoStore.router.js on lines 141..145
            app/src/routes/api/v2/geoStore.router.js on lines 182..186

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

            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 3 locations. Consider refactoring.
            Open

                    if (thresh && typeof thresh === Number && (thresh > 1 || thresh <= 0)) {
                        ctx.throw(404, 'Bad threshold for simplify. Must be in range 0-1.');
                    } else if (thresh && typeof thresh === Boolean && thresh !== true) {
                        ctx.throw(404, 'Bad syntax for simplify. Must be "true".');
                    }
            Severity: Major
            Found in app/src/routes/api/v2/geoStore.router.js and 2 other locations - About 2 hrs to fix
            app/src/routes/api/v2/geoStore.router.js on lines 166..170
            app/src/routes/api/v2/geoStore.router.js on lines 182..186

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

            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 3 locations. Consider refactoring.
            Open

                    if (thresh && typeof thresh === Number && (thresh > 1 || thresh <= 0)) {
                        ctx.throw(404, 'Bad threshold for simplify. Must be in range 0-1.');
                    } else if (thresh && typeof thresh === Boolean && thresh !== true) {
                        ctx.throw(404, 'Bad syntax for simplify. Must be "true".');
                    }
            Severity: Major
            Found in app/src/routes/api/v2/geoStore.router.js and 2 other locations - About 2 hrs to fix
            app/src/routes/api/v2/geoStore.router.js on lines 141..145
            app/src/routes/api/v2/geoStore.router.js on lines 166..170

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

            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 4 locations. Consider refactoring.
            Open

            const executeThunk = (client, sql, params) => new Promise(((resolve, reject) => {
                client.execute(sql, params).done((data) => {
                    resolve(data);
                }).error((err) => {
                    reject(err[0]);
            Severity: Major
            Found in app/src/services/coverageService.js and 3 other locations - About 2 hrs to fix
            app/src/services/coverageServiceV2.js on lines 35..41
            app/src/services/geoStoreService.js on lines 15..21
            app/src/services/geoStoreServiceV2.js on lines 15..21

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

            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 4 locations. Consider refactoring.
            Open

            const executeThunk = (client, sql, params) => new Promise(((resolve, reject) => {
                client.execute(sql, params).done((data) => {
                    resolve(data);
                }).error((err) => {
                    reject(err[0]);
            Severity: Major
            Found in app/src/services/geoStoreServiceV2.js and 3 other locations - About 2 hrs to fix
            app/src/services/coverageService.js on lines 35..41
            app/src/services/coverageServiceV2.js on lines 35..41
            app/src/services/geoStoreService.js on lines 15..21

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

            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 4 locations. Consider refactoring.
            Open

            const executeThunk = (client, sql, params) => new Promise(((resolve, reject) => {
                client.execute(sql, params).done((data) => {
                    resolve(data);
                }).error((err) => {
                    reject(err[0]);
            Severity: Major
            Found in app/src/services/geoStoreService.js and 3 other locations - About 2 hrs to fix
            app/src/services/coverageService.js on lines 35..41
            app/src/services/coverageServiceV2.js on lines 35..41
            app/src/services/geoStoreServiceV2.js on lines 15..21

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

            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 4 locations. Consider refactoring.
            Open

            const executeThunk = (client, sql, params) => new Promise(((resolve, reject) => {
                client.execute(sql, params).done((data) => {
                    resolve(data);
                }).error((err) => {
                    reject(err[0]);
            Severity: Major
            Found in app/src/services/coverageServiceV2.js and 3 other locations - About 2 hrs to fix
            app/src/services/coverageService.js on lines 35..41
            app/src/services/geoStoreService.js on lines 15..21
            app/src/services/geoStoreServiceV2.js on lines 15..21

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

            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 getNationalList(ctx) {
                    logger.info('Obtaining national list');
                    const data = await CartoService.getNationalList();
                    if (!data) {
                        ctx.throw(404, 'Empty List');
            Severity: Major
            Found in app/src/routes/api/v1/geoStore.router.js and 1 other location - About 2 hrs to fix
            app/src/routes/api/v2/geoStore.router.js on lines 153..160

            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

                static async getNationalList(ctx) {
                    logger.info('Obtaining national list (GADM v3.6)');
                    const data = await CartoServiceV2.getNationalList();
                    if (!data) {
                        ctx.throw(404, 'Empty List');
            Severity: Major
            Found in app/src/routes/api/v2/geoStore.router.js and 1 other location - About 2 hrs to fix
            app/src/routes/api/v1/geoStore.router.js on lines 142..149

            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

            Function saveGeostore has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                static async saveGeostore(geojson, data) {
                    const geoStore = {
                        geojson
                    };
            
            
            Severity: Minor
            Found in app/src/services/geoStoreService.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 exports has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = (() => {
            
                const loadAPI = (app, path, pathApi) => {
                    const routesFiles = fs.readdirSync(path);
                    let existIndexRouter = false;
            Severity: Minor
            Found in app/src/loader.js - About 1 hr to fix
              Severity
              Category
              Status
              Source
              Language