test-set/Moonridge-master/query-builder.js
Function MRQuery
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
Open
module.exports = function MRQuery(model, clientQuery) {
var query = model.find();
//query option object,where we index by method, not by invocation order, useful later when we reexecute the query
var opts = {populate:[]};
- 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 MRQuery
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
module.exports = function MRQuery(model, clientQuery) {
var query = model.find();
//query option object,where we index by method, not by invocation order, useful later when we reexecute the query
var opts = {populate:[]};
Avoid deeply nested control flow statements. Open
Open
}else if(methodName === 'populate'){
opts.populate.push(args);
}
Avoid deeply nested control flow statements. Open
Open
if (methodName === 'sort' && opts.count) {
throw new Error('Mongoose does not support sort and count in one query'); //TODO remove when we update to mongoose 3.9.2
}
Avoid deeply nested control flow statements. Open
Open
if (opts[methodName]) {
throw new Error(methodName + ' method can be called just once per query');
} else {
opts[methodName] = args; //we shall add it to the options, this object will be used when reiterating on LQ
}