felipero/couchrails

View on GitHub
examples/helloworld/public/javascripts/controls.js

Summary

Maintainability
F
5 days
Test Coverage

File controls.js has 804 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// script.aculo.us controls.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009

// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
//           (c) 2005-2009 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
//           (c) 2005-2009 Jon Tirsen (http://www.tirsen.com)
Severity: Major
Found in examples/helloworld/public/javascripts/controls.js - About 1 day to fix

    Function setOptions has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

      setOptions: function(options) {
        this.options = Object.extend({
          choices: 10,
          partialSearch: true,
          partialChars: 2,
    Severity: Minor
    Found in examples/helloworld/public/javascripts/controls.js - About 4 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

    InPlaceEditor has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    Ajax.InPlaceEditor = Class.create({
      initialize: function(element, url, options) {
        this.url = url;
        this.element = element = $(element);
        this.prepareOptions();
    Severity: Minor
    Found in examples/helloworld/public/javascripts/controls.js - About 2 hrs to fix

      Base has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      Autocompleter.Base = Class.create({
        baseInitialize: function(element, update, options) {
          element          = $(element);
          this.element     = element;
          this.update      = $(update);
      Severity: Minor
      Found in examples/helloworld/public/javascripts/controls.js - About 2 hrs to fix

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

        Ajax.InPlaceEditor.prototype.initialize.dealWithDeprecatedOptions = function(options) {
          if (!options) return;
          function fallback(name, expr) {
            if (name in options || expr === undefined) return;
            options[name] = expr;
        Severity: Minor
        Found in examples/helloworld/public/javascripts/controls.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 setOptions has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          setOptions: function(options) {
            this.options = Object.extend({
              choices: 10,
              partialSearch: true,
              partialChars: 2,
        Severity: Minor
        Found in examples/helloworld/public/javascripts/controls.js - About 1 hr to fix

          Function baseInitialize has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            baseInitialize: function(element, update, options) {
              element          = $(element);
              this.element     = element;
              this.update      = $(update);
              this.hasFocus    = false;
          Severity: Minor
          Found in examples/helloworld/public/javascripts/controls.js - About 1 hr to fix

            Function onKeyPress has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              onKeyPress: function(event) {
                if(this.active)
                  switch(event.keyCode) {
                   case Event.KEY_TAB:
                   case Event.KEY_RETURN:
            Severity: Minor
            Found in examples/helloworld/public/javascripts/controls.js - About 1 hr to fix

              Function selector has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    selector: function(instance) {
                      var ret       = []; // Beginning matches
                      var partial   = []; // Inside matches
                      var entry     = instance.getToken();
                      var count     = 0;
              Severity: Minor
              Found in examples/helloworld/public/javascripts/controls.js - About 1 hr to fix

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

                  createEditField: function() {
                    var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
                    var fld;
                    if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {
                      fld = document.createElement('input');
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.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 updateChoices has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                  updateChoices: function(choices) {
                    if(!this.changed && this.hasFocus) {
                      this.update.innerHTML = choices;
                      Element.cleanWhitespace(this.update);
                      Element.cleanWhitespace(this.update.down());
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.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 updateElement has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  updateElement: function(selectedElement) {
                    if (this.options.updateElement) {
                      this.options.updateElement(selectedElement);
                      return;
                    }
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.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 render has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  render: function() {
                    if(this.entryCount > 0) {
                      for (var i = 0; i < this.entryCount; i++)
                        this.index==i ?
                          Element.addClassName(this.getEntry(i),"selected") :
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.js - About 55 mins to fix

                Cognitive Complexity

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

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

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

                Further reading

                Function createControl has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  createControl: function(mode, handler, extraClasses) {
                    var control = this.options[mode + 'Control'];
                    var text = this.options[mode + 'Text'];
                    if ('button' == control) {
                      var btn = document.createElement('input');
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.js - About 45 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 getTokenBounds has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  getTokenBounds: function() {
                    if (null != this.tokenBounds) return this.tokenBounds;
                    var value = this.element.value;
                    if (value.strip().empty()) return [-1, 0];
                    var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.js - About 45 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 onKeyPress has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  onKeyPress: function(event) {
                    if(this.active)
                      switch(event.keyCode) {
                       case Event.KEY_TAB:
                       case Event.KEY_RETURN:
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.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 baseInitialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  baseInitialize: function(element, update, options) {
                    element          = $(element);
                    this.element     = element;
                    this.update      = $(update);
                    this.hasFocus    = false;
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.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 initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  initialize: function(element, url, options) {
                    this.url = url;
                    this.element = element = $(element);
                    this.prepareOptions();
                    this._controls = { };
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.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 createForm has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  createForm: function() {
                    var ipe = this;
                    function addText(mode, condition) {
                      var text = ipe.options['text' + mode + 'Controls'];
                      if (!text || condition === false) return;
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.js - About 25 mins to fix

                Cognitive Complexity

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

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

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

                Further reading

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

                  enterHover: function(e) {
                    if (this.options.hoverClassName)
                      this.element.addClassName(this.options.hoverClassName);
                    if (this._saving) return;
                    this.triggerCallback('onEnterHover');
                Severity: Major
                Found in examples/helloworld/public/javascripts/controls.js and 1 other location - About 1 hr to fix
                examples/helloworld/public/javascripts/controls.js on lines 662..667

                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

                  leaveHover: function(e) {
                    if (this.options.hoverClassName)
                      this.element.removeClassName(this.options.hoverClassName);
                    if (this._saving) return;
                    this.triggerCallback('onLeaveHover');
                Severity: Major
                Found in examples/helloworld/public/javascripts/controls.js and 1 other location - About 1 hr to fix
                examples/helloworld/public/javascripts/controls.js on lines 602..607

                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

                  fallback('cancelControl', (options.cancelLink ? 'link' : (options.cancelButton ? 'button' :
                    options.cancelLink == options.cancelButton == false ? false : undefined)));
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.js and 1 other location - About 45 mins to fix
                examples/helloworld/public/javascripts/controls.js on lines 865..866

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

                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

                  fallback('okControl', (options.okLink ? 'link' : (options.okButton ? 'button' :
                    options.okLink == options.okButton == false ? false : undefined)));
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.js and 1 other location - About 45 mins to fix
                examples/helloworld/public/javascripts/controls.js on lines 863..864

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

                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(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.js and 1 other location - About 30 mins to fix
                examples/helloworld/public/javascripts/controls.js on lines 117..117

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

                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(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
                Severity: Minor
                Found in examples/helloworld/public/javascripts/controls.js and 1 other location - About 30 mins to fix
                examples/helloworld/public/javascripts/controls.js on lines 95..95

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

                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