CleverStack/clever-orm

View on GitHub
utils/model/orm/associations/loaders/eager.js

Summary

Maintainability
B
4 hrs
Test Coverage

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

module.exports.load = function eagerLoad(findOptions) {
  if (!!findOptions.include && findOptions.include instanceof Array) {
    for(var i = 0; i < findOptions.include.length; i++) {
      if (this.debug.enabled) {
        this.debug('eagerLoad(' + inspect(underscore.omit(findOptions.include[i], 'model', 'include')) + ', ' + inspect(findOptions.include[i].model.name) + ')');
Severity: Minor
Found in utils/model/orm/associations/loaders/eager.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 hydrateAfterEagerLoad has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports.afterLoad = function hydrateAfterEagerLoad(findOptions, model) {
  if (model !== null && findOptions.include && findOptions.include.length && model.entity.options.include) {
    var models = this.getDefinedModels();

    Object.keys(model.entity.options.includeMap).forEach(function(modelName) {
Severity: Minor
Found in utils/model/orm/associations/loaders/eager.js - About 1 hr to fix

    Avoid deeply nested control flow statements.
    Open

                if (!(model.entity[as][i] instanceof CsModel)) {
                  model.entity[as][i] = new CsModel(model.entity[as][i]);
                  hydrateAfterEagerLoad.apply(CsModel, [model.entity[as][i].entity.options, model.entity[as][i]]);
                }
    Severity: Major
    Found in utils/model/orm/associations/loaders/eager.js - About 45 mins to fix

      There are no issues that match your filters.

      Category
      Status