yoctore/yocto-mongoose

View on GitHub

Showing 82 of 82 total issues

Consider simplifying this complex logical expression.
Open

  if (_.isString(path) && _.isArray(items) && !_.isEmpty(path) && !_.isEmpty(items) &&
     _.isObject(schema) && (schema instanceof Schema) &&
     _.isString(modelName) && !_.isEmpty(modelName)) {
    // retrieving files
    var files = glob.sync([ '**/', modelName, '.js'].join(''), {
Severity: Critical
Found in src/modules/method/index.js - About 1 hr to fix

    Function get has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Crud.prototype.get = function (conditions, filter, method) {
      // process redis usage
      var redis = this[ method === 'findOne' ? 'getOneRedis' : 'getRedis' ];
    
      // defined default method name to use
    Severity: Minor
    Found in src/modules/crud/index.js - About 1 hr to fix

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

      YMongoose.prototype.isConnected = function () {
        // default statement
        return this.mongoose.connection.readyState === this.mongoose.Connection.STATES.connected;
      };
      Severity: Major
      Found in src/index.js and 1 other location - About 1 hr to fix
      src/index.js on lines 122..125

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

      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

      YMongoose.prototype.isDisconnected = function () {
        // default statement
        return this.mongoose.connection.readyState === this.mongoose.Connection.STATES.disconnected;
      };
      Severity: Major
      Found in src/index.js and 1 other location - About 1 hr to fix
      src/index.js on lines 112..115

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

      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

      Function add has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Crud.prototype.add = function (schema, exclude, redisIncludes, redis) {
        // valid data ?
        if ((!_.isObject(schema) && !(schema instanceof Schema)) || !_.isArray(exclude)) {
          this.logger.warning('[ Crud.add ] - Schema or exclude item given is invalid');
          // invalid statement
      Severity: Minor
      Found in src/modules/crud/index.js - About 1 hr to fix

        Function isReady has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        YMongoose.prototype.isReady = function (showErrors) {
          // show errors ?
          if (showErrors) {
            // check connection
            if (!this.isConnected()) {
        Severity: Minor
        Found in src/index.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 get has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        Crud.prototype.get = function (conditions, filter, method) {
          // process redis usage
          var redis = this[ method === 'findOne' ? 'getOneRedis' : 'getRedis' ];
        
          // defined default method name to use
        Severity: Minor
        Found in src/modules/crud/index.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 load has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Enums.prototype.load = function (path) {
          try {
            // test is a valid path
            if (!_.isString(path) || _.isEmpty(path)) {
              throw 'Invalid path given.';
        Severity: Minor
        Found in src/modules/enum/index.js - About 1 hr to fix

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

          YMongoose.prototype.validators = function (directory) {
            // message
            this.logger.debug('[ YMongoose.validators ] - Try to set validator defintion path.');
            // default statement
            return this.setPath(directory, 'validator');
          Severity: Major
          Found in src/index.js and 3 other locations - About 1 hr to fix
          src/index.js on lines 341..346
          src/index.js on lines 367..372
          src/index.js on lines 380..385

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

          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 4 locations. Consider refactoring.
          Open

          YMongoose.prototype.models = function (directory) {
            // message
            this.logger.debug('[ YMongoose.models ] - Try to set model defintion path.');
            // default statement
            return this.setPath(directory, 'model');
          Severity: Major
          Found in src/index.js and 3 other locations - About 1 hr to fix
          src/index.js on lines 354..359
          src/index.js on lines 367..372
          src/index.js on lines 380..385

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

          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 4 locations. Consider refactoring.
          Open

          YMongoose.prototype.enums = function (directory) {
            // message
            this.logger.debug('[ YMongoose.enums ] - Try to set enums defintion path.');
            // default statement
            return this.setPath(directory, 'enums');
          Severity: Major
          Found in src/index.js and 3 other locations - About 1 hr to fix
          src/index.js on lines 341..346
          src/index.js on lines 354..359
          src/index.js on lines 367..372

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

          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 4 locations. Consider refactoring.
          Open

          YMongoose.prototype.methods = function (directory) {
            // message
            this.logger.debug('[ YMongoose.methods ] - Try to set methods defintion path.');
            // default statement
            return this.setPath(directory, 'method');
          Severity: Major
          Found in src/index.js and 3 other locations - About 1 hr to fix
          src/index.js on lines 341..346
          src/index.js on lines 354..359
          src/index.js on lines 380..385

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

          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

          Function disconnect has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          YMongoose.prototype.disconnect = function () {
            // Create our deferred object, which we will use in our promise chain
            var deferred = Q.defer();
          
            // try to disconnect
          Severity: Minor
          Found in src/index.js - About 1 hr to fix

            Function listenEvents has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            RedisUtils.prototype.listenEvents = function () {
              // default events
              var events = [
                { key : 'connect', message      : 'is connecting' },
                { key : 'ready', message        : 'is ready' },
            Severity: Minor
            Found in src/modules/utils/redis.js - About 1 hr to fix

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

                if (validate.error) {
                  // log error message
                  this.logger.warning([ '[ RedisUtils.connect ] - Invalid host config given :',
                                        validate.error ] .join(' '));
                  // default invalid statement
              Severity: Minor
              Found in src/modules/utils/redis.js and 1 other location - About 55 mins to fix
              src/index.js on lines 299..305

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

              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 (validate.error) {
                  // log error message
                  this.logger.warning([ '[ YMongoose.elasticHosts ] - Invalid host config given :',
                                        validate.error ] .join(' '));
                  // default invalid statement
              Severity: Minor
              Found in src/index.js and 1 other location - About 55 mins to fix
              src/modules/utils/redis.js on lines 114..120

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

              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

              Function create has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              Crud.prototype.create = function (value) {
                // Create our deferred object, which we will use in our promise chain
                var deferred = Q.defer();
                // create default instance model
                var model = !_.isFunction(this.save) ? new this() : this;
              Severity: Minor
              Found in src/modules/crud/index.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

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

                        if (cerror) {
                          // message
                          this.logger.error([ '[ YMongoose.disconnect ] - Connection close failed.',
                                                 'Error is :', cerror.message ].join(' '));
                          // reject disconnect failed
              Severity: Minor
              Found in src/index.js and 1 other location - About 50 mins to fix
              src/index.js on lines 232..257

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

              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 (error) {
                      // message
                      this.logger.error([ '[ YMongoose.disconnect ] - Disconnect failed.',
                                             'Error is :', error.message ].join(' '));
                      // reject disconnect failed
              Severity: Minor
              Found in src/index.js and 1 other location - About 50 mins to fix
              src/index.js on lines 244..255

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

              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

              Avoid deeply nested control flow statements.
              Open

                            if (item.redis) {
                              // has custom redis expire time define on schema for specific key/method ?
                              if (!_.isArray(schema.redisExpireTimeByKey)) {
                                // create default item
                                schema.redisExpireTimeByKey = [];
              Severity: Major
              Found in src/modules/method/index.js - About 45 mins to fix
                Severity
                Category
                Status
                Source
                Language