File local_collection.js
has 1383 lines of code (exceeds 250 allowed). Consider refactoring. Open
import Cursor from './cursor.js';
import ObserveHandle from './observe_handle.js';
import {
hasOwn,
isIndexable,
Function _observeFromObserveChanges
has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring. Open
LocalCollection._observeFromObserveChanges = (cursor, observeCallbacks) => {
const transform = cursor.getTransform() || (doc => doc);
let suppressed = !!observeCallbacks._suppress_initial;
let observeChangesCallbacks;
- 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 findModTarget
has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring. Open
function findModTarget(doc, keyparts, options = {}) {
let usedArrayIndex = false;
for (let i = 0; i < keyparts.length; i++) {
const last = i === keyparts.length - 1;
- 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 _observeFromObserveChanges
has 110 lines of code (exceeds 25 allowed). Consider refactoring. Open
LocalCollection._observeFromObserveChanges = (cursor, observeCallbacks) => {
const transform = cursor.getTransform() || (doc => doc);
let suppressed = !!observeCallbacks._suppress_initial;
let observeChangesCallbacks;
Function constructor
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
constructor(options = {}) {
const orderedFromCallbacks = (
options.callbacks &&
LocalCollection._observeChangesCallbacksAreOrdered(options.callbacks)
);
- 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 update
has 85 lines of code (exceeds 25 allowed). Consider refactoring. Open
update(selector, mod, options, callback) {
if (! callback && options instanceof Function) {
callback = options;
options = null;
}
Function $push
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
$push(target, field, arg) {
if (target[field] === undefined) {
target[field] = [];
}
- 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 findModTarget
has 75 lines of code (exceeds 25 allowed). Consider refactoring. Open
function findModTarget(doc, keyparts, options = {}) {
let usedArrayIndex = false;
for (let i = 0; i < keyparts.length; i++) {
const last = i === keyparts.length - 1;
Function $push
has 75 lines of code (exceeds 25 allowed). Consider refactoring. Open
$push(target, field, arg) {
if (target[field] === undefined) {
target[field] = [];
}
Function remove
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
remove(selector, callback) {
// Easy special case: if we're not calling observeChanges callbacks and
// we're not saving originals and we got asked to remove everything, then
// just empty everything directly.
if (this.paused && !this._savedOriginals && EJSON.equals(selector, {})) {
Function constructor
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
constructor(options = {}) {
const orderedFromCallbacks = (
options.callbacks &&
LocalCollection._observeChangesCallbacksAreOrdered(options.callbacks)
);
Function _modify
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
LocalCollection._modify = (doc, modifier, options = {}) => {
if (!LocalCollection._isPlainObject(modifier)) {
throw MinimongoError('Modifier must be an object');
}
Function insert
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
insert(doc, callback) {
doc = EJSON.clone(doc);
assertHasValidFieldNames(doc);
Function _idsMatchedBySelector
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
LocalCollection._idsMatchedBySelector = selector => {
// Is the selector just an ID?
if (LocalCollection._selectorIsId(selector)) {
return [selector];
}
- 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 _modifyAndNotify
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
_modifyAndNotify(doc, mod, recomputeQids, arrayIndices) {
const matched_before = {};
Object.keys(this.queries).forEach(qid => {
const query = this.queries[qid];
Function _updateInResults
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
LocalCollection._updateInResults = (query, doc, old_doc) => {
if (!EJSON.equals(doc._id, old_doc._id)) {
throw new Error('Can\'t change a doc\'s _id while updating');
}
Function wrapTransform
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
LocalCollection.wrapTransform = transform => {
if (!transform) {
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
Function _compileProjection
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
LocalCollection._compileProjection = fields => {
LocalCollection._checkSupportedProjection(fields);
const _idProjection = fields._id === undefined ? true : fields._id;
const details = projectionDetails(fields);
Function _updateInResults
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
LocalCollection._updateInResults = (query, doc, old_doc) => {
if (!EJSON.equals(doc._id, old_doc._id)) {
throw new Error('Can\'t change a doc\'s _id while updating');
}
- 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 update
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
update(selector, mod, options, callback) {
if (! callback && options instanceof Function) {
callback = options;
options = 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
Function _idsMatchedBySelector
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
LocalCollection._idsMatchedBySelector = selector => {
// Is the selector just an ID?
if (LocalCollection._selectorIsId(selector)) {
return [selector];
}
Function $rename
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
$rename(target, field, arg, keypath, doc) {
// no idea why mongo has this restriction..
if (keypath === arg) {
throw MinimongoError('$rename source must differ from target', {field});
}
Function wrapTransform
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
LocalCollection.wrapTransform = transform => {
if (!transform) {
return null;
}
Function _insertInResults
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
LocalCollection._insertInResults = (query, doc) => {
const fields = EJSON.clone(doc);
delete fields._id;
- 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 _checkSupportedProjection
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
LocalCollection._checkSupportedProjection = fields => {
if (fields !== Object(fields) || Array.isArray(fields)) {
throw MinimongoError('fields option must be an object');
}
- 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 (options.noCreate) {
return undefined;
}
Function _modify
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
LocalCollection._modify = (doc, modifier, options = {}) => {
if (!LocalCollection._isPlainObject(modifier)) {
throw MinimongoError('Modifier must be an object');
}
- 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 $rename
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$rename(target, field, arg, keypath, doc) {
Function $unset
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
$unset(target, field, arg) {
if (target !== undefined) {
if (target instanceof Array) {
if (field in target) {
target[field] = 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
Function _compileProjection
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
LocalCollection._compileProjection = fields => {
LocalCollection._checkSupportedProjection(fields);
const _idProjection = fields._id === undefined ? true : fields._id;
const details = projectionDetails(fields);
- 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 $min
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
$min(target, field, arg) {
if (typeof arg !== 'number') {
throw MinimongoError('Modifier $min allowed for numbers only', {field});
}
- 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 $addToSet
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
$addToSet(target, field, arg) {
let isEach = false;
if (typeof arg === 'object') {
// check if first key is '$each'
- 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 $max
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
$max(target, field, arg) {
if (typeof arg !== 'number') {
throw MinimongoError('Modifier $max allowed for numbers only', {field});
}
- 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 too many return
statements within this function. Open
return undefined;
Avoid too many return
statements within this function. Open
return subIds;
Avoid too many return
statements within this function. Open
return doc;
Avoid too many return
statements within this function. Open
return null;
Avoid too many return
statements within this function. Open
return null;
Function $rename
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
$rename(target, field, arg, keypath, doc) {
// no idea why mongo has this restriction..
if (keypath === arg) {
throw MinimongoError('$rename source must differ from target', {field});
}
- 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 remove
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
remove(selector, callback) {
// Easy special case: if we're not calling observeChanges callbacks and
// we're not saving originals and we got asked to remove everything, then
// just empty everything directly.
if (this.paused && !this._savedOriginals && EJSON.equals(selector, {})) {
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
$min(target, field, arg) {
if (typeof arg !== 'number') {
throw MinimongoError('Modifier $min allowed for numbers only', {field});
}
- 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 121.
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
$max(target, field, arg) {
if (typeof arg !== 'number') {
throw MinimongoError('Modifier $max allowed for numbers only', {field});
}
- 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 121.
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 (field in target) {
if (typeof target[field] !== 'number') {
throw MinimongoError(
'Cannot apply $inc modifier to non-number',
{field}
- 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 46.
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 (field in target) {
if (typeof target[field] !== 'number') {
throw MinimongoError(
'Cannot apply $mul modifier to non-number',
{field}
- 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 46.
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