resource-watch/converter

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

Summary

Maintainability
F
5 days
Test Coverage
F
23%

Function obtainFSFromAST has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
Open

    static obtainFSFromAST(parsed) {
        logger.info('Generating FeatureService object from ast object');
        let fs = {};

        if (parsed.select && parsed.select.length > 0) {
Severity: Minor
Found in app/src/services/converterService.js - About 1 day 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

File converterService.js has 408 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const logger = require('logger');
const SQLService = require('services/sqlService');
const { geojsonToArcGIS } = require('arcgis-to-geojson-utils');
const { arcgisToGeoJSON } = require('arcgis-to-geojson-utils');
const Sql2json = require('sql2json').sql2json;
Severity: Minor
Found in app/src/services/converterService.js - About 5 hrs to fix

    Function obtainFSFromAST has 85 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static obtainFSFromAST(parsed) {
            logger.info('Generating FeatureService object from ast object');
            let fs = {};
    
            if (parsed.select && parsed.select.length > 0) {
    Severity: Major
    Found in app/src/services/converterService.js - About 3 hrs to fix

      Function obtainSelect has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          static obtainSelect(fs) {
              let result = '';
              if (!fs.outFields && !fs.outStatistics) {
                  return '*';
              }
      Severity: Minor
      Found in app/src/services/converterService.js - About 3 hrs 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 findIntersect has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          static findIntersect(node, found, result) {
              if (node && node.type === 'string' && node.value && found) {
                  try {
                      const geojson = JSON.parse(node.value);
                      if (!result) {
      Severity: Minor
      Found in app/src/services/converterService.js - About 2 hrs 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 obtainWhere has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          static async obtainWhere(params, apiKey) {
              const fs = params;
              let where = '';
              if (fs.where) {
                  if (!where) {
      Severity: Minor
      Found in app/src/services/converterService.js - About 2 hrs 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 findIntersect has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static findIntersect(node, found, result) {
              if (node && node.type === 'string' && node.value && found) {
                  try {
                      const geojson = JSON.parse(node.value);
                      if (!result) {
      Severity: Minor
      Found in app/src/services/converterService.js - About 1 hr to fix

        Function obtainWhere has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async obtainWhere(params, apiKey) {
                const fs = params;
                let where = '';
                if (fs.where) {
                    if (!where) {
        Severity: Minor
        Found in app/src/services/converterService.js - About 1 hr to fix

          Function obtainSelect has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static obtainSelect(fs) {
                  let result = '';
                  if (!fs.outFields && !fs.outStatistics) {
                      return '*';
                  }
          Severity: Minor
          Found in app/src/services/converterService.js - About 1 hr to fix

            Function sql2FS has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static async sql2FS(params, apiKey) {
                    const sql = params.sql.trim();
                    logger.info('Creating featureservice from sql', sql);
                    const parsed = new Sql2json(sql).toJSON();
                    if (!parsed) {
            Severity: Minor
            Found in app/src/services/converterService.js - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                  for (let j = 0, { length: argumentsLength } = node.arguments; j < argumentsLength; j++) {
                                      const argument = node.arguments[j];
                                      if (outFields !== '') {
                                          outFields += ',';
                                      }
              Severity: Major
              Found in app/src/services/converterService.js - About 45 mins to fix

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

                    static async sql2FS(params, apiKey) {
                        const sql = params.sql.trim();
                        logger.info('Creating featureservice from sql', sql);
                        const parsed = new Sql2json(sql).toJSON();
                        if (!parsed) {
                Severity: Minor
                Found in app/src/services/converterService.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 (node.alias) {
                                            obj.outStatisticFieldName = node.alias;
                                        }
                Severity: Major
                Found in app/src/services/converterService.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if (outFields !== '') {
                                          outFields += ',';
                                      }
                  Severity: Major
                  Found in app/src/services/converterService.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if (node.value.toLowerCase() === 'count' && node.arguments[0].value === '*') {
                                                throw new QueryNotValid(400, 'Invalid query. ArcGis does not support count(*) with more columns');
                                            }
                    Severity: Major
                    Found in app/src/services/converterService.js - About 45 mins to fix

                      Avoid too many return statements within this function.
                      Open

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

                        Avoid too many return statements within this function.
                        Open

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

                          Avoid too many return statements within this function.
                          Open

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

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

                                static async fs2SQL(params, apiKey) {
                                    const fs = params;
                                    logger.info('Creating query from featureService', params);
                                    const where = await ConverterService.obtainWhere(params, apiKey);
                                    const sql = `SELECT ${ConverterService.obtainSelect(fs)} FROM ${params.tableName}
                            Severity: Minor
                            Found in app/src/services/converterService.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

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

                                static parseGroupBy(group) {
                                    if (group) {
                                        const result = [];
                                        for (let i = 0, { length } = group; i < length; i++) {
                                            const node = group[i];
                            Severity: Minor
                            Found in app/src/services/converterService.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

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

                                static obtainAggrFun(exp) {
                                    if (exp) {
                                        for (let i = 0, { length } = aggrFunctions; i < length; i++) {
                                            if (exp.startsWith(aggrFunctions[i])) {
                                                return aggrFunctions[i];
                            Severity: Minor
                            Found in app/src/services/converterService.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

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

                                static removeIntersect(node) {
                                    if (node && node.type === 'function' && node.value.toLowerCase() === 'st_intersects') {
                                        return null;
                                    }
                                    if (node && node.type === 'conditional') {
                            Severity: Minor
                            Found in app/src/services/converterService.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

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

                                static checkGeojson(geojson) {
                                    if (geojson.type.toLowerCase() === 'polygon') {
                                        return {
                                            type: 'FeatureCollection',
                                            features: [{
                            Severity: Major
                            Found in app/src/services/converterService.js and 1 other location - About 3 hrs to fix
                            app/src/services/sqlService.js on lines 69..86

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

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

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

                                        const result = await RWAPIMicroservice.requestToMicroservice({
                                            uri: encodeURI(`/v1/geostore/${id}`),
                                            method: 'GET',
                                            json: true,
                                            headers: {
                            Severity: Major
                            Found in app/src/services/converterService.js and 1 other location - About 1 hr to fix
                            app/src/services/sqlService.js on lines 43..50

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

                            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