ruhley/angular-color-picker

View on GitHub
src/scripts/controller.js

Summary

Maintainability
F
5 days
Test Coverage

File controller.js has 829 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import tinycolor from 'tinycolor2';

export default class AngularColorPickerController {
    constructor(_$scope, _$element, _$document, _$timeout, _ColorPickerOptions) {
        // set angular injected variables
Severity: Major
Found in src/scripts/controller.js - About 1 day to fix

    AngularColorPickerController has 57 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class AngularColorPickerController {
        constructor(_$scope, _$element, _$document, _$timeout, _ColorPickerOptions) {
            // set angular injected variables
            this.$scope = _$scope;
            this.$element = _$element;
    Severity: Major
    Found in src/scripts/controller.js - About 1 day to fix

      Function initWatchers has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          initWatchers() {
      
              // ngModel
      
              this.$scope.$watch('AngularColorPickerController.internalNgModel', this.watchInternalNgModel.bind(this));
      Severity: Major
      Found in src/scripts/controller.js - About 2 hrs to fix

        Function initMouseEvents has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            initMouseEvents() {
                const eventHandlers = {
                    mouseDown: this.onMouseDown.bind(this),
                    mouseUp: this.onMouseUp.bind(this),
                    mouseMove: this.onMouseMove.bind(this),
        Severity: Major
        Found in src/scripts/controller.js - About 2 hrs to fix

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

              setupApi() {
                  if (!this.api) {
                      this.api = {};
                  }
          
          
          Severity: Minor
          Found in src/scripts/controller.js - About 1 hr to fix

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

                update() {
                    if (!this.areAllValuesSet()) {
                        return false;
                    }
            
            
            Severity: Minor
            Found in src/scripts/controller.js - About 1 hr to fix

              Function setupApi has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  setupApi() {
                      if (!this.api) {
                          this.api = {};
                      }
              
              
              Severity: Minor
              Found in src/scripts/controller.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 getColorValue has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  getColorValue(dynamicValues = true, includeOpacity = true) {
                      let value = {
                          h: this.hue,
                          s: dynamicValues ? `${this.saturation}%` : '100%',
                          v: dynamicValues ? `${this.lightness}%`: '100%'
              Severity: Minor
              Found in src/scripts/controller.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 checkDirty has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  checkDirty(color) {
                      // check dirty/pristine state
                      if (this.hasOwnProperty('initialNgModel')) {
                          if (color === this.initialNgModel) {
                              if (typeof this.$scope.control[0].$setPristine === 'function') {
              Severity: Minor
              Found in src/scripts/controller.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 offset has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  offset(el) {
                      var docElem, win, rect, doc, elem = el[0];
              
                      if (!elem) {
                          return;
              Severity: Minor
              Found in src/scripts/controller.js - About 1 hr to fix

                Function updateHueBackground has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    updateHueBackground(color) {
                        var el = this.find('.color-picker-hue .color-picker-overlay');
                        var direction = this.options.horizontal ? 'left' : 'top';
                
                        var zero_sixths = this.getColorValue(this.options.dynamicHue);
                Severity: Minor
                Found in src/scripts/controller.js - About 1 hr to fix

                  Function valueUpdate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      valueUpdate(type) {
                          if (this[type] !== undefined) {
                              if (type === 'saturation') {
                                  this[`${type}Pos`] = this[type];
                              } else {
                  Severity: Minor
                  Found in src/scripts/controller.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 setColorValue has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      setColorValue(color) {
                          let noMouseEvents = !this.anyMouseEvents();
                          let hsl = this.options.round ? color.toHsl() : color.toHsv();
                  
                          if (noMouseEvents || this.hueMouse) {
                  Severity: Minor
                  Found in src/scripts/controller.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 mergeOptions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      mergeOptions(options, defaultOptions) {
                          for (var attr in defaultOptions) {
                              if (defaultOptions.hasOwnProperty(attr)) {
                                  if (!options || !options.hasOwnProperty(attr)) {
                                      options[attr] = defaultOptions[attr];
                  Severity: Minor
                  Found in src/scripts/controller.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 update has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      update() {
                          if (!this.areAllValuesSet()) {
                              return false;
                          }
                  
                  
                  Severity: Minor
                  Found in src/scripts/controller.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 find has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      find(selector) {
                          var context = this.wrapper ? this.wrapper[0] : this.$element[0],
                              results = [],
                              nodeType;
                  
                  
                  Severity: Minor
                  Found in src/scripts/controller.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 watchNgModelSet has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      watchNgModelSet(newValue) {
                          if (newValue !== undefined && newValue !== null) {
                              var color = tinycolor(newValue);
                              var isValid = this.isColorValid(color);
                  
                  
                  Severity: Minor
                  Found in src/scripts/controller.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 offset has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      offset(el) {
                          var docElem, win, rect, doc, elem = el[0];
                  
                          if (!elem) {
                              return;
                  Severity: Minor
                  Found in src/scripts/controller.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 onMouseUp has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      onMouseUp(event) {
                          // no current mouse events and not an element in the picker
                          if (!this.anyMouseEvents() && this.find(event.target).length === 0) {
                              this.setupApi();
                              if (this.options.hide.click) {
                  Severity: Minor
                  Found in src/scripts/controller.js - About 35 mins to fix

                  Cognitive Complexity

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

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

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

                  Further reading

                  Avoid too many return statements within this function.
                  Open

                          return rect;
                  Severity: Major
                  Found in src/scripts/controller.js - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status