| Conditions | 18 |
| Paths | 28 |
| Total Lines | 110 |
| Code Lines | 61 |
| Lines | 4 |
| Ratio | 3.64 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 73 | private static function order_pay( $order_id ) { |
||
| 74 | |||
| 75 | do_action( 'before_woocommerce_pay' ); |
||
| 76 | |||
| 77 | wc_print_notices(); |
||
| 78 | |||
| 79 | $order_id = absint( $order_id ); |
||
| 80 | |||
| 81 | // Handle payment |
||
| 82 | if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) && $order_id ) { |
||
| 83 | |||
| 84 | // Pay for existing order |
||
| 85 | $order_key = $_GET[ 'key' ]; |
||
| 86 | $order = wc_get_order( $order_id ); |
||
| 87 | |||
| 88 | View Code Duplication | if ( ! current_user_can( 'pay_for_order', $order_id ) ) { |
|
| 89 | echo '<div class="woocommerce-error">' . __( 'Invalid order. If you have an account please log in and try again.', 'woocommerce' ) . ' <a href="' . wc_get_page_permalink( 'myaccount' ) . '" class="wc-forward">' . __( 'My Account', 'woocommerce' ) . '</a>' . '</div>'; |
||
| 90 | return; |
||
| 91 | } |
||
| 92 | |||
| 93 | if ( $order->id == $order_id && $order->order_key == $order_key ) { |
||
| 94 | |||
| 95 | if ( $order->needs_payment() ) { |
||
| 96 | |||
| 97 | // Set customer location to order location |
||
| 98 | if ( $order->billing_country ) { |
||
| 99 | WC()->customer->set_country( $order->billing_country ); |
||
| 100 | } |
||
| 101 | if ( $order->billing_state ) { |
||
| 102 | WC()->customer->set_state( $order->billing_state ); |
||
| 103 | } |
||
| 104 | if ( $order->billing_postcode ) { |
||
| 105 | WC()->customer->set_postcode( $order->billing_postcode ); |
||
| 106 | } |
||
| 107 | |||
| 108 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
||
| 109 | |||
| 110 | if ( sizeof( $available_gateways ) ) { |
||
| 111 | current( $available_gateways )->set_current(); |
||
| 112 | } |
||
| 113 | |||
| 114 | wc_get_template( 'checkout/form-pay.php', array( |
||
| 115 | 'order' => $order, |
||
| 116 | 'available_gateways' => $available_gateways, |
||
| 117 | 'order_button_text' => apply_filters( 'woocommerce_pay_order_button_text', __( 'Pay for order', 'woocommerce' ) ) |
||
| 118 | ) ); |
||
| 119 | |||
| 120 | } else { |
||
| 121 | wc_add_notice( sprintf( __( 'This order’s status is “%s”—it cannot be paid for. Please contact us if you need assistance.', 'woocommerce' ), wc_get_order_status_name( $order->get_status() ) ), 'error' ); |
||
| 122 | } |
||
| 123 | |||
| 124 | } else { |
||
| 125 | wc_add_notice( __( 'Sorry, this order is invalid and cannot be paid for.', 'woocommerce' ), 'error' ); |
||
| 126 | } |
||
| 127 | |||
| 128 | } elseif ( $order_id ) { |
||
| 129 | |||
| 130 | // Pay for order after checkout step |
||
| 131 | $order_key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : ''; |
||
| 132 | $order = wc_get_order( $order_id ); |
||
| 133 | |||
| 134 | if ( $order->id == $order_id && $order->order_key == $order_key ) { |
||
| 135 | |||
| 136 | if ( $order->needs_payment() ) { |
||
| 137 | |||
| 138 | ?> |
||
| 139 | <ul class="order_details"> |
||
| 140 | <li class="order"> |
||
| 141 | <?php _e( 'Order Number:', 'woocommerce' ); ?> |
||
| 142 | <strong><?php echo $order->get_order_number(); ?></strong> |
||
| 143 | </li> |
||
| 144 | <li class="date"> |
||
| 145 | <?php _e( 'Date:', 'woocommerce' ); ?> |
||
| 146 | <strong><?php echo date_i18n(get_option('date_format'), strtotime($order->order_date)); ?></strong> |
||
| 147 | </li> |
||
| 148 | <li class="total"> |
||
| 149 | <?php _e( 'Total:', 'woocommerce' ); ?> |
||
| 150 | <strong><?php echo $order->get_formatted_order_total(); ?></strong> |
||
| 151 | </li> |
||
| 152 | <?php if ($order->payment_method_title) : ?> |
||
| 153 | <li class="method"> |
||
| 154 | <?php _e( 'Payment Method:', 'woocommerce' ); ?> |
||
| 155 | <strong><?php |
||
| 156 | echo $order->payment_method_title; |
||
| 157 | ?></strong> |
||
| 158 | </li> |
||
| 159 | <?php endif; ?> |
||
| 160 | </ul> |
||
| 161 | |||
| 162 | <?php do_action( 'woocommerce_receipt_' . $order->payment_method, $order_id ); ?> |
||
| 163 | |||
| 164 | <div class="clear"></div> |
||
| 165 | <?php |
||
| 166 | |||
| 167 | } else { |
||
| 168 | wc_add_notice( sprintf( __( 'This order’s status is “%s”—it cannot be paid for. Please contact us if you need assistance.', 'woocommerce' ), wc_get_order_status_name( $order->get_status() ) ), 'error' ); |
||
| 169 | } |
||
| 170 | |||
| 171 | } else { |
||
| 172 | wc_add_notice( __( 'Sorry, this order is invalid and cannot be paid for.', 'woocommerce' ), 'error' ); |
||
| 173 | } |
||
| 174 | |||
| 175 | } else { |
||
| 176 | wc_add_notice( __( 'Invalid order.', 'woocommerce' ), 'error' ); |
||
| 177 | } |
||
| 178 | |||
| 179 | wc_print_notices(); |
||
| 180 | |||
| 181 | do_action( 'after_woocommerce_pay' ); |
||
| 182 | } |
||
| 183 | |||
| 250 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.