lebretr/sequelize-oracle

View on GitHub
lib/associations/has-many.js

Summary

Maintainability
F
6 days
Test Coverage

Function exports has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = (function() {
  var HasMany = function(source, target, options) {
    var self = this

    this.associationType = 'HasMany'
Severity: Minor
Found in lib/associations/has-many.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

Function exports has 297 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = (function() {
  var HasMany = function(source, target, options) {
    var self = this

    this.associationType = 'HasMany'
Severity: Major
Found in lib/associations/has-many.js - About 1 day to fix

    File has-many.js has 306 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    var Utils      = require("./../utils")
      , DataTypes  = require('./../data-types')
      , Helpers    = require('./helpers')
      , _          = require('lodash')
      , Transaction = require('../transaction')
    Severity: Minor
    Found in lib/associations/has-many.js - About 3 hrs to fix

      Function HasMany has 83 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        var HasMany = function(source, target, options) {
          var self = this
      
          this.associationType = 'HasMany'
          this.source = source
      Severity: Major
      Found in lib/associations/has-many.js - About 3 hrs to fix

        Function injectSetter has 80 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          HasMany.prototype.injectSetter = function(obj) {
            var self = this
        
            obj[this.accessors.set] = function(newAssociatedObjects, defaultAttributes) {
              if (newAssociatedObjects === null) {
        Severity: Major
        Found in lib/associations/has-many.js - About 3 hrs to fix

          Function injectAttributes has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            HasMany.prototype.injectAttributes = function() {
              var doubleLinked      = this.doubleLinked
                , self              = this
                , primaryKeyDeleted = false
          
          
          Severity: Major
          Found in lib/associations/has-many.js - About 2 hrs to fix

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

              HasMany.prototype.injectGetter = function(obj) {
                var self = this
            
                obj[this.accessors.get] = function(options) {
                  var Class = Object(self.through) === self.through ? HasManyDoubleLinked : HasManySingleLinked
            Severity: Minor
            Found in lib/associations/has-many.js - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                  if ((this.isSelfAssociation && Object(this.through) === this.through) || doubleLinked) {
                    // remove the obsolete association identifier from the source
                    if (this.isSelfAssociation) {
                      this.foreignIdentifier = Utils._.underscoredIf((this.options.as || this.target.tableName) + 'Id', this.options.underscored)
                    } else {
              Severity: Major
              Found in lib/associations/has-many.js - About 1 hr to fix

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

                      var newAttributes = {}
                        , sourceKeys = Object.keys(this.source.primaryKeys)
                        , keyType = ((this.source.hasPrimaryKeys && sourceKeys.length === 1) ? this.source.rawAttributes[sourceKeys[0]].type : DataTypes.INTEGER)
                Severity: Major
                Found in lib/associations/has-many.js and 2 other locations - About 2 hrs to fix
                lib/associations/belongs-to.js on lines 45..47
                lib/associations/has-one.js on lines 41..43

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

                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

                    this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.source.tableName, this.source.options.language) + "Id", this.options.underscored)
                Severity: Major
                Found in lib/associations/has-many.js and 1 other location - About 2 hrs to fix
                lib/associations/has-one.js on lines 45..45

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 76.

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

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

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

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

                Refactorings

                Further Reading

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

                                return Utils._.any(associatedObjects, function(associatedObject) {
                                  return Utils._.all(associatedObject.identifiers, function(key, identifier) {
                                    return o[identifier] == associatedObject[identifier];
                                  });
                                })
                Severity: Major
                Found in lib/associations/has-many.js and 1 other location - About 1 hr to fix
                lib/associations/has-many.js on lines 243..247

                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

                            Utils._.any(associatedObjects, function(associatedObject) {
                              return Utils._.all(associatedObject.identifiers, function(key, identifier) {
                                return o[identifier] == associatedObject[identifier];
                              });
                            })
                Severity: Major
                Found in lib/associations/has-many.js and 1 other location - About 1 hr to fix
                lib/associations/has-many.js on lines 224..228

                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

                      var targetKeyType = ((!this.target.hasPrimaryKeys || targetKeys.length !== 1) ? DataTypes.INTEGER : this.target.rawAttributes[targetKeys[0]].type)
                Severity: Major
                Found in lib/associations/has-many.js and 1 other location - About 1 hr to fix
                lib/associations/has-many.js on lines 172..172

                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

                      var sourceKeyType = ((!this.source.hasPrimaryKeys || sourceKeys.length !== 1) ? DataTypes.INTEGER : this.source.rawAttributes[sourceKeys[0]].type)
                Severity: Major
                Found in lib/associations/has-many.js and 1 other location - About 1 hr to fix
                lib/associations/has-many.js on lines 174..174

                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

                        instance[self.accessors.get](options)
                          .error(function(err) { customEventEmitter.emit('error', err) })
                          .success(function(associatedObjects) {
                            customEventEmitter.emit('success',
                              Utils._.all(objects, function(o) {
                Severity: Minor
                Found in lib/associations/has-many.js and 1 other location - About 40 mins to fix
                lib/associations/has-many.js on lines 239..249

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 48.

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

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

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

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

                Refactorings

                Further Reading

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

                        instance[self.accessors.get](options)
                        .error(function(err){ customEventEmitter.emit('error', err)})
                        .success(function(associatedObjects) {
                          customEventEmitter.emit('success',
                            Utils._.any(associatedObjects, function(associatedObject) {
                Severity: Minor
                Found in lib/associations/has-many.js and 1 other location - About 40 mins to fix
                lib/associations/has-many.js on lines 219..231

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

                      hasSingle: Utils._.camelize(Utils.singularize('has_' + this.as, this.target.options.language)),
                Severity: Major
                Found in lib/associations/has-many.js and 3 other locations - About 35 mins to fix
                lib/associations/has-many.js on lines 125..125
                lib/associations/has-many.js on lines 126..126
                lib/associations/has-many.js on lines 127..127

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

                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

                      create: Utils._.camelize(Utils.singularize('create_' + this.as, this.target.options.language)),
                Severity: Major
                Found in lib/associations/has-many.js and 3 other locations - About 35 mins to fix
                lib/associations/has-many.js on lines 125..125
                lib/associations/has-many.js on lines 127..127
                lib/associations/has-many.js on lines 128..128

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

                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

                      remove: Utils._.camelize(Utils.singularize('remove_' + this.as, this.target.options.language)),
                Severity: Major
                Found in lib/associations/has-many.js and 3 other locations - About 35 mins to fix
                lib/associations/has-many.js on lines 125..125
                lib/associations/has-many.js on lines 126..126
                lib/associations/has-many.js on lines 128..128

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

                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

                      add: Utils._.camelize(Utils.singularize('add_' + this.as, this.target.options.language)),
                Severity: Major
                Found in lib/associations/has-many.js and 3 other locations - About 35 mins to fix
                lib/associations/has-many.js on lines 126..126
                lib/associations/has-many.js on lines 127..127
                lib/associations/has-many.js on lines 128..128

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

                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