Showing 63 of 66 total issues
Function init
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
exports.init = (opts) => {
exports.opts = opts;
if (!opts.objectMapping) {
Interface.logger.error('The objectMapping option appears to be missing. Please make sure it is set correctly.');
- 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 FiltersParser
has 183 lines of code (exceeds 25 allowed). Consider refactoring. Open
function FiltersParser(model, timezone, options) {
const modelSchema = Interface.Schemas.schemas[utils.getModelName(model)];
const parseInteger = (value) => Number.parseInt(value, 10);
const parseDate = (value) => new Date(value);
Function FiltersParser
has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring. Open
function FiltersParser(model, timezone, options) {
const modelSchema = Interface.Schemas.schemas[utils.getModelName(model)];
const parseInteger = (value) => Number.parseInt(value, 10);
const parseDate = (value) => new Date(value);
- 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 init
has 116 lines of code (exceeds 25 allowed). Consider refactoring. Open
exports.init = (opts) => {
exports.opts = opts;
if (!opts.objectMapping) {
Interface.logger.error('The objectMapping option appears to be missing. Please make sure it is set correctly.');
Similar blocks of code found in 2 locations. Consider refactoring. Open
getCustomer(customerModel, customerField, customerId) {
return new P((resolve, reject) => {
if (customerId) {
return customerModel
.findById(customerId)
- 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 117.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
getUser(customerModel, customerField, customerId) {
return new P((resolve, reject) => {
if (customerId) {
return customerModel
.findById(customerId)
- 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 117.
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
Function _getTypeFromMongoose
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
_getTypeFromMongoose(fieldInfo) {
if (_.isPlainObject(fieldInfo) && !fieldInfo.path) {
// Deal with Object
return this._objectType(
fieldInfo,
- 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 perform
has 92 lines of code (exceeds 25 allowed). Consider refactoring. Open
async perform() {
const params = await getScopedParams(this._params, this._model, this._user);
const timezone = -parseInt(moment().tz(params.timezone).format('Z'), 10);
const timezoneOffset = timezone * 60 * 60 * 1000;
const queryBuilder = new QueryBuilder(this._model, params, this._opts);
Function SearchBuilder
has 85 lines of code (exceeds 25 allowed). Consider refactoring. Open
function SearchBuilder(model, opts, params, searchFields) {
const schema = Interface.Schemas.schemas[utils.getModelName(model)];
const fieldsSearched = [];
this.hasSmartFieldSearch = false;
Identical blocks of code found in 2 locations. Consider refactoring. Open
_handlePopulate(query) {
const schema = Interface.Schemas.schemas[utils.getModelName(this._model)];
_.each(schema.fields, (field) => {
if (field.reference) {
- 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
_handlePopulate(query) {
const schema = Interface.Schemas.schemas[utils.getModelName(this._model)];
_.each(schema.fields, (field) => {
if (field.reference) {
query.populate({ path: field.field, strictPopulate: false });
- 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
Function getConditions
has 76 lines of code (exceeds 25 allowed). Consider refactoring. Open
this.getConditions = async () => {
this.hasSmartFieldSearch = false;
const orQuery = { $or: [] };
function pushCondition(condition, fieldName) {
exports
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
module.exports = class Flattener {
constructor(schema, flatten, model, lianaOptions) {
this.schema = schema;
this.flatten = flatten;
this.model = model;
File flattener.js
has 280 lines of code (exceeds 250 allowed). Consider refactoring. Open
import _ from 'lodash';
import Interface from 'forest-express';
import FieldIntrospector from '../utils/field-analyser';
import { getMongooseSchemaFromFieldPath } from '../utils/schema';
Function _getTypeFromNative
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
_getTypeFromNative(type) {
if (type instanceof Array) {
if (_.isEmpty(type)) {
return [null];
}
- 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
return moment()
.year(record._id.year)
.month(record._id.month - 1)
.startOf('month')
.add(record._id.day - 1, 'days')
- 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 77.
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
return moment()
.year(record._id.year)
.month(record._id.month - 1)
.startOf('month')
.add(record._id.day - 1, 'days')
- 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 77.
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
Function formatConditionForReferences
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
this.formatConditionForReferences = async (condition) => {
if (_.isEmpty(condition)) {
throw new InvalidFiltersFormatError('Empty condition in filter');
}
if (!_.isObject(condition)) {
Function _getTypeFromMongoose
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
_getTypeFromMongoose(fieldInfo) {
if (_.isPlainObject(fieldInfo) && !fieldInfo.path) {
// Deal with Object
return this._objectType(
fieldInfo,
Function _detectReference
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
_detectReference(fieldInfo) {
if (fieldInfo.options) {
if (fieldInfo.options.ref && fieldInfo.options.type) {
const ref = this._formatRef(fieldInfo.options.ref);
return ref ? `${ref}._id` : null;
- 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"