yahoo/elide-js

View on GitHub
lib/datastores/jsonapidatastore.js

Summary

Maintainability
F
1 wk
Test Coverage

File jsonapidatastore.js has 953 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/jsonapidatastore.js - About 2 days to fix

    Function find has 111 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      find(query) {
        let willReject = false;
        let withReason;
        let params = query._params;
        let options = query._opts;
    Severity: Major
    Found in lib/datastores/jsonapidatastore.js - About 4 hrs to fix

      JsonApiDatastore has 34 functions (exceeds 20 allowed). Consider refactoring.
      Open

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

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

          find(query) {
            let willReject = false;
            let withReason;
            let params = query._params;
            let options = query._opts;
        Severity: Minor
        Found in lib/datastores/jsonapidatastore.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 _transformRequest has 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _transformRequest(model, toSend, fillBlanks) {
            let payload = {
              data: {
                type: model,
                id: toSend.id,
        Severity: Major
        Found in lib/datastores/jsonapidatastore.js - About 2 hrs to fix

          Function _fromApiObject has 62 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _fromApiObject(apiObject) {
              let template = this._models[apiObject.type];
              let projection = {
                id: apiObject.id
              };
          Severity: Major
          Found in lib/datastores/jsonapidatastore.js - About 2 hrs to fix

            Function _rootDiffs has 57 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              _rootDiffs(diffTree) {
                let rootedDiffs = [];
            
                let rootDiffs = function rootDiffs(parentPath, objectId, object) {
                  let diffs = [];
            Severity: Major
            Found in lib/datastores/jsonapidatastore.js - About 2 hrs to fix

              Function _rollUpDiffs has 49 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                _rollUpDiffs(objectDiffs, model, fromObjects) {
                  let template = this._models[model];
                  if (!template.links) { return; }
              
                  Object.keys(fromObjects).forEach((id) => {
              Severity: Minor
              Found in lib/datastores/jsonapidatastore.js - About 1 hr to fix

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

                  commit(patches) {
                    let unrootedDiffs = this._parseObjects(patches);
                
                    let diffTree = {};
                    for (let i = 0; i < this._modelHierarchy.length; i++) {
                Severity: Minor
                Found in lib/datastores/jsonapidatastore.js - About 1 hr to fix

                  Function _getUrlForModel has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    _getUrlForModel(model, getCollection, withData) {
                      let willReject = false;
                      let withReason;
                  
                      let modelUrl = this._urlTemplateCache[model];
                  Severity: Minor
                  Found in lib/datastores/jsonapidatastore.js - About 1 hr to fix

                    Function _buildModelHierarchy has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      _buildModelHierarchy() {
                        let models = [];
                        let inList = {};
                        let hierarchy = [];
                    
                    
                    Severity: Minor
                    Found in lib/datastores/jsonapidatastore.js - About 1 hr to fix

                      Function _rootNewModel has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        _rootNewModel(model, id, state) {
                          let rootPath;
                      
                          let requiredModels = this._urlTemplateCache[model].split('|');
                          rootPath = requiredModels.shift();
                      Severity: Minor
                      Found in lib/datastores/jsonapidatastore.js - About 1 hr to fix

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

                          _parseObjects(patches) {
                            let objects = {};
                        
                            patches.forEach((patch) => {
                              let [ , model, id, ...path] = patch.path.split('/');
                        Severity: Minor
                        Found in lib/datastores/jsonapidatastore.js - About 1 hr to fix

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

                            _findLinkingObject(fromModel, toModel, toId) {
                              let fromId;
                              let alias = this._aliasIds[toId];
                          
                              /*
                          Severity: Minor
                          Found in lib/datastores/jsonapidatastore.js - About 1 hr to fix

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

                              _rootDiffs(diffTree) {
                                let rootedDiffs = [];
                            
                                let rootDiffs = function rootDiffs(parentPath, objectId, object) {
                                  let diffs = [];
                            Severity: Minor
                            Found in lib/datastores/jsonapidatastore.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 _getUrlForModel has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                              _getUrlForModel(model, getCollection, withData) {
                                let willReject = false;
                                let withReason;
                            
                                let modelUrl = this._urlTemplateCache[model];
                            Severity: Minor
                            Found in lib/datastores/jsonapidatastore.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 _fromApiObject has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              _fromApiObject(apiObject) {
                                let template = this._models[apiObject.type];
                                let projection = {
                                  id: apiObject.id
                                };
                            Severity: Minor
                            Found in lib/datastores/jsonapidatastore.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 _buildModelHierarchy has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              _buildModelHierarchy() {
                                let models = [];
                                let inList = {};
                                let hierarchy = [];
                            
                            
                            Severity: Minor
                            Found in lib/datastores/jsonapidatastore.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

                                return this._request('PATCH', url, queryParams, data, JSONAPI_MIME_TYPE)
                                  .then(this._transformResult.bind(this), (error) => {
                                    printDebug(error);
                                    let message = ERROR_CANNOT_UPDATE_OBJECT
                                                  .replace('${model}', model)
                            Severity: Major
                            Found in lib/datastores/jsonapidatastore.js and 1 other location - About 3 hrs to fix
                            lib/datastores/jsonapidatastore.js on lines 1139..1147

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

                            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

                                return this._request('POST', url, queryParams, data, JSONAPI_MIME_TYPE)
                                  .then(this._transformResult.bind(this), (error) => {
                                    printDebug(error);
                                    let message = ERROR_CANNOT_CREATE_OBJECT
                                                  .replace('${model}', model)
                            Severity: Major
                            Found in lib/datastores/jsonapidatastore.js and 1 other location - About 3 hrs to fix
                            lib/datastores/jsonapidatastore.js on lines 1165..1172

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

                            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

                                    Object.keys(template.links).forEach((linkName) => {
                                      let link = template.links[linkName];
                                      if (!inList[link.model]) {
                                        newModels.push(link.model);
                                        inList[link.model] = true;
                            Severity: Major
                            Found in lib/datastores/jsonapidatastore.js and 1 other location - About 2 hrs to fix
                            lib/datastores/jsonapidatastore.js on lines 216..222

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

                            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

                                  Object.keys(template.links).forEach((linkName) => {
                                    let link = template.links[linkName];
                                    if (!inList[link.model]) {
                                      models.push(link.model);
                                      inList[link.model] = true;
                            Severity: Major
                            Found in lib/datastores/jsonapidatastore.js and 1 other location - About 2 hrs to fix
                            lib/datastores/jsonapidatastore.js on lines 232..238

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

                            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 (!this._relationCache[fromModel].hasOwnProperty(toModel)) {
                                  this._relationCache[fromModel][toModel] = {};
                                }
                            Severity: Minor
                            Found in lib/datastores/jsonapidatastore.js and 1 other location - About 30 mins to fix
                            lib/datastores/jsonapidatastore.js on lines 369..371

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

                            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 (!this._relationCache[toModel].hasOwnProperty(fromModel)) {
                                  this._relationCache[toModel][fromModel] = {};
                                }
                            Severity: Minor
                            Found in lib/datastores/jsonapidatastore.js and 1 other location - About 30 mins to fix
                            lib/datastores/jsonapidatastore.js on lines 361..363

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

                            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