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) {
- Read upRead up
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;
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) {
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 '*';
}
- Read upRead up
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) {
- Read upRead up
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) {
- Read upRead up
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) {
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) {
Function obtainSelect
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
static obtainSelect(fs) {
let result = '';
if (!fs.outFields && !fs.outStatistics) {
return '*';
}
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) {
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 += ',';
}
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) {
- Read upRead up
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;
}
Avoid deeply nested control flow statements. Open
if (outFields !== '') {
outFields += ',';
}
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');
}
Avoid too many return
statements within this function. Open
return right;
Avoid too many return
statements within this function. Open
return left;
Avoid too many return
statements within this function. Open
return null;
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}
- Read upRead up
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];
- Read upRead up
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];
- Read upRead up
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') {
- Read upRead up
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: [{
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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: {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76