File model.js
has 724 lines of code (exceeds 250 allowed). Consider refactoring. Open
'use strict';
const Promise = require('bluebird'),
EventEmitter = require('events'),
Document = require('./document'),
Errors = require('./errors'),
Model
has 36 functions (exceeds 20 allowed). Consider refactoring. Open
class Model extends EventEmitter {
/*
* Constructor for a Model. Note that this is not what `thinkagain.createModel`
* returns. It is the prototype of what `thinkagain.createModel` returns.
Function hasAndBelongsToMany
has 100 lines of code (exceeds 25 allowed). Consider refactoring. Open
hasAndBelongsToMany(joinedModel, fieldDoc, leftKey, rightKey, options) {
let link;
let thinkagain = this._getModel()._thinkagain;
options = options || {};
Function new
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
static new(name, schema, options, thinkagain) {
let validate = thinkagain.ajv.compile(schema);
let proto = new Model(name, validate, options, thinkagain);
proto._initModel = options.init !== undefined ? !!options.init : true;
Function save
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
save(docs, options) {
let r = this._getModel()._thinkagain.r;
let isArray = Array.isArray(docs);
if (!isArray) {
Function save
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
save(docs, options) {
let r = this._getModel()._thinkagain.r;
let isArray = Array.isArray(docs);
if (!isArray) {
- 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 new
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
static new(name, schema, options, thinkagain) {
let validate = thinkagain.ajv.compile(schema);
let proto = new Model(name, validate, options, thinkagain);
proto._initModel = options.init !== undefined ? !!options.init : true;
- 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 model
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
let model = function model(doc, _options) {
if (!util.isPlainObject(doc)) {
throw new Errors.ThinkAgainError('Cannot build a new instance of `' + proto._name + '` without an object');
}
Function hasAndBelongsToMany
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
hasAndBelongsToMany(joinedModel, fieldDoc, leftKey, rightKey, options) {
let link;
let thinkagain = this._getModel()._thinkagain;
options = options || {};
- 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 constructor
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
constructor(name, validate, options, thinkagain) {
super();
/**
* Name of the table used
Function belongsTo
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
belongsTo(joinedModel, fieldDoc, leftKey, rightKey, options) {
if ((joinedModel instanceof Model) === false) {
throw new Errors.ThinkAgainError('First argument of `belongsTo` must be a Model');
}
Function executeInsert
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
let executeInsert = (resolve, reject) => {
toSave--;
resolves.push(resolve);
rejects.push(reject);
Function hasOne
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
hasOne(joinedModel, fieldDoc, leftKey, rightKey, options) {
if ((joinedModel instanceof Model) === false) {
throw new Errors.ThinkAgainError('First argument of `hasOne` must be a Model');
}
Function hasMany
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
hasMany(joinedModel, fieldDoc, leftKey, rightKey, options) {
if ((joinedModel instanceof Model) === false) {
throw new Errors.ThinkAgainError('First argument of `hasMany` must be a Model');
}
Function _promisesReady
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
_promisesReady() {
let self = this;
if (this._promisesReadyPromise) return this._promisesReadyPromise;
let verifyAll = function() {
return Promise.all(self._pendingPromises)
- 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 (doc[key][i] instanceof Document === false) {
doc[key][i] = new joins[key].model(doc[key][i], _options); // eslint-disable-line
}
Function docRemoveListener
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
docRemoveListener(ev, listener) {
if (Array.isArray(this._getModel()._listeners[ev])) {
for (let i = 0, ii = this._getModel()._listeners[ev].length; i < ii; ++i) {
if (this._getModel()._listeners[ev][i] === listener) {
this._getModel()._listeners[ev].splice(i, 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
TODO found Open
// TODO: This regex seems a bit too generous since messages such
- Exclude checks
TODO found Open
//TODO Expand error with more information
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
post(ev, fn) {
if (typeof fn !== 'function') {
throw new Errors.ThinkAgainError('Second argument to `pre` must be a function');
}
if (fn.length > 1) {
- 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 181.
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
pre(ev, fn) {
if (typeof fn !== 'function') {
throw new Errors.ThinkAgainError('Second argument to `pre` must be a function');
}
if (fn.length > 1) {
- 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 181.
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
docAddListener(eventKey, listener) {
let listeners = this._getModel()._listeners;
if (listeners[eventKey] == null) { // eslint-disable-line
listeners[eventKey] = [];
}
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
docOnce(eventKey, listener) {
let listeners = this._getModel()._listeners;
if (listeners[eventKey] == null) { // eslint-disable-line
listeners[eventKey] = [];
}
- 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
for (let i = 0, ii = doc[key].length; i < ii; ++i) {
if (doc[key][i] instanceof Document === false) {
doc[key][i] = new joins[key].model(doc[key][i], _options); // eslint-disable-line
}
}
- 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 65.
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
for (let i = 0, ii = doc[key].length; i < ii; ++i) {
if (doc[key][i] instanceof Document === false) {
doc[key][i] = new joins[key].model(doc[key][i], _options); // eslint-disable-line
}
}
- 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 65.
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
case 'get':
// Make a copy of `get` into `_get`
Model.prototype._get = function() {
let query = new Query(this);
query = query._get.apply(query, arguments);
- 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 57.
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
default: // eslint-disable-line
Model.prototype[key] = function() {
let query = new Query(this);
query = query[key].apply(query, arguments);
return query;
- 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 57.
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