test-set/Moonridge-master/mr-rpc-methods.js
Function expose
has a Cognitive Complexity of 153 (exceeds 5 allowed). Consider refactoring. Open
Open
var expose = function(model, schema, opts) {
var liveQueries = {};
var modelName = model.modelName;
- 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 expose
has 505 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
var expose = function(model, schema, opts) {
var liveQueries = {};
var modelName = model.modelName;
File mr-rpc-methods.js
has 519 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
var _ = require('lodash');
var Promise = require('bluebird');
var eventNames = require('./schema-events').eventNames;
var queryBuilder = require('./query-builder');
var populateWithClientQuery = require('./utils/populate-doc-util');
Function syncLogic
has 101 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
var syncLogic = function() {
var cQindex = LQ.getIndexById(doc._id); //index of current doc in the query
if (evName === 'remove' && LQ.docs[cQindex]) {
Function liveQuery
has 74 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
liveQuery: function(clientQuery, LQIndex) {
if (!opts.checkPermission(this, 'R')) {
return new Error('You lack a privilege to read this collection');
}
def = Promise.defer();
Function update
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
update: function(toUpdate) {
var def = Promise.defer();
var socket = this;
var id = toUpdate._id;
Function _distributeChange
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
_distributeChange: function(doc, evName, isInResult) {
var self = this;
var actuallySend = function() {
for (var socketId in self.listeners) {
var listener = self.listeners[socketId];
Function accessControlQueryModifier
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function accessControlQueryModifier(clQuery, schema, userPL, op) { // guards the properties that are marked with higher required permissions for reading
var pathPs = schema.pathPermissions;
var select;
if (clQuery.select) {
select = clQuery.select[0];
Function exposeCallback
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
return function exposeCallback(rpcInstance) {
var chnlName = 'MR-' + modelName; //prefix MR stands for Moonridge
rpcInstance.expose(chnlName, channel, opts.authFn);
var chnlSocket = rpcInstance.channels[chnlName]._socket;
Avoid deeply nested control flow statements. Open
Open
if (cQindex === -1) {
LQ.docs.splice(index, 0, doc); //insert the document
} else {
if (cQindex !== index) {
if (cQindex < index) { // if we remove item before, the whole array shifts, so we have to compensate index by 1.
Avoid deeply nested control flow statements. Open
Open
if (cQindex === -1) {
index = getIndexInSorted(doc, LQ.docs, sortBy);
LQ.docs.splice(index, 0, doc);
if (LQ.indexedByMethods.limit) {
if (LQ.docs.length > LQ.indexedByMethods.limit[0]) {
Avoid deeply nested control flow statements. Open
Open
if (cQindex === -1) {
LQ.docs.push(doc);
LQ._distributeChange(doc, evName, null);
}
Avoid deeply nested control flow statements. Open
Open
if (cQindex === -1) {
LQ.docs.push(doc);
LQ._distributeChange(doc, evName, true); //doc wasn't in the result, but after update is
} else {