File jsonapidatastore.js
has 953 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*********************************************************************************
* Copyright 2015 Yahoo Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
********************************************************************************/
Function find
has 111 lines of code (exceeds 25 allowed). Consider refactoring. Open
find(query) {
let willReject = false;
let withReason;
let params = query._params;
let options = query._opts;
JsonApiDatastore
has 34 functions (exceeds 20 allowed). Consider refactoring. Open
class JsonApiDatastore extends Datastore {
constructor(Promise, ttl, baseURL, models) {
super(Promise, ttl, baseURL, models);
this._urlTemplateCache = {};
Function find
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
find(query) {
let willReject = false;
let withReason;
let params = query._params;
let options = query._opts;
- 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 _transformRequest
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
_transformRequest(model, toSend, fillBlanks) {
let payload = {
data: {
type: model,
id: toSend.id,
Function _fromApiObject
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
_fromApiObject(apiObject) {
let template = this._models[apiObject.type];
let projection = {
id: apiObject.id
};
Function _rootDiffs
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
_rootDiffs(diffTree) {
let rootedDiffs = [];
let rootDiffs = function rootDiffs(parentPath, objectId, object) {
let diffs = [];
Function _rollUpDiffs
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
_rollUpDiffs(objectDiffs, model, fromObjects) {
let template = this._models[model];
if (!template.links) { return; }
Object.keys(fromObjects).forEach((id) => {
Function commit
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
commit(patches) {
let unrootedDiffs = this._parseObjects(patches);
let diffTree = {};
for (let i = 0; i < this._modelHierarchy.length; i++) {
Function _getUrlForModel
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
_getUrlForModel(model, getCollection, withData) {
let willReject = false;
let withReason;
let modelUrl = this._urlTemplateCache[model];
Function _buildModelHierarchy
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
_buildModelHierarchy() {
let models = [];
let inList = {};
let hierarchy = [];
Function _rootNewModel
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
_rootNewModel(model, id, state) {
let rootPath;
let requiredModels = this._urlTemplateCache[model].split('|');
rootPath = requiredModels.shift();
Function _parseObjects
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
_parseObjects(patches) {
let objects = {};
patches.forEach((patch) => {
let [ , model, id, ...path] = patch.path.split('/');
Function _findLinkingObject
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
_findLinkingObject(fromModel, toModel, toId) {
let fromId;
let alias = this._aliasIds[toId];
/*
Function _rootDiffs
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
_rootDiffs(diffTree) {
let rootedDiffs = [];
let rootDiffs = function rootDiffs(parentPath, objectId, object) {
let diffs = [];
- 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 _getUrlForModel
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
_getUrlForModel(model, getCollection, withData) {
let willReject = false;
let withReason;
let modelUrl = this._urlTemplateCache[model];
- 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 _fromApiObject
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
_fromApiObject(apiObject) {
let template = this._models[apiObject.type];
let projection = {
id: apiObject.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 _buildModelHierarchy
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
_buildModelHierarchy() {
let models = [];
let inList = {};
let hierarchy = [];
- 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
return this._request('PATCH', url, queryParams, data, JSONAPI_MIME_TYPE)
.then(this._transformResult.bind(this), (error) => {
printDebug(error);
let message = ERROR_CANNOT_UPDATE_OBJECT
.replace('${model}', model)
- 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 95.
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
return this._request('POST', url, queryParams, data, JSONAPI_MIME_TYPE)
.then(this._transformResult.bind(this), (error) => {
printDebug(error);
let message = ERROR_CANNOT_CREATE_OBJECT
.replace('${model}', model)
- 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 95.
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
Object.keys(template.links).forEach((linkName) => {
let link = template.links[linkName];
if (!inList[link.model]) {
newModels.push(link.model);
inList[link.model] = true;
- 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 91.
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
Object.keys(template.links).forEach((linkName) => {
let link = template.links[linkName];
if (!inList[link.model]) {
models.push(link.model);
inList[link.model] = true;
- 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 91.
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 (!this._relationCache[fromModel].hasOwnProperty(toModel)) {
this._relationCache[fromModel][toModel] = {};
}
- 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 45.
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 (!this._relationCache[toModel].hasOwnProperty(fromModel)) {
this._relationCache[toModel][fromModel] = {};
}
- 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 45.
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