busy-web/data

View on GitHub

Showing 32 of 32 total issues

Function validateDocumentStructure has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

function validateDocumentStructure(doc) {
  let errors = [];
  if (!doc || typeof doc !== 'object') {
    errors.push('Top level of a JSON API document must be an object');
  } else {
Severity: Minor
Found in addon/mixins/store-finders.js - About 6 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 buildJSON has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    buildJSON(store, primaryModelClass, type, json, included) {
        const primaryKey = get(this, 'primaryKey');

        // create a data type object
        const model = {
Severity: Minor
Found in addon/mixins/json-api-serializer.js - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File store-finders.js has 281 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * @module store
 *
 */
import { getOwner } from '@ember/application';
Severity: Minor
Found in addon/mixins/store-finders.js - About 2 hrs to fix

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

        addRelationships(store, primaryModelClass, json) {
            const data = {};
            primaryModelClass.eachRelationship((type, opts) => {
                // get the model name + -id and underscore it.
                let name = underscore(`${opts.type}-id`);
    Severity: Major
    Found in addon/mixins/json-api-serializer.js - About 2 hrs to fix

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

          initialize(/*registry*/) {
              DS.RPCModel = DS.Model.extend(RPCModelMixin, {});
      
              const belongsTo = DS.belongsTo;
      
      
      Severity: Major
      Found in addon/initializers/@busy-web/data.js - About 2 hrs to fix

        Function serializeAttribute has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            serializeAttribute(snapshot, json, key, attribute) {
                const type = attribute.type;
                if (this._canSerialize(key)) {
                    let value = snapshot.attr(key);
                    if (!isNone(type) && value !== undefined && value !== '_-NULL-_' && value !== '!_-NULL-_' && value !== '_-DISABLE-_')  {
        Severity: Minor
        Found in addon/serializers/json.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 validateDocumentStructure has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function validateDocumentStructure(doc) {
          let errors = [];
          if (!doc || typeof doc !== 'object') {
            errors.push('Top level of a JSON API document must be an object');
          } else {
        Severity: Minor
        Found in addon/mixins/store-finders.js - About 1 hr to fix

          Function typeCast has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          function typeCast(value) {
              if (/^[.][\d]+/.test(value)) {
                  return typeCast(0 + value);
              }
          
          
          Severity: Minor
          Found in addon/utils/query.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 _sendBatch has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              _sendBatch() {
                  const { requests, responses } = this._requestStore.flushPending();
                  this.rpcRequest(this.store, 'batch', 'batch-rest', { requests }).then(batch => {
                      const results = get(batch, 'data.results');
                      if (batch.success && results) {
          Severity: Minor
          Found in addon/mixins/batch.js - About 1 hr to fix

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

            function nextParams(model, query, lastQuery) {
                let isJsonApi = false;
                let next = get(model, 'meta.next');
                if (isNone(next)) {
                    isJsonApi = true;
            Severity: Minor
            Found in addon/mixins/store-finders.js - About 1 hr to fix

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

                  buildJSON(store, primaryModelClass, type, json, included) {
                      const primaryKey = get(this, 'primaryKey');
              
                      // create a data type object
                      const model = {
              Severity: Minor
              Found in addon/mixins/json-api-serializer.js - About 1 hr to fix

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

                    normalizeResponse(store, primaryModelClass, payload, id, requestType) {
                        let response;
                        if (!payload.jsonapi) {
                            if (requestType === 'deleteRecord') { // delete record should return a no content response
                                response = {
                Severity: Minor
                Found in addon/mixins/json-api-serializer.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

                    headersForRequest(params) {
                        const headers = this._super(params);
                        if (params._requestType === 'rpc') {
                            headers.Accept = 'application/json; charset=utf-8';
                        }
                Severity: Minor
                Found in addon/mixins/rpc-adapter.js and 1 other location - About 55 mins to fix
                addon/mixins/rpc-adapter.js on lines 140..146

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

                    _requestFor(params) {
                        const res = this._super(params);
                        if (params._requestType === 'rpc') {
                            res._requestType = 'rpc';
                        }
                Severity: Minor
                Found in addon/mixins/rpc-adapter.js and 1 other location - About 55 mins to fix
                addon/mixins/rpc-adapter.js on lines 107..113

                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

                Avoid deeply nested control flow statements.
                Open

                                        if (!get(value, primaryKey)) {
                                            value.id = v4.apply(v4, arguments);
                                        }
                Severity: Major
                Found in addon/mixins/json-api-serializer.js - About 45 mins to fix

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

                  function normalizeResponseHelper(serializer, store, modelClass, payload, id, requestType) {
                  Severity: Minor
                  Found in addon/mixins/store-finders.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                                if (opts.kind === 'belongsTo') {
                                                    link += `&page_size=1`;
                                                }
                    Severity: Major
                    Found in addon/mixins/json-api-serializer.js - About 45 mins to fix

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

                              if (!isEmpty(codes)) {
                                  codes.forEach((code, idx) => {
                                      errs.push(this.normalizeAdapterError(type, status, code, details[idx]));
                                  });
                              } else if (!isEmpty(details)) {
                      Severity: Minor
                      Found in addon/utils/error.js and 1 other location - About 40 mins to fix
                      addon/utils/error.js on lines 30..36

                      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

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

                              } else if (!isEmpty(details)) {
                                  codes.forEach((code, idx) => {
                                      errs.push(this.normalizeAdapterError(type, status, code, details[idx]));
                                  });
                              } else {
                      Severity: Minor
                      Found in addon/utils/error.js and 1 other location - About 40 mins to fix
                      addon/utils/error.js on lines 26..36

                      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

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

                          convertResponse(store, primaryModelClass, payload, id, requestType) {
                      Severity: Minor
                      Found in addon/mixins/json-api-serializer.js - About 35 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language