Function confirmRecordExists
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
static confirmRecordExists(model, config) {
config = config || {};
const dbKey = config.databaseKey || config.requestKey;
const requestKey = config.requestKey;
Function validateCreationPermission
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
static validateCreationPermission(getUserForModelFn) {
return {
method(request, reply) {
const result = Promise.fromCallback(next => {
return request.server.methods.user(request.auth.credentials.username, next);
Function confirmRecordExists
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
static confirmRecordExists(model, config) {
config = config || {};
const dbKey = config.databaseKey || config.requestKey;
const requestKey = config.requestKey;
- 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 validateOwnership
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
static validateOwnership(recordsAreNotModels, fetchUser, userIsNotModel) {
if (recordsAreNotModels && typeof fetchUser !== `function`) {
throw new Error(`fetchUser needs to be a function provided if recordsAreNotModels is set to true`);
}
Function method
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
method(request, reply) {
const result = Promise.fromCallback(next => {
return request.server.methods.user(request.auth.credentials.username, next);
})
.then(function(user) {
Function validateOwnership
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
static validateOwnership(recordsAreNotModels, fetchUser, userIsNotModel) {
if (recordsAreNotModels && typeof fetchUser !== `function`) {
throw new Error(`fetchUser needs to be a function provided if recordsAreNotModels is set to 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 method
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
method(request, reply) {
const records = request.pre.records;
const resource = recordsAreNotModels ? records[0] : records.models[0];
const authenticatedUser = request.pre.user;
Function validateCreationPermission
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
static validateCreationPermission(getUserForModelFn) {
return {
method(request, reply) {
const result = Promise.fromCallback(next => {
return request.server.methods.user(request.auth.credentials.username, next);
- 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"