fogine/couchbase-odm

View on GitHub

Showing 72 of 72 total issues

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

Object.defineProperty(UUID4Key.prototype, 'inspect', {
    writable: true,
    value: function() {
        return '[object UUID4Key: "' + this.toString() + '" ]';
    }
Severity: Major
Found in lib/key/uuid4Key.js and 2 other locations - About 55 mins to fix
lib/key/incrementalKey.js on lines 72..77
lib/key/refDocKey.js on lines 156..161

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

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

Object.defineProperty(RefDocKey.prototype, 'inspect', {
    writable: true,
    value: function() {
        return '[object RefDocKey: "' + this.toString() + '" ]';
    }
Severity: Major
Found in lib/key/refDocKey.js and 2 other locations - About 55 mins to fix
lib/key/incrementalKey.js on lines 72..77
lib/key/uuid4Key.js on lines 65..70

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

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

Model.prototype.getByIdOrFail = Promise.method(function(id, options) {
    let key = id;
    const actions = [];
    const defaults = {
        paranoid: true,
Severity: Minor
Found in lib/model.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

Function validate has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

        validate: function(schema, data, parentSchema, dataPath, parentData, prop) {
Severity: Minor
Found in lib/validator.js - About 45 mins to fix

    Function validate has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            validate: function(schema, data, parentSchema, dataPath, parentData, prop) {
    Severity: Minor
    Found in lib/validator.js - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                  if (!_.isEmpty(_schema)) {
                      _.set(out, ['items'], _schema);
                  }
      Severity: Major
      Found in lib/util/schema.js - About 45 mins to fix

        Function generate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        RefDocKey.prototype.generate = Promise.method(function(instance) {
        
            let id = "";
            let instanceData = instance.getData();
        
        
        Severity: Minor
        Found in lib/key/refDocKey.js - About 35 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 _cloneData has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        Instance.prototype._cloneData = function(customizer) {
            return _.cloneDeepWith(this.getData(), function(val) {
                if (customizer instanceof Function) {
                    let resolved = customizer(val);
                    if (resolved !== undefined) {
        Severity: Minor
        Found in lib/instance.js - About 35 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 too many return statements within this function.
        Open

                        return Promise.reject(reason);
        Severity: Major
        Found in lib/instance.js - About 30 mins to fix

          Function removeHook has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          Hook.removeHook = function(hookType, name) {
              if (HookValues.indexOf(HookType[hookType]) === -1) {
                  throw new HookError('Attempted to remove hook: ' + name + ' of invalid hook type.');
              }
          
          
          Severity: Minor
          Found in lib/hook.js - About 25 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 Model has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          function Model(name, schema, options) {
          
              if (!name || (typeof name !== "string" && !(name instanceof String) )) {
                  throw new ModelError("Model's name must be non-empty string value");
              }
          Severity: Minor
          Found in lib/model.js - About 25 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 build has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          function build(options) {
              const defaults = {
                  _data: true, //data json references
                  allErrors: false,
                  verbose: true, //include validated data in errors
          Severity: Minor
          Found in lib/validator.js - About 25 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

          Severity
          Category
          Status
          Source
          Language