yahoo/elide-js

View on GitHub
lib/datastores/memorydatastore.js

Summary

Maintainability
F
5 days
Test Coverage

File memorydatastore.js has 568 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*********************************************************************************
 * Copyright 2015 Yahoo Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 ********************************************************************************/
Severity: Major
Found in lib/datastores/memorydatastore.js - About 1 day to fix

    Function find has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

      find(query) {
        let willReject = false;
        let withReason;
        let foundObject;
        let foundObjects = [];
    Severity: Minor
    Found in lib/datastores/memorydatastore.js - About 5 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 find has 95 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      find(query) {
        let willReject = false;
        let withReason;
        let foundObject;
        let foundObjects = [];
    Severity: Major
    Found in lib/datastores/memorydatastore.js - About 3 hrs to fix

      MemoryDatastore has 28 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class MemoryDatastore extends Datastore {
        constructor(Promise, ttl, baseURL, models) {
          super(Promise, ttl, baseURL, models);
      
          this._data = {};
      Severity: Minor
      Found in lib/datastores/memorydatastore.js - About 3 hrs to fix

        Function _updateLinkProperties has 71 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _updateLinkProperties(model, instance, state, createProps, method) {
            let willReject = false;
            let withReason;
        
            let watcher = new ChangeWatcher();
        Severity: Major
        Found in lib/datastores/memorydatastore.js - About 2 hrs to fix

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

            update(model, state) {
              this._checkModel(model, 'update');
              let willReject = false;
              let withReason;
          
          
          Severity: Minor
          Found in lib/datastores/memorydatastore.js - About 1 hr to fix

            Function create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              create(model, state) {
                this._checkModel(model, 'create');
                let willReject = false;
                let withReason;
            
            
            Severity: Minor
            Found in lib/datastores/memorydatastore.js - About 1 hr to fix

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

                commit(_) {
                  let willReject = false;
              
                  if (!this._upstream) {
                    return this._promise.reject(new Error(ERROR_NO_UPSTREAM));
              Severity: Minor
              Found in lib/datastores/memorydatastore.js - About 1 hr to fix

                Function _ensureReferencesExist has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  _ensureReferencesExist(model, value, method) {
                    let willReject = false;
                    let withReason;
                
                    if (!value) {
                Severity: Minor
                Found in lib/datastores/memorydatastore.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 update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  update(model, state) {
                    this._checkModel(model, 'update');
                    let willReject = false;
                    let withReason;
                
                
                Severity: Minor
                Found in lib/datastores/memorydatastore.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 this._promise.resolve(toUpdate);
                Severity: Major
                Found in lib/datastores/memorydatastore.js - About 30 mins to fix

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

                    _setDataFromUpstreamQuery(query, results) {
                      let model;
                  
                      if (results === undefined || results.length === 0) {
                        return;
                  Severity: Minor
                  Found in lib/datastores/memorydatastore.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 create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    create(model, state) {
                      this._checkModel(model, 'create');
                      let willReject = false;
                      let withReason;
                  
                  
                  Severity: Minor
                  Found in lib/datastores/memorydatastore.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

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

                            for (let i = 0; i < toRemove.length; i++) {
                              let leaf = this._getData(otherModel, toRemove[i]);
                              watcher.watchModel(leaf, otherModel);
                  
                              this._removeMultiLeaf(model, prop, instance,
                  Severity: Major
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 2 hrs to fix
                  lib/datastores/memorydatastore.js on lines 586..592

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

                  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

                            for (let i = 0; i < value.length; i++) {
                              let leaf = this._getData(otherModel, value[i]);
                              watcher.watchModel(leaf, otherModel);
                  
                              this._addMultiLeaf(model, prop, instance,
                  Severity: Major
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 2 hrs to fix
                  lib/datastores/memorydatastore.js on lines 578..584

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

                  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 (leafInstance[leafProp] !== rootInstance.id) {
                        let curRoot = this._getData(rootModel, leafInstance[leafProp]);
                        watcher.watchModel(curRoot, rootModel);
                  
                        this._removeMultiLeaf(rootModel, rootProp, curRoot,
                  Severity: Major
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 1 hr to fix
                  lib/datastores/memorydatastore.js on lines 410..416

                  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 (leafInstance[leafProp] !== rootInstance.id) {
                          let curRoot = this._getData(rootModel, leafInstance[leafProp]);
                          watcher.watchModel(curRoot, rootModel);
                  
                          this._removeMultiRoot(rootModel, rootProp, curRoot,
                  Severity: Major
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 1 hr to fix
                  lib/datastores/memorydatastore.js on lines 444..450

                  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 (rootInstance[rootProp] !== undefined) {
                        // we need to unlink the current value
                        let curLeaf = this._getData(leafModel, rootInstance[rootProp]);
                        watcher.watchModel(curLeaf, leafModel);
                  
                  
                  Severity: Minor
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 55 mins to fix
                  lib/datastores/memorydatastore.js on lines 284..291

                  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

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

                      if (rootInstance[rootProp] !== undefined) {
                        // we need to unlink the current value
                        let curLeaf = this._getData(leafModel, rootInstance[rootProp]);
                        watcher.watchModel(curLeaf, leafModel);
                  
                  
                  Severity: Minor
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 55 mins to fix
                  lib/datastores/memorydatastore.js on lines 343..350

                  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 (direction === OWNS) {
                            let leaf = this._getData(otherModel, value);
                            watcher.watchModel(leaf, otherModel);
                            this._addSingleLeaf(model, prop, instance,
                                                otherModel, otherProp, leaf, watcher);
                  Severity: Minor
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 40 mins to fix
                  lib/datastores/memorydatastore.js on lines 574..600

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

                  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 (direction === OWNS) {
                            let toRemove = instance[prop].filter((element) => {
                              return value.indexOf(element) === -1;
                            });
                            for (let i = 0; i < toRemove.length; i++) {
                  Severity: Minor
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 40 mins to fix
                  lib/datastores/memorydatastore.js on lines 559..571

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

                  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

                      } else if (!this._getData(model, state.id)) {
                        let err = new Error(ERROR_CANNOT_UPDATE_MISSING_RECORD
                                      .replace('${model}', model)
                                      .replace('${method}', 'update'));
                        return this._promise.reject(err);
                  Severity: Minor
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 40 mins to fix
                  lib/datastores/memorydatastore.js on lines 835..843

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

                  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

                      } else if (!this._getData(model, state.id)) {
                        let err = new Error(ERROR_CANNOT_UPDATE_MISSING_RECORD
                                      .replace('${model}', model)
                                      .replace('${method}', 'delete'));
                        return this._promise.reject(err);
                  Severity: Minor
                  Found in lib/datastores/memorydatastore.js and 1 other location - About 40 mins to fix
                  lib/datastores/memorydatastore.js on lines 793..817

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

                  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