gfw-api/gfw-geostore-api

View on GitHub
app/src/services/geoStoreService.js

Summary

Maintainability
F
1 wk
Test Coverage
B
80%

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

    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

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

          static crossAntimeridian(feature, bbox) {
              logger.info('Checking antimeridian');
      
              const geomTypes = ['Point', 'MultiPoint'];
              const bboxTotal = bbox || turf.bbox(feature);
      Severity: Minor
      Found in app/src/services/geoStoreService.js - About 1 hr to fix

        Function crossAntimeridian has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            static crossAntimeridian(feature, bbox) {
                logger.info('Checking antimeridian');
        
                const geomTypes = ['Point', 'MultiPoint'];
                const bboxTotal = bbox || turf.bbox(feature);
        Severity: Minor
        Found in app/src/services/geoStoreService.js - About 25 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

            static crossAntimeridian(feature, bbox) {
                logger.info('Checking antimeridian');
        
                const geomTypes = ['Point', 'MultiPoint'];
                const bboxTotal = bbox || turf.bbox(feature);
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 2 days to fix
        app/src/services/geoStoreServiceV2.js on lines 191..238

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

        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 getGeometryType(geojson) {
                logger.debug('Get geometry type');
                logger.debug('Geometry type: %s', geojson.type);
        
                if (geojson.type === 'Point' || geojson.type === 'MultiPoint') {
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 5 hrs to fix
        app/src/services/geoStoreServiceV2.js on lines 25..39

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

        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 (geomType && geomType === 'FeatureCollection') {
                    logger.info('Preserving FeatureCollection properties.');
                    props = geoStore.geojson.features[0].properties || null;
                } else if (geomType && geomType === 'Feature') {
                    logger.info('Preserving Feature properties.');
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 4 hrs to fix
        app/src/services/geoStoreServiceV2.js on lines 306..315

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

        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

                if (data && data.provider) {
                    const geoJsonObtained = await GeoStoreService.obtainGeoJSON(data.provider);
                    geoStore.geojson = geoJsonObtained.geojson;
                    geoStore.areaHa = geoJsonObtained.area_ha;
                    geoStore.provider = {
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 4 hrs to fix
        app/src/services/geoStoreServiceV2.js on lines 293..303

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

        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 getMultipleGeostores(ids) {
                logger.debug(`Getting geostores with ids: ${ids}`);
                const hashes = await Promise.all(ids.map(GeoStoreService.getNewHash));
                const query = { hash: { $in: hashes } };
                const geoStores = await GeoStore.find(query);
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 4 hrs to fix
        app/src/services/geoStoreServiceV2.js on lines 116..126

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

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

                if (data.rows && data.rows.length === 1) {
                    data.rows[0].geojson = JSON.parse(data.rows[0].geojson);
                    logger.debug(data.rows[0].geojson);
                    return data.rows[0];
                }
        Severity: Major
        Found in app/src/services/geoStoreService.js and 2 other locations - About 3 hrs to fix
        app/src/services/geoStoreService.js on lines 73..77
        app/src/services/geoStoreServiceV2.js on lines 88..92

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

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

                    if (data.rows && data.rows.length === 1) {
                        data.rows[0].geojson = JSON.parse(data.rows[0].geojson);
                        logger.debug(data.rows[0].geojson);
                        return data.rows[0];
                    }
        Severity: Major
        Found in app/src/services/geoStoreService.js and 2 other locations - About 3 hrs to fix
        app/src/services/geoStoreService.js on lines 97..101
        app/src/services/geoStoreServiceV2.js on lines 88..92

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

        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 swapBBox(geoStore) {
                const orgBbox = turf.bbox(geoStore.geojson);
                const bbox = turf.featureReduce(
                    geoStore.geojson,
                    (previousValue, currentFeature) => GeoStoreService.crossAntimeridian(currentFeature, previousValue),
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 3 hrs to fix
        app/src/services/geoStoreServiceV2.js on lines 260..269

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

        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 obtainGeoJSON(provider) {
                logger.debug('Obtaining geojson of provider', provider);
                switch (provider.type) {
        
                    case CARTO_PROVIDER:
        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 147..158

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

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

                if (data && data.provider) {
                    const geoJsonObtained = await GeoStoreService.obtainGeoJSON(data.provider);
                    geoStore.geojson = geoJsonObtained.geojson;
                    geoStore.areaHa = geoJsonObtained.area_ha;
                }
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 1 hr to fix
        app/src/services/geoStoreServiceV2.js on lines 378..382

        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

            static translateBBox(bbox) {
                logger.debug('Converting bbox from [-180,180] to [0,360] for representation');
                return [bbox[0], bbox[1], 360 - Math.abs(bbox[2]), bbox[3]];
            }
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 1 hr to fix
        app/src/services/geoStoreServiceV2.js on lines 246..249

        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

            static async getNewHash(hash) {
                const idCon = await IdConnection.findOne({ oldId: hash }).exec();
                if (!idCon) {
                    return hash;
                }
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 1 hr to fix
        app/src/services/geoStoreServiceV2.js on lines 96..102

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

        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 calculateBBox(geoStore) {
                logger.debug('Calculating bbox');
                geoStore.bbox = GeoStoreService.swapBBox(geoStore);
                await geoStore.save();
                return geoStore;
        Severity: Major
        Found in app/src/services/geoStoreService.js and 1 other location - About 1 hr to fix
        app/src/services/geoStoreServiceV2.js on lines 280..285

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

        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

        There are no issues that match your filters.

        Category
        Status