mbroadst/thinkagain

View on GitHub
lib/query.js

Summary

Maintainability
F
1 wk
Test Coverage

File query.js has 597 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';
const Promise = require('bluebird'),
      Errors = require('./errors'),
      Feed = require('./feed'),
      util = require('./util');
Severity: Major
Found in lib/query.js - About 1 day to fix

    Function getJoin has 109 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      getJoin(modelToGet, _getAll, gotModel) {
        let r = this._model._getModel()._thinkagain.r;
        let model = this._model;
        let joins = this._model._getModel()._joins;
    
    
    Severity: Major
    Found in lib/query.js - About 4 hrs to fix

      Function removeRelation has 105 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        removeRelation(field, joinedDocument) {
          let model = this._model;
          let joins = this._model._getModel()._joins;
          let joinedModel = joins[field].model;
          let r = this._model._thinkagain.r;
      Severity: Major
      Found in lib/query.js - About 4 hrs to fix

        Function addRelation has 99 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          addRelation(field, joinedDocument) {
            let model = this._model;
            let joins = this._model._getModel()._joins;
            let joinedModel = joins[field].model;
            let r = this._model._thinkagain.r;
        Severity: Major
        Found in lib/query.js - About 3 hrs to fix

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

            removeRelation(field, joinedDocument) {
              let model = this._model;
              let joins = this._model._getModel()._joins;
              let joinedModel = joins[field].model;
              let r = this._model._thinkagain.r;
          Severity: Minor
          Found in lib/query.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 addRelation has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

            addRelation(field, joinedDocument) {
              let model = this._model;
              let joins = this._model._getModel()._joins;
              let joinedModel = joins[field].model;
              let r = this._model._thinkagain.r;
          Severity: Minor
          Found in lib/query.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 _validateQueryResult has 62 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _validateQueryResult(result) {
              if (result.errors > 0) {
                return Promise.reject(new Errors.InvalidWrite('An error occured during the write', result));
              }
          
          
          Severity: Major
          Found in lib/query.js - About 2 hrs to fix

            Function _executeCallback has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              _executeCallback(fullOptions, parse, groupFormat) {
                if (this._error !== undefined) {
                  return Promise.reject(new Errors.ThinkAgainError('The partial value is not valid, so the write was not executed.', this._error));
                }
            
            
            Severity: Minor
            Found in lib/query.js - About 1 hr to fix

              Function _query has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                        this._query = this._query.merge(doc => {
                          if ((model.getTableName() === joins[key].model.getTableName()) && (joins[key].leftKey === joins[key].rightKey)) {
                            // In case the model is linked with itself on the same key
              
                            innerQuery = r.table(joins[key].link)
              Severity: Minor
              Found in lib/query.js - About 1 hr to fix

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

                  constructor(model, query, options, error) {
                    this._model = model; // constructor of the model we should use for the results.
                    if (model !== undefined) {
                      this._r = model._getModel()._thinkagain.r;
                      util.loopKeys(model._getModel()._staticMethods, (staticMethods, key) => {
                Severity: Minor
                Found in lib/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 constructor has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  constructor(model, query, options, error) {
                    this._model = model; // constructor of the model we should use for the results.
                    if (model !== undefined) {
                      this._r = model._getModel()._thinkagain.r;
                      util.loopKeys(model._getModel()._staticMethods, (staticMethods, key) => {
                Severity: Minor
                Found in lib/query.js - About 1 hr to fix

                  Avoid deeply nested control flow statements.
                  Open

                                  if (model.getTableName() < joinedModel.getTableName()) {
                                    return linkModel.getAll(leftKey.add('_').add(rightKey)).delete()._query;
                                  } else if (model.getTableName() > joinedModel.getTableName()) {
                                    return linkModel.getAll(rightKey.add('_').add(leftKey)).delete()._query;
                                  }
                  Severity: Major
                  Found in lib/query.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    if (model.getTableName() < joinedModel.getTableName()) {
                                      return linkModel.getAll(leftKey.add('_').add(rightKey)).delete()._query;
                                    } else if (model.getTableName() > joinedModel.getTableName()) {
                                      return linkModel.getAll(rightKey.add('_').add(leftKey)).delete()._query;
                                    }
                    Severity: Major
                    Found in lib/query.js - About 45 mins to fix

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

                        _validateQueryResult(result) {
                          if (result.errors > 0) {
                            return Promise.reject(new Errors.InvalidWrite('An error occured during the write', result));
                          }
                      
                      
                      Severity: Minor
                      Found in lib/query.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 linkModel.insert(linkValue, {conflict: 'replace', returnChanges: 'always'})
                              .do(result => r.branch(
                                result('errors').eq(0),
                                true, // not relevant value
                                r.error(result('errors'))
                      Severity: Major
                      Found in lib/query.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                  return new Query(model, this, {},
                                      new Errors.ThinkAgainError('The primary key or the joined key must be defined in the joined document for a `hasAndBelongsToMany` relation.')
                                  );
                        Severity: Major
                        Found in lib/query.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                    return this._convertGroupedData(result);
                          Severity: Major
                          Found in lib/query.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                    return result;
                            Severity: Major
                            Found in lib/query.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    return query;
                              Severity: Major
                              Found in lib/query.js - About 30 mins to fix

                                TODO found
                                Open

                                  //TODO Support an array of joinedDocuments?
                                Severity: Minor
                                Found in lib/query.js by fixme

                                TODO found
                                Open

                                      // TODO: Do not hardcode this?
                                Severity: Minor
                                Found in lib/query.js by fixme

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

                                              && (joins[field].leftKey === joins[field].rightKey)) {
                                            query = this._query(joins[field].leftKey).do(leftKey => {
                                              return joinedModel.get(joinedDocument[joinedModel._pk]).bracket(joins[field].rightKey).do(rightKey => {
                                                if (model.getTableName() < joinedModel.getTableName()) {
                                                  return linkModel.getAll(leftKey.add('_').add(rightKey)).delete()._query;
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 day to fix
                                lib/query.js on lines 645..661

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

                                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 {
                                            query = this._query(joins[field].leftKey).do(leftKey => {
                                              return joinedModel.get(joinedDocument[joinedModel._pk]).bracket(joins[field].rightKey).do(rightKey => {
                                                if (model.getTableName() < joinedModel.getTableName()) {
                                                  return linkModel.getAll(leftKey.add('_').add(rightKey)).delete()._query;
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 day to fix
                                lib/query.js on lines 629..645

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

                                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 (model.getTableName() < joinedModel.getTableName()) {
                                              return r.object(
                                                'id', leftKey.add('_').add(rightKey),
                                                model.getTableName() + '_' + joins[field].leftKey, leftKey,
                                                joinedModel.getTableName() + '_' + joins[field].rightKey, rightKey
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 2 hrs to fix
                                lib/query.js on lines 522..528

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

                                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 (model.getTableName() > joinedModel.getTableName()) {
                                              return r.object(
                                                'id', rightKey.add('_').add(leftKey),
                                                model.getTableName() + '_' + joins[field].leftKey, leftKey,
                                                joinedModel.getTableName() + '_' + joins[field].rightKey, rightKey
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 2 hrs to fix
                                lib/query.js on lines 516..528

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

                                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

                                        query = joinedModel
                                          .getAll(this._query(joins[field].leftKey), { index: joins[field].rightKey })
                                          .replace(row => row.without(joins[field].rightKey));
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 577..579

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

                                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

                                      query = joinedModel
                                        .getAll(this._query(joins[field].leftKey), { index: joins[field].rightKey })
                                        .replace(row => row.without(joins[field].rightKey));
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 587..589

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

                                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

                                              return r.branch(
                                                doc.hasFields(joins[key].leftKey),
                                                r.object(key, new Query(joins[key].model, innerQuery).getJoin(modelToGet[key], getAll, gotModel)._query),
                                                {}
                                              );
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 416..421

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

                                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

                                            return r.branch(
                                              doc.hasFields(joins[key].leftKey),
                                              r.object(key,
                                                new Query(joins[key].model, innerQuery).getJoin(modelToGet[key], getAll, gotModel)._query),
                                              {}
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 396..400

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

                                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

                                  bindExecute() {
                                    let curriedArgs = Array.prototype.slice.call(arguments);
                                    return Function.prototype.bind.apply(this.execute, [this].concat(curriedArgs));
                                  }
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 100..103

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

                                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

                                  bindRun() {
                                    let curriedArgs = Array.prototype.slice.call(arguments);
                                    return Function.prototype.bind.apply(this.run, [this].concat(curriedArgs));
                                  }
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 111..114

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

                                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

                                  run(options, callback) {
                                    if (typeof options === 'function') {
                                      callback = options;
                                      options = {};
                                    }
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 86..92

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

                                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

                                  execute(options, callback) {
                                    if (typeof options === 'function') {
                                      callback = options;
                                      options = {};
                                    }
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 71..77

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

                                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

                                                        r.table(joins[key].model.getTableName())
                                                      .getAll(doc(joins[key].leftKey), {index: joins[key].rightKey}));
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 324..325

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

                                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

                                                r.table(joins[key].model.getTableName())
                                                  .getAll(doc(joins[key].leftKey), {index: joins[key].rightKey}).coerceTo('ARRAY')
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 351..352

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

                                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

                                            r.object(
                                              'id', leftKey.add('_').add(rightKey),
                                              joins[field].leftKey + '_' + joins[field].leftKey, [leftKey, rightKey]
                                            )
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 504..507

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

                                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

                                            r.object(
                                              'id', rightKey.add('_').add(leftKey),
                                              joins[field].leftKey + '_' + joins[field].leftKey, [leftKey, rightKey]
                                            ),
                                Severity: Major
                                Found in lib/query.js and 1 other location - About 1 hr to fix
                                lib/query.js on lines 508..511

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

                                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

                                                    if ((modelToGet[key] != null) && (typeof modelToGet[key]._apply === 'function')) { // eslint-disable-line
                                                      innerQuery = modelToGet[key]._apply(innerQuery);
                                                    }
                                Severity: Major
                                Found in lib/query.js and 3 other locations - About 55 mins to fix
                                lib/query.js on lines 354..356
                                lib/query.js on lines 388..390
                                lib/query.js on lines 408..410

                                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

                                    Query.prototype._get = function() {
                                      // Create a new query to let people fork it
                                      return new Query(this._model, this._query[key]
                                        .apply(this._query, arguments));
                                    };
                                Severity: Minor
                                Found in lib/query.js and 1 other location - About 55 mins to fix
                                lib/query.js on lines 786..790

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

                                            if ((modelToGet[key] != null) && (typeof modelToGet[key]._apply === 'function')) { // eslint-disable-line
                                              innerQuery = modelToGet[key]._apply(innerQuery);
                                            }
                                Severity: Major
                                Found in lib/query.js and 3 other locations - About 55 mins to fix
                                lib/query.js on lines 329..331
                                lib/query.js on lines 354..356
                                lib/query.js on lines 388..390

                                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

                                    Query.prototype[key] = function() {
                                      // Create a new query to let people fork it
                                      return new Query(this._model, this._query[key]
                                        .apply(this._query, arguments));
                                    };
                                Severity: Minor
                                Found in lib/query.js and 1 other location - About 55 mins to fix
                                lib/query.js on lines 730..734

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

                                              if ((modelToGet[key] != null) && (typeof modelToGet[key]._apply === 'function')) { // eslint-disable-line
                                                innerQuery = modelToGet[key]._apply(innerQuery);
                                              }
                                Severity: Major
                                Found in lib/query.js and 3 other locations - About 55 mins to fix
                                lib/query.js on lines 329..331
                                lib/query.js on lines 354..356
                                lib/query.js on lines 408..410

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

                                            if ((modelToGet[key] != null) && (typeof modelToGet[key]._apply === 'function')) { // eslint-disable-line
                                              innerQuery = modelToGet[key]._apply(innerQuery);
                                            }
                                Severity: Major
                                Found in lib/query.js and 3 other locations - About 55 mins to fix
                                lib/query.js on lines 329..331
                                lib/query.js on lines 388..390
                                lib/query.js on lines 408..410

                                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 ((model.getTableName() === joins[key].model.getTableName()) && (joins[key].leftKey === joins[key].rightKey)) {
                                              // In case the model is linked with itself on the same key
                                
                                              innerQuery = r.table(joins[key].link)
                                                .getAll(doc(joins[key].leftKey), {index: joins[key].leftKey + '_' + joins[key].leftKey})
                                Severity: Minor
                                Found in lib/query.js and 1 other location - About 50 mins to fix
                                lib/document.js on lines 741..767

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

                                            if ((modelToGet[key] == null) || (modelToGet[key]._array !== false)) { // eslint-disable-line
                                              innerQuery = innerQuery.coerceTo('ARRAY');
                                            }
                                Severity: Minor
                                Found in lib/query.js and 2 other locations - About 40 mins to fix
                                lib/query.js on lines 358..360
                                lib/query.js on lines 392..394

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

                                            if ((modelToGet[key] == null) || (modelToGet[key]._array !== false)) { // eslint-disable-line
                                              innerQuery = innerQuery.coerceTo('ARRAY');
                                            }
                                Severity: Minor
                                Found in lib/query.js and 2 other locations - About 40 mins to fix
                                lib/query.js on lines 392..394
                                lib/query.js on lines 412..414

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

                                              if ((modelToGet[key] == null) || (modelToGet[key]._array !== false)) { // eslint-disable-line
                                                innerQuery = innerQuery.coerceTo('ARRAY');
                                              }
                                Severity: Minor
                                Found in lib/query.js and 2 other locations - About 40 mins to fix
                                lib/query.js on lines 358..360
                                lib/query.js on lines 412..414

                                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