adammcarth/instance.js

View on GitHub

Showing 17 of 17 total issues

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

function validates_instance_alphanumeric( type, attr ) {
    if ( /^[a-zA-Z0-9 ]+$/g.test(attr) !== true ) {
        var alphanumeric = false;
    } else {
        var alphanumeric = true;
Severity: Major
Found in lib/validations/methods.js and 4 other locations - About 3 hrs to fix
lib/validations/methods.js on lines 50..64
lib/validations/methods.js on lines 67..81
lib/validations/methods.js on lines 101..115
lib/validations/methods.js on lines 162..176

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

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

function validates_instance_alphabetic( type, attr ) {
    if ( /^[a-zA-Z ]*$/g.test(attr) !== true ) {
        var alphabetic = false;
    } else {
        var alphabetic = true;
Severity: Major
Found in lib/validations/methods.js and 4 other locations - About 3 hrs to fix
lib/validations/methods.js on lines 50..64
lib/validations/methods.js on lines 84..98
lib/validations/methods.js on lines 101..115
lib/validations/methods.js on lines 162..176

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

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

function validates_instance_spaces( type, attr ) {
    if ( /( )/g.test(attr) !== true ) {
        var spaces = false;
    } else {
        var spaces = true;
Severity: Major
Found in lib/validations/methods.js and 4 other locations - About 3 hrs to fix
lib/validations/methods.js on lines 50..64
lib/validations/methods.js on lines 67..81
lib/validations/methods.js on lines 84..98
lib/validations/methods.js on lines 162..176

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

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

function validates_instance_numeric( type, attr ) {
    if ( /^[0-9. ]*$/g.test(attr) !== true ) {
        var numeric = false;
    } else {
        var numeric = true;
Severity: Major
Found in lib/validations/methods.js and 4 other locations - About 3 hrs to fix
lib/validations/methods.js on lines 67..81
lib/validations/methods.js on lines 84..98
lib/validations/methods.js on lines 101..115
lib/validations/methods.js on lines 162..176

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

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

function validates_instance_email( type, attr ) {
    if ( /\S+@\S+\.\S+/.test(attr) !== true ) {
        var email = false;
    } else {
        var email = true;
Severity: Major
Found in lib/validations/methods.js and 4 other locations - About 3 hrs to fix
lib/validations/methods.js on lines 50..64
lib/validations/methods.js on lines 67..81
lib/validations/methods.js on lines 84..98
lib/validations/methods.js on lines 101..115

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

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

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

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

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

Refactorings

Further Reading

Function validate has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

Instance.prototype.validate = function() {
    var validations = this.validations;
    var validation_callback_queue = [];

    if ( validations ) {
Severity: Minor
Found in lib/validations/validate.js - About 3 hrs to fix

Cognitive Complexity

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

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

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

Further reading

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

Instance.prototype.validate = function() {
    var validations = this.validations;
    var validation_callback_queue = [];

    if ( validations ) {
Severity: Major
Found in lib/validations/validate.js - About 2 hrs to fix

    Function send has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Instance.prototype.send = function( url, method, validation ) {
        if ( validation !== false ) {
            // Validate the model
            if ( this.validate() === false ) {
                // Woah. No way we're sending this off.
    Severity: Major
    Found in lib/send.js - About 2 hrs to fix

      Function send has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      Instance.prototype.send = function( url, method, validation ) {
          if ( validation !== false ) {
              // Validate the model
              if ( this.validate() === false ) {
                  // Woah. No way we're sending this off.
      Severity: Minor
      Found in lib/send.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

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

      Instance.prototype.addElement = function( ids ) {
          // Convert `ids` to an array if it is a string
          ids = this.ensureArray( ids );
      
          // Add the element id's to the instance's elements variable, and
      Severity: Major
      Found in lib/add.js and 1 other location - About 1 hr to fix
      lib/add.js on lines 27..34

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

      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

      Instance.prototype.addField = function( names ) {
          // Convert `names` to an array if it is a string
          names = this.ensureArray( names );
      
          // Add the field names to the instance's fields variable, and
      Severity: Major
      Found in lib/add.js and 1 other location - About 1 hr to fix
      lib/add.js on lines 43..50

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

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

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

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

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

      Refactorings

      Further Reading

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

      module.exports = function (grunt) {
          grunt.initConfig({
      
              pkg: grunt.file.readJSON("package.json"),
      
      
      Severity: Minor
      Found in Gruntfile.js - About 1 hr to fix

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

        Instance.prototype.get = function( attr ) {
            var input,
                element;
        
            // Add the latest values of any HTML INPUT FIELDS specified
        Severity: Minor
        Found in lib/get.js - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                                      if ( pass_callback ) { validation_callback_queue.push( pass_callback ); }
          Severity: Major
          Found in lib/validations/validate.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                        if ( fail_callback ) { validation_callback_queue.push( fail_callback ); }
            Severity: Major
            Found in lib/validations/validate.js - About 45 mins to fix

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

              function validates_instance_url( url, attr ) {
                  var xhr = new XMLHttpRequest();
                  xhr.open( "GET", url + "?value=" + encodeURIComponent(attr), true );
                  xhr.setRequestHeader( "Instance-Validation", attr );
                  xhr.onreadystatechange = function() {
              Severity: Minor
              Found in lib/validations/methods.js - About 35 mins to fix

              Cognitive Complexity

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

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

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

              Further reading

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

              function validates_instance_presence( type, attr ) {
                  if ( attr === undefined || attr === null || attr === "" || attr === 0 || attr === "0" ) {
                      var presence = false;
                  } else {
                      var presence = true;
              Severity: Minor
              Found in lib/validations/methods.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

              Severity
              Category
              Status
              Source
              Language