woothemes/woocommerce

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

Summary

Maintainability
F
1 wk
Test Coverage

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

<?php
/**
 * Checkout functionality
 *
 * The WooCommerce checkout class handles the checkout process, collecting user data and processing the payment.
Severity: Major
Found in includes/class-wc-checkout.php - About 1 day to fix

    Function validate_posted_data has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function validate_posted_data( &$data, &$errors ) {
            foreach ( $this->get_checkout_fields() as $fieldset_key => $fieldset ) {
                $validate_fieldset = true;
                if ( $this->maybe_skip_fieldset( $fieldset_key, $data ) ) {
                    $validate_fieldset = false;
    Severity: Minor
    Found in includes/class-wc-checkout.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

    WC_Checkout has 32 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WC_Checkout {
    
        /**
         * The single instance of the class.
         *
    Severity: Minor
    Found in includes/class-wc-checkout.php - About 4 hrs to fix

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

          protected function validate_checkout( &$data, &$errors ) {
              $this->validate_posted_data( $data, $errors );
              $this->check_cart_items();
      
              // phpcs:ignore WordPress.Security.NonceVerification.Missing
      Severity: Minor
      Found in includes/class-wc-checkout.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 process_customer has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function process_customer( $data ) {
              $customer_id = apply_filters( 'woocommerce_checkout_customer_id', get_current_user_id() );
      
              if ( ! is_user_logged_in() && ( $this->is_registration_required() || ! empty( $data['createaccount'] ) ) ) {
                  $username    = ! empty( $data['account_username'] ) ? $data['account_username'] : '';
      Severity: Minor
      Found in includes/class-wc-checkout.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 validate_posted_data has 71 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function validate_posted_data( &$data, &$errors ) {
              foreach ( $this->get_checkout_fields() as $fieldset_key => $fieldset ) {
                  $validate_fieldset = true;
                  if ( $this->maybe_skip_fieldset( $fieldset_key, $data ) ) {
                      $validate_fieldset = false;
      Severity: Major
      Found in includes/class-wc-checkout.php - About 2 hrs to fix

        Method get_checkout_fields has 64 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function get_checkout_fields( $fieldset = '' ) {
                if ( ! is_null( $this->fields ) ) {
                    return $fieldset ? $this->fields[ $fieldset ] : $this->fields;
                }
        
        
        Severity: Major
        Found in includes/class-wc-checkout.php - About 2 hrs to fix

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

              public function get_posted_data() {
                  // phpcs:disable WordPress.Security.NonceVerification.Missing
                  $data = array(
                      'terms'                              => (int) isset( $_POST['terms'] ),
                      'createaccount'                      => (int) ( $this->is_registration_enabled() ? ! empty( $_POST['createaccount'] ) : false ),
          Severity: Minor
          Found in includes/class-wc-checkout.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 create_order has 56 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function create_order( $data ) {
                  // Give plugins the opportunity to create an order themselves.
                  $order_id = apply_filters( 'woocommerce_create_order', null, $this );
                  if ( $order_id ) {
                      return $order_id;
          Severity: Major
          Found in includes/class-wc-checkout.php - About 2 hrs to fix

            Function process_checkout has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

                public function process_checkout() {
                    try {
                        $nonce_value = wc_get_var( $_REQUEST['woocommerce-process-checkout-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
            
                        if ( empty( $nonce_value ) || ! wp_verify_nonce( $nonce_value, 'woocommerce-process_checkout' ) ) {
            Severity: Minor
            Found in includes/class-wc-checkout.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 process_customer has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function process_customer( $data ) {
                    $customer_id = apply_filters( 'woocommerce_checkout_customer_id', get_current_user_id() );
            
                    if ( ! is_user_logged_in() && ( $this->is_registration_required() || ! empty( $data['createaccount'] ) ) ) {
                        $username    = ! empty( $data['account_username'] ) ? $data['account_username'] : '';
            Severity: Minor
            Found in includes/class-wc-checkout.php - About 1 hr to fix

              Method process_checkout has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function process_checkout() {
                      try {
                          $nonce_value = wc_get_var( $_REQUEST['woocommerce-process-checkout-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
              
                          if ( empty( $nonce_value ) || ! wp_verify_nonce( $nonce_value, 'woocommerce-process_checkout' ) ) {
              Severity: Minor
              Found in includes/class-wc-checkout.php - About 1 hr to fix

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

                    public function create_order( $data ) {
                        // Give plugins the opportunity to create an order themselves.
                        $order_id = apply_filters( 'woocommerce_create_order', null, $this );
                        if ( $order_id ) {
                            return $order_id;
                Severity: Minor
                Found in includes/class-wc-checkout.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 get_posted_data has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function get_posted_data() {
                        // phpcs:disable WordPress.Security.NonceVerification.Missing
                        $data = array(
                            'terms'                              => (int) isset( $_POST['terms'] ),
                            'createaccount'                      => (int) ( $this->is_registration_enabled() ? ! empty( $_POST['createaccount'] ) : false ),
                Severity: Minor
                Found in includes/class-wc-checkout.php - About 1 hr to fix

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

                      public function get_checkout_fields( $fieldset = '' ) {
                          if ( ! is_null( $this->fields ) ) {
                              return $fieldset ? $this->fields[ $fieldset ] : $this->fields;
                          }
                  
                  
                  Severity: Minor
                  Found in includes/class-wc-checkout.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 validate_checkout has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function validate_checkout( &$data, &$errors ) {
                          $this->validate_posted_data( $data, $errors );
                          $this->check_cart_items();
                  
                          // phpcs:ignore WordPress.Security.NonceVerification.Missing
                  Severity: Minor
                  Found in includes/class-wc-checkout.php - About 1 hr to fix

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

                        public function create_order_line_items( &$order, $cart ) {
                            foreach ( $cart->get_cart() as $cart_item_key => $values ) {
                                /**
                                 * Filter hook to get initial item object.
                                 *
                    Severity: Minor
                    Found in includes/class-wc-checkout.php - About 1 hr to fix

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

                          public function __set( $key, $value ) {
                              switch ( $key ) {
                                  case 'enable_signup':
                                      $bool_value = wc_string_to_bool( $value );
                      
                      
                      Severity: Minor
                      Found in includes/class-wc-checkout.php - About 1 hr to fix

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

                            public function get_value( $input ) {
                                // If the form was posted, get the posted value. This will only tend to happen when JavaScript is disabled client side.
                                if ( ! empty( $_POST[ $input ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
                                    return wc_clean( wp_unslash( $_POST[ $input ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
                                }
                        Severity: Minor
                        Found in includes/class-wc-checkout.php - About 1 hr to fix

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

                              public function get_value( $input ) {
                                  // If the form was posted, get the posted value. This will only tend to happen when JavaScript is disabled client side.
                                  if ( ! empty( $_POST[ $input ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
                                      return wc_clean( wp_unslash( $_POST[ $input ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
                                  }
                          Severity: Minor
                          Found in includes/class-wc-checkout.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 __set has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function __set( $key, $value ) {
                                  switch ( $key ) {
                                      case 'enable_signup':
                                          $bool_value = wc_string_to_bool( $value );
                          
                          
                          Severity: Minor
                          Found in includes/class-wc-checkout.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 maybe_skip_fieldset has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              protected function maybe_skip_fieldset( $fieldset_key, $data ) {
                                  if ( 'shipping' === $fieldset_key && ( ! $data['ship_to_different_address'] || ! WC()->cart->needs_shipping_address() ) ) {
                                      return true;
                                  }
                          
                          
                          Severity: Minor
                          Found in includes/class-wc-checkout.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

                          Avoid too many return statements within this method.
                          Open

                                          return apply_filters( 'woocommerce_checkout_customer_id', get_current_user_id() );
                          Severity: Major
                          Found in includes/class-wc-checkout.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return $this->legacy_posted_data['payment_method'];
                            Severity: Major
                            Found in includes/class-wc-checkout.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return $this->legacy_posted_data;
                              Severity: Major
                              Found in includes/class-wc-checkout.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return (array) WC()->session->get( 'chosen_shipping_methods' );
                                Severity: Major
                                Found in includes/class-wc-checkout.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                  return $this->legacy_posted_data['shipping_method'];
                                  Severity: Major
                                  Found in includes/class-wc-checkout.php - About 30 mins to fix

                                    Function create_order_shipping_lines has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public function create_order_shipping_lines( &$order, $chosen_shipping_methods, $packages ) {
                                            foreach ( $packages as $package_key => $package ) {
                                                if ( isset( $chosen_shipping_methods[ $package_key ], $package['rates'][ $chosen_shipping_methods[ $package_key ] ] ) ) {
                                                    $shipping_rate            = $package['rates'][ $chosen_shipping_methods[ $package_key ] ];
                                                    $item                     = new WC_Order_Item_Shipping();
                                    Severity: Minor
                                    Found in includes/class-wc-checkout.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

                                    There are no issues that match your filters.

                                    Category
                                    Status