woothemes/woocommerce

View on GitHub
includes/class-wc-ajax.php

Summary

Maintainability
F
3 wks
Test Coverage

File class-wc-ajax.php has 1943 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WooCommerce WC_AJAX. AJAX Event Handlers.
 *
 * @class   WC_AJAX
Severity: Major
Found in includes/class-wc-ajax.php - About 5 days to fix

    WC_AJAX has 90 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WC_AJAX {
    
        /**
         * Hook in ajax handlers.
         */
    Severity: Major
    Found in includes/class-wc-ajax.php - About 1 day to fix

      Function shipping_zone_methods_save_changes has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function shipping_zone_methods_save_changes() {
              if ( ! isset( $_POST['wc_shipping_zones_nonce'], $_POST['zone_id'], $_POST['changes'] ) ) {
                  wp_send_json_error( 'missing_fields' );
                  wp_die();
              }
      Severity: Minor
      Found in includes/class-wc-ajax.php - About 5 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 shipping_classes_save_changes has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function shipping_classes_save_changes() {
              if ( ! isset( $_POST['wc_shipping_classes_nonce'], $_POST['changes'] ) ) {
                  wp_send_json_error( 'missing_fields' );
                  wp_die();
              }
      Severity: Minor
      Found in includes/class-wc-ajax.php - 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

      Method update_order_review has 83 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function update_order_review() {
              check_ajax_referer( 'update-order-review', 'security' );
      
              wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
      
      
      Severity: Major
      Found in includes/class-wc-ajax.php - About 3 hrs to fix

        Method shipping_zone_methods_save_changes has 82 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function shipping_zone_methods_save_changes() {
                if ( ! isset( $_POST['wc_shipping_zones_nonce'], $_POST['zone_id'], $_POST['changes'] ) ) {
                    wp_send_json_error( 'missing_fields' );
                    wp_die();
                }
        Severity: Major
        Found in includes/class-wc-ajax.php - About 3 hrs to fix

          Method update_api_key has 81 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function update_api_key() {
                  ob_start();
          
                  global $wpdb;
          
          
          Severity: Major
          Found in includes/class-wc-ajax.php - About 3 hrs to fix

            Method add_ajax_events has 74 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function add_ajax_events() {
                    $ajax_events_nopriv = array(
                        'get_refreshed_fragments',
                        'apply_coupon',
                        'remove_coupon',
            Severity: Major
            Found in includes/class-wc-ajax.php - About 2 hrs to fix

              Function grant_access_to_download has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function grant_access_to_download() {
              
                      check_ajax_referer( 'grant-access', 'security' );
              
                      if ( ! current_user_can( 'edit_shop_orders' ) || ! isset( $_POST['loop'], $_POST['order_id'], $_POST['product_ids'] ) ) {
              Severity: Minor
              Found in includes/class-wc-ajax.php - About 2 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

              Method remove_order_item has 66 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function remove_order_item() {
                      check_ajax_referer( 'order-item', 'security' );
              
                      if ( ! current_user_can( 'edit_shop_orders' ) || ! isset( $_POST['order_id'], $_POST['order_item_ids'] ) ) {
                          wp_die( -1 );
              Severity: Major
              Found in includes/class-wc-ajax.php - About 2 hrs to fix

                Function tax_rates_save_changes has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function tax_rates_save_changes() {
                        // phpcs:disable WordPress.Security.NonceVerification.Missing
                        if ( ! isset( $_POST['wc_tax_nonce'], $_POST['changes'] ) ) {
                            wp_send_json_error( 'missing_fields' );
                            wp_die();
                Severity: Minor
                Found in includes/class-wc-ajax.php - About 2 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 remove_order_item has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function remove_order_item() {
                        check_ajax_referer( 'order-item', 'security' );
                
                        if ( ! current_user_can( 'edit_shop_orders' ) || ! isset( $_POST['order_id'], $_POST['order_item_ids'] ) ) {
                            wp_die( -1 );
                Severity: Minor
                Found in includes/class-wc-ajax.php - About 2 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 json_search_products has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function json_search_products( $term = '', $include_variations = false ) {
                        check_ajax_referer( 'search-products', 'security' );
                
                        if ( empty( $term ) && isset( $_GET['term'] ) ) {
                            $term = (string) wc_clean( wp_unslash( $_GET['term'] ) );
                Severity: Minor
                Found in includes/class-wc-ajax.php - About 2 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

                Method refund_line_items has 63 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function refund_line_items() {
                        ob_start();
                
                        check_ajax_referer( 'order-item', 'security' );
                
                
                Severity: Major
                Found in includes/class-wc-ajax.php - About 2 hrs to fix

                  Method tax_rates_save_changes has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static function tax_rates_save_changes() {
                          // phpcs:disable WordPress.Security.NonceVerification.Missing
                          if ( ! isset( $_POST['wc_tax_nonce'], $_POST['changes'] ) ) {
                              wp_send_json_error( 'missing_fields' );
                              wp_die();
                  Severity: Major
                  Found in includes/class-wc-ajax.php - About 2 hrs to fix

                    Function json_search_categories has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function json_search_categories() {
                            ob_start();
                    
                            check_ajax_referer( 'search-categories', 'security' );
                    
                    
                    Severity: Minor
                    Found in includes/class-wc-ajax.php - About 2 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 toggle_gateway_enabled has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function toggle_gateway_enabled() {
                            if ( current_user_can( 'manage_woocommerce' ) && check_ajax_referer( 'woocommerce-toggle-payment-gateway-enabled', 'security' ) && isset( $_POST['gateway_id'] ) ) {
                                // Load gateways.
                                $payment_gateways = WC()->payment_gateways->payment_gateways();
                    
                    
                    Severity: Minor
                    Found in includes/class-wc-ajax.php - About 2 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 shipping_zones_save_changes has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function shipping_zones_save_changes() {
                            if ( ! isset( $_POST['wc_shipping_zones_nonce'], $_POST['changes'] ) ) {
                                wp_send_json_error( 'missing_fields' );
                                wp_die();
                            }
                    Severity: Minor
                    Found in includes/class-wc-ajax.php - About 2 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

                    Method maybe_add_order_item has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private static function maybe_add_order_item( $order_id, $items, $items_to_add ) {
                            try {
                                $order = wc_get_order( $order_id );
                    
                                if ( ! $order ) {
                    Severity: Major
                    Found in includes/class-wc-ajax.php - About 2 hrs to fix

                      Method shipping_classes_save_changes has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public static function shipping_classes_save_changes() {
                              if ( ! isset( $_POST['wc_shipping_classes_nonce'], $_POST['changes'] ) ) {
                                  wp_send_json_error( 'missing_fields' );
                                  wp_die();
                              }
                      Severity: Minor
                      Found in includes/class-wc-ajax.php - About 2 hrs to fix

                        Method json_search_products has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public static function json_search_products( $term = '', $include_variations = false ) {
                                check_ajax_referer( 'search-products', 'security' );
                        
                                if ( empty( $term ) && isset( $_GET['term'] ) ) {
                                    $term = (string) wc_clean( wp_unslash( $_GET['term'] ) );
                        Severity: Minor
                        Found in includes/class-wc-ajax.php - About 1 hr to fix

                          Function maybe_add_order_item has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                          Open

                              private static function maybe_add_order_item( $order_id, $items, $items_to_add ) {
                                  try {
                                      $order = wc_get_order( $order_id );
                          
                                      if ( ! $order ) {
                          Severity: Minor
                          Found in includes/class-wc-ajax.php - 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

                          Method add_order_fee has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public static function add_order_fee() {
                                  check_ajax_referer( 'order-item', 'security' );
                          
                                  if ( ! current_user_can( 'edit_shop_orders' ) ) {
                                      wp_die( -1 );
                          Severity: Minor
                          Found in includes/class-wc-ajax.php - About 1 hr to fix

                            Method shipping_zones_save_changes has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public static function shipping_zones_save_changes() {
                                    if ( ! isset( $_POST['wc_shipping_zones_nonce'], $_POST['changes'] ) ) {
                                        wp_send_json_error( 'missing_fields' );
                                        wp_die();
                                    }
                            Severity: Minor
                            Found in includes/class-wc-ajax.php - About 1 hr to fix

                              Method add_coupon_discount has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public static function add_coupon_discount() {
                                      check_ajax_referer( 'order-item', 'security' );
                              
                                      if ( ! current_user_can( 'edit_shop_orders' ) ) {
                                          wp_die( -1 );
                              Severity: Minor
                              Found in includes/class-wc-ajax.php - About 1 hr to fix

                                Function save_attributes has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public static function save_attributes() {
                                        check_ajax_referer( 'save-attributes', 'security' );
                                
                                        if ( ! current_user_can( 'edit_products' ) || ! isset( $_POST['data'], $_POST['post_id'] ) ) {
                                            wp_die( -1 );
                                Severity: Minor
                                Found in includes/class-wc-ajax.php - 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

                                Method json_search_customers has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public static function json_search_customers() {
                                        ob_start();
                                
                                        check_ajax_referer( 'search-customers', 'security' );
                                
                                
                                Severity: Minor
                                Found in includes/class-wc-ajax.php - About 1 hr to fix

                                  Method load_variations has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      public static function load_variations() {
                                          ob_start();
                                  
                                          check_ajax_referer( 'load-variations', 'security' );
                                  
                                  
                                  Severity: Minor
                                  Found in includes/class-wc-ajax.php - About 1 hr to fix

                                    Method save_attributes has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        public static function save_attributes() {
                                            check_ajax_referer( 'save-attributes', 'security' );
                                    
                                            if ( ! current_user_can( 'edit_products' ) || ! isset( $_POST['data'], $_POST['post_id'] ) ) {
                                                wp_die( -1 );
                                    Severity: Minor
                                    Found in includes/class-wc-ajax.php - About 1 hr to fix

                                      Method add_order_note has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                          public static function add_order_note() {
                                              check_ajax_referer( 'add-order-note', 'security' );
                                      
                                              if ( ! current_user_can( 'edit_shop_orders' ) || ! isset( $_POST['post_id'], $_POST['note'], $_POST['note_type'] ) ) {
                                                  wp_die( -1 );
                                      Severity: Minor
                                      Found in includes/class-wc-ajax.php - About 1 hr to fix

                                        Method json_search_categories has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                            public static function json_search_categories() {
                                                ob_start();
                                        
                                                check_ajax_referer( 'search-categories', 'security' );
                                        
                                        
                                        Severity: Minor
                                        Found in includes/class-wc-ajax.php - About 1 hr to fix

                                          Function refund_line_items has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                              public static function refund_line_items() {
                                                  ob_start();
                                          
                                                  check_ajax_referer( 'order-item', 'security' );
                                          
                                          
                                          Severity: Minor
                                          Found in includes/class-wc-ajax.php - 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

                                          Method grant_access_to_download has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                                          Open

                                              public static function grant_access_to_download() {
                                          
                                                  check_ajax_referer( 'grant-access', 'security' );
                                          
                                                  if ( ! current_user_can( 'edit_shop_orders' ) || ! isset( $_POST['loop'], $_POST['order_id'], $_POST['product_ids'] ) ) {
                                          Severity: Minor
                                          Found in includes/class-wc-ajax.php - About 1 hr to fix

                                            Method product_ordering has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                                            Open

                                                public static function product_ordering() {
                                                    global $wpdb;
                                            
                                                    // phpcs:disable WordPress.Security.NonceVerification.Missing
                                                    if ( ! current_user_can( 'edit_products' ) || empty( $_POST['id'] ) ) {
                                            Severity: Minor
                                            Found in includes/class-wc-ajax.php - About 1 hr to fix

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

                                                  public static function update_order_review() {
                                                      check_ajax_referer( 'update-order-review', 'security' );
                                              
                                                      wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
                                              
                                              
                                              Severity: Minor
                                              Found in includes/class-wc-ajax.php - 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 update_api_key has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  public static function update_api_key() {
                                                      ob_start();
                                              
                                                      global $wpdb;
                                              
                                              
                                              Severity: Minor
                                              Found in includes/class-wc-ajax.php - 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 product_ordering has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  public static function product_ordering() {
                                                      global $wpdb;
                                              
                                                      // phpcs:disable WordPress.Security.NonceVerification.Missing
                                                      if ( ! current_user_can( 'edit_products' ) || empty( $_POST['id'] ) ) {
                                              Severity: Minor
                                              Found in includes/class-wc-ajax.php - 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

                                              Method remove_order_coupon has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                              Open

                                                  public static function remove_order_coupon() {
                                                      check_ajax_referer( 'order-item', 'security' );
                                              
                                                      if ( ! current_user_can( 'edit_shop_orders' ) ) {
                                                          wp_die( -1 );
                                              Severity: Minor
                                              Found in includes/class-wc-ajax.php - About 1 hr to fix

                                                Method bulk_edit_variations has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                                                Open

                                                    public static function bulk_edit_variations() {
                                                        ob_start();
                                                
                                                        check_ajax_referer( 'bulk-edit-variations', 'security' );
                                                
                                                
                                                Severity: Minor
                                                Found in includes/class-wc-ajax.php - About 1 hr to fix

                                                  Method add_to_cart has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                                                  Open

                                                      public static function add_to_cart() {
                                                          ob_start();
                                                  
                                                          // phpcs:disable WordPress.Security.NonceVerification.Missing
                                                          if ( ! isset( $_POST['product_id'] ) ) {
                                                  Severity: Minor
                                                  Found in includes/class-wc-ajax.php - About 1 hr to fix

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

                                                        public static function json_search_customers() {
                                                            ob_start();
                                                    
                                                            check_ajax_referer( 'search-customers', 'security' );
                                                    
                                                    
                                                    Severity: Minor
                                                    Found in includes/class-wc-ajax.php - 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

                                                    Method add_order_tax has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                                    Open

                                                        public static function add_order_tax() {
                                                            check_ajax_referer( 'order-item', 'security' );
                                                    
                                                            if ( ! current_user_can( 'edit_shop_orders' ) ) {
                                                                wp_die( -1 );
                                                    Severity: Minor
                                                    Found in includes/class-wc-ajax.php - About 1 hr to fix

                                                      Method shipping_zone_methods_save_settings has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                                      Open

                                                          public static function shipping_zone_methods_save_settings() {
                                                              if ( ! isset( $_POST['wc_shipping_zones_nonce'], $_POST['instance_id'], $_POST['data'] ) ) {
                                                                  wp_send_json_error( 'missing_fields' );
                                                                  wp_die();
                                                              }
                                                      Severity: Minor
                                                      Found in includes/class-wc-ajax.php - About 1 hr to fix

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

                                                            public static function add_new_attribute() {
                                                                check_ajax_referer( 'add-attribute', 'security' );
                                                        
                                                                if ( current_user_can( 'manage_product_terms' ) && isset( $_POST['taxonomy'], $_POST['term'] ) ) {
                                                                    $taxonomy = esc_attr( wp_unslash( $_POST['taxonomy'] ) ); // phpcs:ignore
                                                        Severity: Minor
                                                        Found in includes/class-wc-ajax.php - 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 term_ordering has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            public static function term_ordering() {
                                                                // phpcs:disable WordPress.Security.NonceVerification.Missing
                                                                if ( ! current_user_can( 'edit_products' ) || empty( $_POST['id'] ) ) {
                                                                    wp_die( -1 );
                                                                }
                                                        Severity: Minor
                                                        Found in includes/class-wc-ajax.php - 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 add_coupon_discount has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            public static function add_coupon_discount() {
                                                                check_ajax_referer( 'order-item', 'security' );
                                                        
                                                                if ( ! current_user_can( 'edit_shop_orders' ) ) {
                                                                    wp_die( -1 );
                                                        Severity: Minor
                                                        Found in includes/class-wc-ajax.php - 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 remove_variations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            public static function remove_variations() {
                                                                check_ajax_referer( 'delete-variations', 'security' );
                                                        
                                                                if ( current_user_can( 'edit_products' ) && isset( $_POST['variation_ids'] ) ) {
                                                                    $variation_ids = array_map( 'absint', (array) wp_unslash( $_POST['variation_ids'] ) );
                                                        Severity: Minor
                                                        Found in includes/class-wc-ajax.php - 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 variation_bulk_action_variable_sale_schedule has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            private static function variation_bulk_action_variable_sale_schedule( $variations, $data ) {
                                                                if ( ! isset( $data['date_from'] ) && ! isset( $data['date_to'] ) ) {
                                                                    return;
                                                                }
                                                        
                                                        
                                                        Severity: Minor
                                                        Found in includes/class-wc-ajax.php - 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 add_to_cart has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            public static function add_to_cart() {
                                                                ob_start();
                                                        
                                                                // phpcs:disable WordPress.Security.NonceVerification.Missing
                                                                if ( ! isset( $_POST['product_id'] ) ) {
                                                        Severity: Minor
                                                        Found in includes/class-wc-ajax.php - 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 delete_refund has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            public static function delete_refund() {
                                                                check_ajax_referer( 'order-item', 'security' );
                                                        
                                                                if ( ! current_user_can( 'edit_shop_orders' ) || ! isset( $_POST['refund_id'] ) ) {
                                                                    wp_die( -1 );
                                                        Severity: Minor
                                                        Found in includes/class-wc-ajax.php - 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

                                                                if ( wc_ship_to_billing_address_only() ) {
                                                                    WC()->customer->set_props(
                                                                        array(
                                                                            'shipping_country'   => isset( $_POST['country'] ) ? wc_clean( wp_unslash( $_POST['country'] ) ) : null,
                                                                            'shipping_state'     => isset( $_POST['state'] ) ? wc_clean( wp_unslash( $_POST['state'] ) ) : null,
                                                        Severity: Major
                                                        Found in includes/class-wc-ajax.php and 1 other location - About 1 day to fix
                                                        includes/class-wc-ajax.php on lines 335..346

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

                                                        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

                                                                } else {
                                                                    WC()->customer->set_props(
                                                                        array(
                                                                            'shipping_country'   => isset( $_POST['s_country'] ) ? wc_clean( wp_unslash( $_POST['s_country'] ) ) : null,
                                                                            'shipping_state'     => isset( $_POST['s_state'] ) ? wc_clean( wp_unslash( $_POST['s_state'] ) ) : null,
                                                        Severity: Major
                                                        Found in includes/class-wc-ajax.php and 1 other location - About 1 day to fix
                                                        includes/class-wc-ajax.php on lines 324..346

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

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

                                                                    $calculate_tax_args = array(
                                                                        'country'  => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
                                                                        'state'    => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
                                                                        'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
                                                                        'city'     => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
                                                        Severity: Major
                                                        Found in includes/class-wc-ajax.php and 4 other locations - About 4 hrs to fix
                                                        includes/class-wc-ajax.php on lines 992..997
                                                        includes/class-wc-ajax.php on lines 1136..1141
                                                        includes/class-wc-ajax.php on lines 1199..1204
                                                        includes/class-wc-ajax.php on lines 1378..1383

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

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

                                                                    $calculate_tax_args = array(
                                                                        'country'  => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
                                                                        'state'    => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
                                                                        'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
                                                                        'city'     => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
                                                        Severity: Major
                                                        Found in includes/class-wc-ajax.php and 4 other locations - About 4 hrs to fix
                                                        includes/class-wc-ajax.php on lines 992..997
                                                        includes/class-wc-ajax.php on lines 1136..1141
                                                        includes/class-wc-ajax.php on lines 1257..1262
                                                        includes/class-wc-ajax.php on lines 1378..1383

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

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

                                                                    $calculate_tax_args = array(
                                                                        'country'  => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
                                                                        'state'    => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
                                                                        'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
                                                                        'city'     => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
                                                        Severity: Major
                                                        Found in includes/class-wc-ajax.php and 4 other locations - About 4 hrs to fix
                                                        includes/class-wc-ajax.php on lines 992..997
                                                        includes/class-wc-ajax.php on lines 1199..1204
                                                        includes/class-wc-ajax.php on lines 1257..1262
                                                        includes/class-wc-ajax.php on lines 1378..1383

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

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

                                                                    $calculate_tax_args = array(
                                                                        'country'  => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
                                                                        'state'    => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
                                                                        'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
                                                                        'city'     => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
                                                        Severity: Major
                                                        Found in includes/class-wc-ajax.php and 4 other locations - About 4 hrs to fix
                                                        includes/class-wc-ajax.php on lines 1136..1141
                                                        includes/class-wc-ajax.php on lines 1199..1204
                                                        includes/class-wc-ajax.php on lines 1257..1262
                                                        includes/class-wc-ajax.php on lines 1378..1383

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

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

                                                                $calculate_tax_args = array(
                                                                    'country'  => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
                                                                    'state'    => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
                                                                    'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
                                                                    'city'     => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
                                                        Severity: Major
                                                        Found in includes/class-wc-ajax.php and 4 other locations - About 4 hrs to fix
                                                        includes/class-wc-ajax.php on lines 992..997
                                                        includes/class-wc-ajax.php on lines 1136..1141
                                                        includes/class-wc-ajax.php on lines 1199..1204
                                                        includes/class-wc-ajax.php on lines 1257..1262

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

                                                        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