woothemes/woocommerce

View on GitHub
assets/js/frontend/add-to-cart-variation.js

Summary

Maintainability
F
6 days
Test Coverage

File add-to-cart-variation.js has 582 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*global wc_add_to_cart_variation_params */
;(function ( $, window, document, undefined ) {
    /**
     * VariationForm class which handles variation forms and attributes.
     */
Severity: Major
Found in assets/js/frontend/add-to-cart-variation.js - About 1 day to fix

    Function onUpdateAttributes has 91 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        VariationForm.prototype.onUpdateAttributes = function( event ) {
            var form              = event.data.variationForm,
                attributes        = form.getChosenAttributes(),
                currentAttributes = attributes.data;
    
    
    Severity: Major
    Found in assets/js/frontend/add-to-cart-variation.js - About 3 hrs to fix

      Function onFindVariation has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          VariationForm.prototype.onFindVariation = function( event, chosenAttributes ) {
              var form              = event.data.variationForm,
                  attributes        = 'undefined' !== typeof chosenAttributes ? chosenAttributes : form.getChosenAttributes(),
                  currentAttributes = attributes.data;
      
      
      Severity: Major
      Found in assets/js/frontend/add-to-cart-variation.js - About 2 hrs to fix

        Function onFoundVariation has 63 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            VariationForm.prototype.onFoundVariation = function( event, variation ) {
                var form           = event.data.variationForm,
                    $sku           = form.$product.find( '.product_meta' ).find( '.sku' ),
                    $weight        = form.$product.find(
                        '.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value'
        Severity: Major
        Found in assets/js/frontend/add-to-cart-variation.js - About 2 hrs to fix

          Function wc_variations_image_update has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              $.fn.wc_variations_image_update = function( variation ) {
                  var $form             = this,
                      $product          = $form.closest( '.product' ),
                      $product_gallery  = $product.find( '.images' ),
                      $gallery_nav      = $product.find( '.flex-control-nav' ),
          Severity: Minor
          Found in assets/js/frontend/add-to-cart-variation.js - About 1 hr to fix

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

                var VariationForm = function( $form ) {
                    var self = this;
            
                    self.$form                = $form;
                    self.$attributeFields     = $form.find( '.variations select' );
            Severity: Minor
            Found in assets/js/frontend/add-to-cart-variation.js - About 1 hr to fix

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

                  VariationForm.prototype.onShow = function( event, variation, purchasable ) {
                      event.preventDefault();
                      if ( purchasable ) {
                          event.data.variationForm.$form
                              .find( '.single_add_to_cart_button' )
              Severity: Minor
              Found in assets/js/frontend/add-to-cart-variation.js - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                                            if ( attr_name === current_attr_name ) {
                                                if ( variations[ num ].variation_is_active ) {
                                                    variation_active = 'enabled';
                                                }
                
                
                Severity: Major
                Found in assets/js/frontend/add-to-cart-variation.js - About 45 mins to fix

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

                      VariationForm.prototype.isMatch = function( variation_attributes, attributes ) {
                          var match = true;
                          for ( var attr_name in variation_attributes ) {
                              if ( variation_attributes.hasOwnProperty( attr_name ) ) {
                                  var val1 = variation_attributes[ attr_name ];
                  Severity: Major
                  Found in assets/js/frontend/add-to-cart-variation.js and 1 other location - About 4 hrs to fix
                  assets/js/frontend/add-to-cart-variation.js on lines 763..775

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

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

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

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

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

                  Refactorings

                  Further Reading

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

                                          if ( variation ) {
                                              form.$form.trigger( 'found_variation', [ variation ] );
                                          } else {
                                              form.$form.trigger( 'reset_data' );
                                              attributes.chosenCount = 0;
                  Severity: Major
                  Found in assets/js/frontend/add-to-cart-variation.js and 1 other location - About 4 hrs to fix
                  assets/js/frontend/add-to-cart-variation.js on lines 209..225

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

                  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

                          variations_match: function( attrs1, attrs2 ) {
                              var match = true;
                              for ( var attr_name in attrs1 ) {
                                  if ( attrs1.hasOwnProperty( attr_name ) ) {
                                      var val1 = attrs1[ attr_name ];
                  Severity: Major
                  Found in assets/js/frontend/add-to-cart-variation.js and 1 other location - About 4 hrs to fix
                  assets/js/frontend/add-to-cart-variation.js on lines 545..557

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

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

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

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

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

                  Refactorings

                  Further Reading

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

                                  if ( variation ) {
                                      form.$form.trigger( 'found_variation', [ variation ] );
                                  } else {
                                      form.$form.trigger( 'reset_data' );
                                      attributes.chosenCount = 0;
                  Severity: Major
                  Found in assets/js/frontend/add-to-cart-variation.js and 1 other location - About 4 hrs to fix
                  assets/js/frontend/add-to-cart-variation.js on lines 181..197

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

                  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

                          var $form             = this,
                              $product          = $form.closest( '.product' ),
                              $product_gallery  = $product.find( '.images' ),
                              $gallery_nav      = $product.find( '.flex-control-nav' ),
                              $gallery_img      = $gallery_nav.find( 'li:eq(0) img' ),
                  Severity: Major
                  Found in assets/js/frontend/add-to-cart-variation.js and 1 other location - About 3 hrs to fix
                  assets/js/frontend/add-to-cart-variation.js on lines 710..719

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

                  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

                          var $form             = this,
                              $product          = $form.closest( '.product' ),
                              $product_gallery  = $product.find( '.images' ),
                              $gallery_nav      = $product.find( '.flex-control-nav' ),
                              $gallery_img      = $gallery_nav.find( 'li:eq(0) img' ),
                  Severity: Major
                  Found in assets/js/frontend/add-to-cart-variation.js and 1 other location - About 3 hrs to fix
                  assets/js/frontend/add-to-cart-variation.js on lines 647..656

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

                  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