woocommerce/woocommerce

View on GitHub
includes/class-wc-form-handler.php

Summary

Maintainability
F
1 wk
Test Coverage

File class-wc-form-handler.php has 747 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Handle frontend forms.
 *
 * @package WooCommerce\Classes\
Severity: Major
Found in includes/class-wc-form-handler.php - About 1 day to fix

    Function save_address has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function save_address() {
            global $wp;
    
            $nonce_value = wc_get_var( $_REQUEST['woocommerce-edit-address-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
    
    
    Severity: Minor
    Found in includes/class-wc-form-handler.php - About 1 day 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_cart_action has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function update_cart_action() {
            if ( ! ( isset( $_REQUEST['apply_coupon'] ) || isset( $_REQUEST['remove_coupon'] ) || isset( $_REQUEST['remove_item'] ) || isset( $_REQUEST['undo_item'] ) || isset( $_REQUEST['update_cart'] ) || isset( $_REQUEST['proceed'] ) ) ) {
                return;
            }
    
    
    Severity: Minor
    Found in includes/class-wc-form-handler.php - About 7 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 save_account_details has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function save_account_details() {
            $nonce_value = wc_get_var( $_REQUEST['save-account-details-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
    
            if ( ! wp_verify_nonce( $nonce_value, 'save_account_details' ) ) {
                return;
    Severity: Minor
    Found in includes/class-wc-form-handler.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 pay_action has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function pay_action() {
            global $wp;
    
            if ( isset( $_POST['woocommerce_pay'], $_GET['key'] ) ) {
                wc_nocache_headers();
    Severity: Minor
    Found in includes/class-wc-form-handler.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

    Method save_account_details has 101 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function save_account_details() {
            $nonce_value = wc_get_var( $_REQUEST['save-account-details-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
    
            if ( ! wp_verify_nonce( $nonce_value, 'save_account_details' ) ) {
                return;
    Severity: Major
    Found in includes/class-wc-form-handler.php - About 4 hrs to fix

      Function process_registration has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function process_registration() {
              $nonce_value = isset( $_POST['_wpnonce'] ) ? wp_unslash( $_POST['_wpnonce'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
              $nonce_value = isset( $_POST['woocommerce-register-nonce'] ) ? wp_unslash( $_POST['woocommerce-register-nonce'] ) : $nonce_value; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
      
              if ( isset( $_POST['register'], $_POST['email'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-register' ) ) {
      Severity: Minor
      Found in includes/class-wc-form-handler.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

      Function add_payment_method_action has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function add_payment_method_action() {
              if ( isset( $_POST['woocommerce_add_payment_method'], $_POST['payment_method'] ) ) {
                  wc_nocache_headers();
      
                  $nonce_value = wc_get_var( $_REQUEST['woocommerce-add-payment-method-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
      Severity: Minor
      Found in includes/class-wc-form-handler.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 save_address has 89 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function save_address() {
              global $wp;
      
              $nonce_value = wc_get_var( $_REQUEST['woocommerce-edit-address-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
      
      
      Severity: Major
      Found in includes/class-wc-form-handler.php - About 3 hrs to fix

        Function process_login has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function process_login() {
                // The global form-login.php template used `_wpnonce` in template versions < 3.3.0.
                $nonce_value = wc_get_var( $_REQUEST['woocommerce-login-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
        
                if ( isset( $_POST['login'], $_POST['username'], $_POST['password'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-login' ) ) {
        Severity: Minor
        Found in includes/class-wc-form-handler.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 update_cart_action has 72 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function update_cart_action() {
                if ( ! ( isset( $_REQUEST['apply_coupon'] ) || isset( $_REQUEST['remove_coupon'] ) || isset( $_REQUEST['remove_item'] ) || isset( $_REQUEST['undo_item'] ) || isset( $_REQUEST['update_cart'] ) || isset( $_REQUEST['proceed'] ) ) ) {
                    return;
                }
        
        
        Severity: Major
        Found in includes/class-wc-form-handler.php - About 2 hrs to fix

          Method pay_action has 59 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function pay_action() {
                  global $wp;
          
                  if ( isset( $_POST['woocommerce_pay'], $_GET['key'] ) ) {
                      wc_nocache_headers();
          Severity: Major
          Found in includes/class-wc-form-handler.php - About 2 hrs to fix

            Method add_payment_method_action has 54 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function add_payment_method_action() {
                    if ( isset( $_POST['woocommerce_add_payment_method'], $_POST['payment_method'] ) ) {
                        wc_nocache_headers();
            
                        $nonce_value = wc_get_var( $_REQUEST['woocommerce-add-payment-method-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
            Severity: Major
            Found in includes/class-wc-form-handler.php - About 2 hrs to fix

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

                  private static function add_to_cart_handler_grouped( $product_id ) {
                      $was_added_to_cart = false;
                      $added_to_cart     = array();
                      $items             = isset( $_REQUEST['quantity'] ) && is_array( $_REQUEST['quantity'] ) ? wp_unslash( $_REQUEST['quantity'] ) : array(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
              
              
              Severity: Minor
              Found in includes/class-wc-form-handler.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 process_registration has 45 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function process_registration() {
                      $nonce_value = isset( $_POST['_wpnonce'] ) ? wp_unslash( $_POST['_wpnonce'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
                      $nonce_value = isset( $_POST['woocommerce-register-nonce'] ) ? wp_unslash( $_POST['woocommerce-register-nonce'] ) : $nonce_value; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
              
                      if ( isset( $_POST['register'], $_POST['email'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-register' ) ) {
              Severity: Minor
              Found in includes/class-wc-form-handler.php - About 1 hr to fix

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

                    public static function process_reset_password() {
                        $nonce_value = wc_get_var( $_REQUEST['woocommerce-reset-password-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
                
                        if ( ! wp_verify_nonce( $nonce_value, 'reset_password' ) ) {
                            return;
                Severity: Minor
                Found in includes/class-wc-form-handler.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 process_login has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function process_login() {
                        // The global form-login.php template used `_wpnonce` in template versions < 3.3.0.
                        $nonce_value = wc_get_var( $_REQUEST['woocommerce-login-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
                
                        if ( isset( $_POST['login'], $_POST['username'], $_POST['password'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-login' ) ) {
                Severity: Minor
                Found in includes/class-wc-form-handler.php - About 1 hr to fix

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

                      public static function add_to_cart_action( $url = false ) {
                          if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( wp_unslash( $_REQUEST['add-to-cart'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
                              return;
                          }
                  
                  
                  Severity: Minor
                  Found in includes/class-wc-form-handler.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

                  Consider simplifying this complex logical expression.
                  Open

                          if ( ! empty( $pass_cur ) && empty( $pass1 ) && empty( $pass2 ) ) {
                              wc_add_notice( __( 'Please fill out all password fields.', 'woocommerce' ), 'error' );
                              $save_pass = false;
                          } elseif ( ! empty( $pass1 ) && empty( $pass_cur ) ) {
                              wc_add_notice( __( 'Please enter your current password.', 'woocommerce' ), 'error' );
                  Severity: Critical
                  Found in includes/class-wc-form-handler.php - About 1 hr to fix

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

                        public static function process_reset_password() {
                            $nonce_value = wc_get_var( $_REQUEST['woocommerce-reset-password-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
                    
                            if ( ! wp_verify_nonce( $nonce_value, 'reset_password' ) ) {
                                return;
                    Severity: Minor
                    Found in includes/class-wc-form-handler.php - About 1 hr to fix

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

                          private static function add_to_cart_handler_grouped( $product_id ) {
                              $was_added_to_cart = false;
                              $added_to_cart     = array();
                              $items             = isset( $_REQUEST['quantity'] ) && is_array( $_REQUEST['quantity'] ) ? wp_unslash( $_REQUEST['quantity'] ) : array(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
                      
                      
                      Severity: Minor
                      Found in includes/class-wc-form-handler.php - About 1 hr to fix

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

                            public static function add_to_cart_action( $url = false ) {
                                if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( wp_unslash( $_REQUEST['add-to-cart'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
                                    return;
                                }
                        
                        
                        Severity: Minor
                        Found in includes/class-wc-form-handler.php - About 1 hr to fix

                          Method cancel_order has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public static function cancel_order() {
                                  if (
                                      isset( $_GET['cancel_order'] ) &&
                                      isset( $_GET['order'] ) &&
                                      isset( $_GET['order_id'] ) &&
                          Severity: Minor
                          Found in includes/class-wc-form-handler.php - About 1 hr to fix

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

                                public static function redirect_reset_password_link() {
                                    if ( is_account_page() && isset( $_GET['key'] ) && ( isset( $_GET['id'] ) || isset( $_GET['login'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
                            
                                        // If available, get $user_id from query string parameter for fallback purposes.
                                        if ( isset( $_GET['login'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
                            Severity: Minor
                            Found in includes/class-wc-form-handler.php - About 1 hr to fix

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

                                  public static function redirect_reset_password_link() {
                                      if ( is_account_page() && isset( $_GET['key'] ) && ( isset( $_GET['id'] ) || isset( $_GET['login'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
                              
                                          // If available, get $user_id from query string parameter for fallback purposes.
                                          if ( isset( $_GET['login'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
                              Severity: Minor
                              Found in includes/class-wc-form-handler.php - About 55 mins to fix

                              Cognitive Complexity

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

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

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

                              Further reading

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

                                  public static function cancel_order() {
                                      if (
                                          isset( $_GET['cancel_order'] ) &&
                                          isset( $_GET['order'] ) &&
                                          isset( $_GET['order_id'] ) &&
                              Severity: Minor
                              Found in includes/class-wc-form-handler.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

                              Avoid deeply nested control flow statements.
                              Open

                                                                  switch ( $country ) {
                                                                      case 'IE':
                                                                          $postcode_validation_notice = __( 'Please enter a valid Eircode.', 'woocommerce' );
                                                                          break;
                                                                      default:
                              Severity: Major
                              Found in includes/class-wc-form-handler.php - About 45 mins to fix

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

                                    private static function add_to_cart_handler_variable( $product_id ) {
                                        $variation_id = empty( $_REQUEST['variation_id'] ) ? '' : absint( wp_unslash( $_REQUEST['variation_id'] ) );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
                                        $quantity     = empty( $_REQUEST['quantity'] ) ? 1 : wc_stock_amount( wp_unslash( $_REQUEST['quantity'] ) );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
                                        $variations   = array();
                                
                                
                                Severity: Minor
                                Found in includes/class-wc-form-handler.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

                                Consider simplifying this complex logical expression.
                                Open

                                        if ( ! ( isset( $_REQUEST['apply_coupon'] ) || isset( $_REQUEST['remove_coupon'] ) || isset( $_REQUEST['remove_item'] ) || isset( $_REQUEST['undo_item'] ) || isset( $_REQUEST['update_cart'] ) || isset( $_REQUEST['proceed'] ) ) ) {
                                            return;
                                        }
                                Severity: Major
                                Found in includes/class-wc-form-handler.php - About 40 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return;
                                  Severity: Major
                                  Found in includes/class-wc-form-handler.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return;
                                    Severity: Major
                                    Found in includes/class-wc-form-handler.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                          return;
                                      Severity: Major
                                      Found in includes/class-wc-form-handler.php - About 30 mins to fix

                                        There are no issues that match your filters.

                                        Category
                                        Status