RouteInjector/route-injector

View on GitHub
lib/engine/routeinjector/utils.js

Summary

Maintainability
F
6 days
Test Coverage

Function pruneDocument has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
Open

module.exports.pruneDocument = function (indoc) {
    return prune(indoc);

    function prune(doc) {
        if (doc instanceof Array) {
Severity: Minor
Found in lib/engine/routeinjector/utils.js - About 1 day 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

File utils.js has 350 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var async = require('async');
var statusCode = require('http-status-codes');
var _ = require('lodash');
var Q = require('q');
Severity: Minor
Found in lib/engine/routeinjector/utils.js - About 4 hrs to fix

    Function getElementSchema has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports.getElementSchema = function (paths, element) {
        var sc = paths[element];
        if (sc) {
            return sc;
        } else {
    Severity: Minor
    Found in lib/engine/routeinjector/utils.js - About 3 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 mongoConfigurationCheck has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    function mongoConfigurationCheck(config, gConfig, method) {
        if (config.profiles == undefined) {
            config.profiles = {};
        }
    
    Severity: Minor
    Found in lib/engine/routeinjector/utils.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 pruneDocument has 64 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports.pruneDocument = function (indoc) {
        return prune(indoc);
    
        function prune(doc) {
            if (doc instanceof Array) {
    Severity: Major
    Found in lib/engine/routeinjector/utils.js - About 2 hrs to fix

      Function prune has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function prune(doc) {
              if (doc instanceof Array) {
                  var objDoc = {};
      
                  //CAREFUL!!! --> Strictly necessary iterate over the plain object
      Severity: Major
      Found in lib/engine/routeinjector/utils.js - About 2 hrs to fix

        Function it has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        module.exports.iterate = function it(fullPath, doc, iterator, callback, parents) {
        
            var paths = fullPath.split('.');
            parents = parents || [];
        
        Severity: Major
        Found in lib/engine/routeinjector/utils.js - About 2 hrs to fix

          Function configureForm has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

          module.exports.configureForm = function (Model) {
              var inj = Model.injector();
              if (inj.form && inj.form.tabs) {
                  for (var t in inj.form.tabs) {
                      var tab = inj.form.tabs[t];
          Severity: Minor
          Found in lib/engine/routeinjector/utils.js - About 1 hr 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

          Consider simplifying this complex logical expression.
          Open

              if ((routesRestrictions.blacklist && routesRestrictions.blacklist.routes) || (routesRestrictions.whitelist && routesRestrictions.whitelist.routes)) {
                  allowed = (routesRestrictions.whitelist && routesRestrictions.whitelist.routes && routesRestrictions.whitelist.routes.indexOf(method) > -1) ||
                      (routesRestrictions.blacklist && routesRestrictions.blacklist.routes && routesRestrictions.blacklist.routes.indexOf(method) == -1);
              }
          Severity: Critical
          Found in lib/engine/routeinjector/utils.js - About 1 hr to fix

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

            module.exports.checkSetup = function (Model) {
                var mConf = Model.injector();
            
                //Limit shards based on the environment!
                if (mConf.shard && mConf.shard.shardValues) {
            Severity: Minor
            Found in lib/engine/routeinjector/utils.js - About 1 hr to fix

              Function configureForm has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              module.exports.configureForm = function (Model) {
                  var inj = Model.injector();
                  if (inj.form && inj.form.tabs) {
                      for (var t in inj.form.tabs) {
                          var tab = inj.form.tabs[t];
              Severity: Minor
              Found in lib/engine/routeinjector/utils.js - About 1 hr to fix

                Function getConfigByProfile has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                module.exports.getConfigByProfile = function (gConfig, req) {
                    var profile = req.query.profile || req.headers.profile;
                    var config = {};
                
                    if (profile == undefined) {
                Severity: Minor
                Found in lib/engine/routeinjector/utils.js - About 1 hr to fix

                  Function checkSetup has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                  module.exports.checkSetup = function (Model) {
                      var mConf = Model.injector();
                  
                      //Limit shards based on the environment!
                      if (mConf.shard && mConf.shard.shardValues) {
                  Severity: Minor
                  Found in lib/engine/routeinjector/utils.js - About 1 hr 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 getConfigByProfile has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                  module.exports.getConfigByProfile = function (gConfig, req) {
                      var profile = req.query.profile || req.headers.profile;
                      var config = {};
                  
                      if (profile == undefined) {
                  Severity: Minor
                  Found in lib/engine/routeinjector/utils.js - About 55 mins 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 routeConfigurationCheck has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function routeConfigurationCheck(config, method) {
                      var routesRestrictions = injector.config.env.restrictions || {};
                      var allowed = true;
                  
                      if ((routesRestrictions.blacklist && routesRestrictions.blacklist.routes) || (routesRestrictions.whitelist && routesRestrictions.whitelist.routes)) {
                  Severity: Minor
                  Found in lib/engine/routeinjector/utils.js - About 45 mins 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

                  Avoid deeply nested control flow statements.
                  Open

                                      for (var i in doc) {
                                          if (doc.hasOwnProperty(i)) {
                                              //Prune all the elements in the object
                                              doc[i] = prune(doc[i]);
                                          }
                  Severity: Major
                  Found in lib/engine/routeinjector/utils.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if (parent) {
                                            var child = element.substring(parentPath.length + 1);
                                            return module.exports.getElementSchema(parent.schema.paths, child);
                                        }
                    Severity: Major
                    Found in lib/engine/routeinjector/utils.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                          if (Object.keys(objDoc).length > 0) {
                                              for (var i in objDoc) {
                                                  if (objDoc.hasOwnProperty(i)) {
                                                      //Prune all the elements in the object
                                                      //Although we are working with the plain object, we COPY and PRUNE the original object
                      Severity: Major
                      Found in lib/engine/routeinjector/utils.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                            if (objDoc == null || objDoc == undefined) {
                                                //Null objects marked as undefined
                                                doc = undefined;
                                            }
                        Severity: Major
                        Found in lib/engine/routeinjector/utils.js - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                              if (parentPath) {
                                                  parentPath += "." + chunk
                                              } else {
                                                  parentPath = chunk;
                                              }
                          Severity: Major
                          Found in lib/engine/routeinjector/utils.js - About 45 mins to fix

                            Function runPostCallbacks has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            module.exports.runPostCallbacks = function (config, req, res, value, cbk) {
                            Severity: Minor
                            Found in lib/engine/routeinjector/utils.js - About 35 mins to fix

                              Function runPreCallbacks has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                              module.exports.runPreCallbacks = function (preFnArray, Model, req, res, cbk) {
                              Severity: Minor
                              Found in lib/engine/routeinjector/utils.js - About 35 mins to fix

                                Function iterate has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                module.exports.iterate = function it(fullPath, doc, iterator, callback, parents) {
                                Severity: Minor
                                Found in lib/engine/routeinjector/utils.js - About 35 mins to fix

                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                          if (restrictions && restrictions.whitelist && restrictions.whitelist.shards) {
                                              mConf.shard.shardValues = _.intersection(restrictions.whitelist.shards, mConf.shard.shardValues);
                                          }
                                  Severity: Major
                                  Found in lib/engine/routeinjector/utils.js and 1 other location - About 1 hr to fix
                                  lib/engine/routeinjector/utils.js on lines 21..23

                                  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 67.

                                  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

                                  Further Reading

                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                          if (restrictions && restrictions.blacklist && restrictions.blacklist.shards) {
                                              mConf.shard.shardValues = _.xor(restrictions.blacklist.shards, mConf.shard.shardValues);
                                          }
                                  Severity: Major
                                  Found in lib/engine/routeinjector/utils.js and 1 other location - About 1 hr to fix
                                  lib/engine/routeinjector/utils.js on lines 25..27

                                  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 67.

                                  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

                                  Further Reading

                                  Identical blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                      if (profile == undefined) {
                                          config = gConfig.profiles._default;
                                          if (config == undefined) {
                                              config = {
                                                  mongo: {
                                  Severity: Major
                                  Found in lib/engine/routeinjector/utils.js and 1 other location - About 1 hr to fix
                                  lib/engine/routeinjector/utils.js on lines 300..311

                                  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 59.

                                  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

                                  Further Reading

                                  Identical blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                          if (config == undefined) {
                                              config = gConfig.profiles._default;
                                              if (config == undefined) {
                                                  config = {
                                                      mongo: {
                                  Severity: Major
                                  Found in lib/engine/routeinjector/utils.js and 1 other location - About 1 hr to fix
                                  lib/engine/routeinjector/utils.js on lines 287..312

                                  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 59.

                                  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

                                  Further Reading

                                  There are no issues that match your filters.

                                  Category
                                  Status