Function pruneDocument
has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring. Open
module.exports.pruneDocument = function (indoc) {
return prune(indoc);
function prune(doc) {
if (doc instanceof Array) {
- 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 utils.js
has 350 lines of code (exceeds 250 allowed). Consider refactoring. Open
var async = require('async');
var statusCode = require('http-status-codes');
var _ = require('lodash');
var Q = require('q');
Function getElementSchema
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
module.exports.getElementSchema = function (paths, element) {
var sc = paths[element];
if (sc) {
return sc;
} else {
- 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 mongoConfigurationCheck
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
function mongoConfigurationCheck(config, gConfig, method) {
if (config.profiles == undefined) {
config.profiles = {};
}
- 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 pruneDocument
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports.pruneDocument = function (indoc) {
return prune(indoc);
function prune(doc) {
if (doc instanceof Array) {
Function prune
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
function prune(doc) {
if (doc instanceof Array) {
var objDoc = {};
//CAREFUL!!! --> Strictly necessary iterate over the plain object
Function it
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports.iterate = function it(fullPath, doc, iterator, callback, parents) {
var paths = fullPath.split('.');
parents = parents || [];
Function configureForm
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
module.exports.configureForm = function (Model) {
var inj = Model.injector();
if (inj.form && inj.form.tabs) {
for (var t in inj.form.tabs) {
var tab = inj.form.tabs[t];
- 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
Consider simplifying this complex logical expression. Open
if ((routesRestrictions.blacklist && routesRestrictions.blacklist.routes) || (routesRestrictions.whitelist && routesRestrictions.whitelist.routes)) {
allowed = (routesRestrictions.whitelist && routesRestrictions.whitelist.routes && routesRestrictions.whitelist.routes.indexOf(method) > -1) ||
(routesRestrictions.blacklist && routesRestrictions.blacklist.routes && routesRestrictions.blacklist.routes.indexOf(method) == -1);
}
Function checkSetup
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports.checkSetup = function (Model) {
var mConf = Model.injector();
//Limit shards based on the environment!
if (mConf.shard && mConf.shard.shardValues) {
Function configureForm
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports.configureForm = function (Model) {
var inj = Model.injector();
if (inj.form && inj.form.tabs) {
for (var t in inj.form.tabs) {
var tab = inj.form.tabs[t];
Function getConfigByProfile
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports.getConfigByProfile = function (gConfig, req) {
var profile = req.query.profile || req.headers.profile;
var config = {};
if (profile == undefined) {
Function checkSetup
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
module.exports.checkSetup = function (Model) {
var mConf = Model.injector();
//Limit shards based on the environment!
if (mConf.shard && mConf.shard.shardValues) {
- 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 getConfigByProfile
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
module.exports.getConfigByProfile = function (gConfig, req) {
var profile = req.query.profile || req.headers.profile;
var config = {};
if (profile == undefined) {
- 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 routeConfigurationCheck
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function routeConfigurationCheck(config, method) {
var routesRestrictions = injector.config.env.restrictions || {};
var allowed = true;
if ((routesRestrictions.blacklist && routesRestrictions.blacklist.routes) || (routesRestrictions.whitelist && routesRestrictions.whitelist.routes)) {
- 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
for (var i in doc) {
if (doc.hasOwnProperty(i)) {
//Prune all the elements in the object
doc[i] = prune(doc[i]);
}
Avoid deeply nested control flow statements. Open
if (parent) {
var child = element.substring(parentPath.length + 1);
return module.exports.getElementSchema(parent.schema.paths, child);
}
Avoid deeply nested control flow statements. Open
if (Object.keys(objDoc).length > 0) {
for (var i in objDoc) {
if (objDoc.hasOwnProperty(i)) {
//Prune all the elements in the object
//Although we are working with the plain object, we COPY and PRUNE the original object
Avoid deeply nested control flow statements. Open
if (objDoc == null || objDoc == undefined) {
//Null objects marked as undefined
doc = undefined;
}
Avoid deeply nested control flow statements. Open
if (parentPath) {
parentPath += "." + chunk
} else {
parentPath = chunk;
}
Function runPostCallbacks
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
module.exports.runPostCallbacks = function (config, req, res, value, cbk) {
Function runPreCallbacks
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
module.exports.runPreCallbacks = function (preFnArray, Model, req, res, cbk) {
Function iterate
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
module.exports.iterate = function it(fullPath, doc, iterator, callback, parents) {
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (restrictions && restrictions.whitelist && restrictions.whitelist.shards) {
mConf.shard.shardValues = _.intersection(restrictions.whitelist.shards, mConf.shard.shardValues);
}
- 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 67.
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
if (restrictions && restrictions.blacklist && restrictions.blacklist.shards) {
mConf.shard.shardValues = _.xor(restrictions.blacklist.shards, mConf.shard.shardValues);
}
- 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 67.
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
if (profile == undefined) {
config = gConfig.profiles._default;
if (config == undefined) {
config = {
mongo: {
- 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 59.
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
if (config == undefined) {
config = gConfig.profiles._default;
if (config == undefined) {
config = {
mongo: {
- 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 59.
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