balderdashy/waterline

View on GitHub
lib/waterline/utils/query/forge-stage-three-query.js

Summary

Maintainability
F
1 wk
Test Coverage

Function forgeStageThreeQuery has 380 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function forgeStageThreeQuery(options) {
  //  ╦  ╦╔═╗╦  ╦╔╦╗╔═╗╔╦╗╔═╗  ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
  //  ╚╗╔╝╠═╣║  ║ ║║╠═╣ ║ ║╣   │ │├─┘ │ ││ ││││└─┐
  //   ╚╝ ╩ ╩╩═╝╩═╩╝╩ ╩ ╩ ╚═╝  └─┘┴   ┴ ┴└─┘┘└┘└─┘
  if (!_.has(options, 'stageTwoQuery') || !_.isPlainObject(options.stageTwoQuery)) {
Severity: Major
Found in lib/waterline/utils/query/forge-stage-three-query.js - About 1 day to fix

    Function forgeStageThreeQuery has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = function forgeStageThreeQuery(options) {
      //  ╦  ╦╔═╗╦  ╦╔╦╗╔═╗╔╦╗╔═╗  ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
      //  ╚╗╔╝╠═╣║  ║ ║║╠═╣ ║ ║╣   │ │├─┘ │ ││ ││││└─┐
      //   ╚╝ ╩ ╩╩═╝╩═╩╝╩ ╩ ╩ ╚═╝  └─┘┴   ┴ ┴└─┘┘└┘└─┘
      if (!_.has(options, 'stageTwoQuery') || !_.isPlainObject(options.stageTwoQuery)) {
    Severity: Minor
    Found in lib/waterline/utils/query/forge-stage-three-query.js - About 1 day 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 forge-stage-three-query.js has 385 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /**
     * Module dependencies
     */
    
    var util = require('util');
    Severity: Minor
    Found in lib/waterline/utils/query/forge-stage-three-query.js - About 5 hrs to fix

      Consider simplifying this complex logical expression.
      Open

        if (s3Q.method === 'find' || s3Q.method === 'findOne') {
          s3Q.method = 'find';
      
          //  ╔╗ ╦ ╦╦╦  ╔╦╗   ┬┌─┐┬┌┐┌  ┬┌┐┌┌─┐┌┬┐┬─┐┬ ┬┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
          //  ╠╩╗║ ║║║   ║║   ││ │││││  ││││└─┐ │ ├┬┘│ ││   │ ││ ││││└─┐
      Severity: Major
      Found in lib/waterline/utils/query/forge-stage-three-query.js - About 40 mins to fix

        Avoid too many return statements within this function.
        Open

            return s3Q;
        Severity: Major
        Found in lib/waterline/utils/query/forge-stage-three-query.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return s3Q;
          Severity: Major
          Found in lib/waterline/utils/query/forge-stage-three-query.js - About 30 mins to fix

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

                if (!_.isUndefined(s3Q.criteria.sort) && s3Q.criteria.sort.length) {
                  s3Q.criteria.sort = _.map(s3Q.criteria.sort, function(sortClause) {
                    var comparatorTarget = _.first(_.keys(sortClause));
                    var attrName = _.first(comparatorTarget.split(/\./));
                    var sortDirection = sortClause[comparatorTarget];
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 1 other location - About 1 day to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 253..264

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

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

                if (!_.isUndefined(s3Q.criteria.sort) && s3Q.criteria.sort.length) {
                  s3Q.criteria.sort = _.map(s3Q.criteria.sort, function(sortClause) {
                    var comparatorTarget = _.first(_.keys(sortClause));
                    var attrName = _.first(comparatorTarget.split(/\./));
                    var sortDirection = sortClause[comparatorTarget];
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 1 other location - About 1 day to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 199..210

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

            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

                    _.each(originalModels[parentAttr.referenceIdentity].schema, function(val, key) {
                      // Ignore virtual attributes
                      if(_.has(val, 'collection')) {
                        return;
                      }
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 1 other location - About 3 hrs to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 424..437

            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

                      _.each(originalModels[reference.referenceIdentity].schema, function(val, key) {
                        // Ignore virtual attributes
                        if(_.has(val, 'collection')) {
                          return;
                        }
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 1 other location - About 3 hrs to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 361..374

            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

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

                try {
                  s3Q.criteria.where = transformer.serializeCriteria(s3Q.criteria.where);
                } catch (e) {
                  throw flaverr('E_INVALID_RECORD', new Error(
                    'Failed process the criteria for the record.\n'+
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 1 other location - About 2 hrs to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 237..245

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

            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

                try {
                  s3Q.criteria.where = transformer.serializeCriteria(s3Q.criteria.where);
                } catch (e) {
                  throw flaverr('E_INVALID_RECORD', new Error(
                    'Failed process the criteria for the record.\n'+
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 1 other location - About 2 hrs to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 183..191

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

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

                if (!_.has(s3Q, 'valuesToSet') || !_.isPlainObject(s3Q.valuesToSet)) {
                  throw flaverr('E_INVALID_RECORD', new Error(
                    'Failed process the values set for the record.'
                  ));
                }
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 4 other locations - About 50 mins to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 124..128
            lib/waterline/utils/query/forge-stage-three-query.js on lines 165..169
            lib/waterline/utils/query/forge-stage-three-query.js on lines 230..234
            lib/waterline/utils/query/forge-stage-three-query.js on lines 661..665

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

                if (!_.has(s3Q, 'newRecords') || !_.isArray(s3Q.newRecords)) {
                  throw flaverr('E_INVALID_RECORDS', new Error(
                    'Failed process the values set for the record.'
                  ));
                }
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 4 other locations - About 50 mins to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 158..162
            lib/waterline/utils/query/forge-stage-three-query.js on lines 165..169
            lib/waterline/utils/query/forge-stage-three-query.js on lines 230..234
            lib/waterline/utils/query/forge-stage-three-query.js on lines 661..665

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

                if (!_.has(s3Q, 'criteria') || !_.isPlainObject(s3Q.criteria)) {
                  throw flaverr('E_INVALID_RECORD', new Error(
                    'Failed process the criteria for the record.'
                  ));
                }
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 4 other locations - About 50 mins to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 124..128
            lib/waterline/utils/query/forge-stage-three-query.js on lines 158..162
            lib/waterline/utils/query/forge-stage-three-query.js on lines 230..234
            lib/waterline/utils/query/forge-stage-three-query.js on lines 661..665

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

                if (!_.has(s3Q, 'criteria') || !_.isPlainObject(s3Q.criteria)) {
                  throw flaverr('E_INVALID_RECORD', new Error(
                    'Failed process the criteria for the record.'
                  ));
                }
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 4 other locations - About 50 mins to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 124..128
            lib/waterline/utils/query/forge-stage-three-query.js on lines 158..162
            lib/waterline/utils/query/forge-stage-three-query.js on lines 165..169
            lib/waterline/utils/query/forge-stage-three-query.js on lines 661..665

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

                if (!_.has(s3Q, 'criteria') || !_.isPlainObject(s3Q.criteria)) {
                  throw flaverr('E_INVALID_RECORD', new Error(
                    'Failed process the criteria for the record.'
                  ));
                }
            Severity: Major
            Found in lib/waterline/utils/query/forge-stage-three-query.js and 4 other locations - About 50 mins to fix
            lib/waterline/utils/query/forge-stage-three-query.js on lines 124..128
            lib/waterline/utils/query/forge-stage-three-query.js on lines 158..162
            lib/waterline/utils/query/forge-stage-three-query.js on lines 165..169
            lib/waterline/utils/query/forge-stage-three-query.js on lines 230..234

            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

            There are no issues that match your filters.

            Category
            Status