gerard2p/koaton

View on GitHub
src/support/RestModel.js

Summary

Maintainability
F
3 days
Test Coverage

Function REST_POST_SINGLE has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
Open

export async function REST_POST_SINGLE (Model, model, entity = null) {
    if (!entity) {
        entity = await Model.create(model);
    }
    let modelRelations = {};
Severity: Minor
Found in src/support/RestModel.js - About 7 hrs to fix

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 RestModel has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

export function RestModel (options, route, modelname) {
    let routers = {
        public: new Router(),
        private: new Router()
    };
Severity: Minor
Found in src/support/RestModel.js - About 6 hrs to fix

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 RestModel has 114 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function RestModel (options, route, modelname) {
    let routers = {
        public: new Router(),
        private: new Router()
    };
Severity: Major
Found in src/support/RestModel.js - About 4 hrs to fix

Function REST_POST_SINGLE has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export async function REST_POST_SINGLE (Model, model, entity = null) {
    if (!entity) {
        entity = await Model.create(model);
    }
    let modelRelations = {};
Severity: Major
Found in src/support/RestModel.js - About 2 hrs to fix

Function restify has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

export async function restify (modelinstance, /* istanbul ignore next */ relations = {}, /* istanbul ignore next */MODEL = {}) {
    /* istanbul ignore next */
    let model = modelinstance.toJSON ? modelinstance.toJSON() : modelinstance;
    for (const key of Object.keys(relations)) {
        const keyTo = relations[key].keyTo === 'id' ? '_id' : relations[key].keyTo;
Severity: Minor
Found in src/support/RestModel.js - About 2 hrs to fix

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 restify has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export async function restify (modelinstance, /* istanbul ignore next */ relations = {}, /* istanbul ignore next */MODEL = {}) {
    /* istanbul ignore next */
    let model = modelinstance.toJSON ? modelinstance.toJSON() : modelinstance;
    for (const key of Object.keys(relations)) {
        const keyTo = relations[key].keyTo === 'id' ? '_id' : relations[key].keyTo;
Severity: Major
Found in src/support/RestModel.js - About 2 hrs to fix

Function REST_GET has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    pOrp(routers, options.get).get('/', async function REST_GET (ctx, next) {
        let res = {},
            filteroptions = { skip: 0 };
        filteroptions.limit = isNaN(ctx.query.size) ? isNaN(configuration.server.pagination.limit) ? /* istanbul ignore next */50 : configuration.server.pagination.limit : parseInt(ctx.query.size, 10);
        if (ctx.query.size) {
Severity: Minor
Found in src/support/RestModel.js - About 1 hr to fix

Avoid deeply nested control flow statements.
Open

                    if (res.id) {
                        modelRelations[related].push(id);
                    }
Severity: Major
Found in src/support/RestModel.js - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                        if (typeof related === 'object') {
                            related[foreignKey] = foreignValue;
                            modelRelations[relation].push((await child.create(related)).id);
                        } else {
                            let data = {};
Severity: Major
Found in src/support/RestModel.js - About 45 mins to fix

There are no issues that match your filters.

Category
Status