Conditions | 43 |
Paths | > 20000 |
Total Lines | 264 |
Code Lines | 161 |
Lines | 73 |
Ratio | 27.65 % |
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 |
||
139 | public static function output( $post ) { |
||
140 | global $theorder; |
||
141 | |||
142 | if ( ! is_object( $theorder ) ) { |
||
143 | $theorder = wc_get_order( $post->ID ); |
||
144 | } |
||
145 | |||
146 | $order = $theorder; |
||
147 | |||
148 | self::init_address_fields(); |
||
149 | |||
150 | if ( WC()->payment_gateways() ) { |
||
151 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
||
152 | } else { |
||
153 | $payment_gateways = array(); |
||
154 | } |
||
155 | |||
156 | $payment_method = ! empty( $order->payment_method ) ? $order->payment_method : ''; |
||
157 | |||
158 | $order_type_object = get_post_type_object( $post->post_type ); |
||
159 | wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); |
||
160 | ?> |
||
161 | <style type="text/css"> |
||
162 | #post-body-content, #titlediv { display:none } |
||
163 | </style> |
||
164 | <div class="panel-wrap woocommerce"> |
||
165 | <input name="post_title" type="hidden" value="<?php echo empty( $post->post_title ) ? __( 'Order', 'woocommerce' ) : esc_attr( $post->post_title ); ?>" /> |
||
166 | <input name="post_status" type="hidden" value="<?php echo esc_attr( $post->post_status ); ?>" /> |
||
167 | <div id="order_data" class="panel"> |
||
168 | |||
169 | <h2><?php echo esc_html( sprintf( _x( '%s #%s details', 'Order #123 details', 'woocommerce' ), $order_type_object->labels->singular_name, $order->get_order_number() ) ); ?></h2> |
||
170 | <p class="order_number"><?php |
||
171 | |||
172 | if ( $payment_method ) { |
||
173 | printf( __( 'Payment via %s', 'woocommerce' ), ( isset( $payment_gateways[ $payment_method ] ) ? esc_html( $payment_gateways[ $payment_method ]->get_title() ) : esc_html( $payment_method ) ) ); |
||
174 | |||
175 | if ( $transaction_id = $order->get_transaction_id() ) { |
||
176 | if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order ) ) ) { |
||
177 | echo ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)'; |
||
178 | } else { |
||
179 | echo ' (' . esc_html( $transaction_id ) . ')'; |
||
180 | } |
||
181 | } |
||
182 | echo '. '; |
||
183 | } |
||
184 | |||
185 | View Code Duplication | if ( $ip_address = get_post_meta( $post->ID, '_customer_ip_address', true ) ) { |
|
186 | echo __( 'Customer IP', 'woocommerce' ) . ': ' . esc_html( $ip_address ); |
||
187 | } |
||
188 | ?></p> |
||
189 | |||
190 | <div class="order_data_column_container"> |
||
191 | <div class="order_data_column"> |
||
192 | <h3><?php _e( 'General Details', 'woocommerce' ); ?></h3> |
||
193 | |||
194 | <p class="form-field form-field-wide"><label for="order_date"><?php _e( 'Order date:', 'woocommerce' ) ?></label> |
||
195 | <input type="text" class="date-picker" name="order_date" id="order_date" maxlength="10" value="<?php echo date_i18n( 'Y-m-d', strtotime( $post->post_date ) ); ?>" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />@<input type="text" class="hour" placeholder="<?php esc_attr_e( 'h', 'woocommerce' ) ?>" name="order_date_hour" id="order_date_hour" maxlength="2" size="2" value="<?php echo date_i18n( 'H', strtotime( $post->post_date ) ); ?>" pattern="\-?\d+(\.\d{0,})?" />:<input type="text" class="minute" placeholder="<?php esc_attr_e( 'm', 'woocommerce' ) ?>" name="order_date_minute" id="order_date_minute" maxlength="2" size="2" value="<?php echo date_i18n( 'i', strtotime( $post->post_date ) ); ?>" pattern="\-?\d+(\.\d{0,})?" /> |
||
196 | </p> |
||
197 | |||
198 | <p class="form-field form-field-wide wc-order-status"><label for="order_status"><?php _e( 'Order status:', 'woocommerce' ) ?> <?php |
||
199 | if ( $order->has_status( 'pending' ) ) { |
||
200 | printf( '<a href="%s">%s →</a>', |
||
201 | esc_url( $order->get_checkout_payment_url() ), |
||
202 | __( 'Customer payment page', 'woocommerce' ) |
||
203 | ); |
||
204 | } |
||
205 | ?></label> |
||
206 | <select id="order_status" name="order_status" class="wc-enhanced-select"> |
||
207 | <?php |
||
208 | $statuses = wc_get_order_statuses(); |
||
209 | foreach ( $statuses as $status => $status_name ) { |
||
210 | echo '<option value="' . esc_attr( $status ) . '" ' . selected( $status, 'wc-' . $order->get_status(), false ) . '>' . esc_html( $status_name ) . '</option>'; |
||
211 | } |
||
212 | ?> |
||
213 | </select></p> |
||
214 | |||
215 | <p class="form-field form-field-wide wc-customer-user"> |
||
216 | <label for="customer_user"><?php _e( 'Customer:', 'woocommerce' ) ?> <?php |
||
217 | if ( ! empty( $order->customer_user ) ) { |
||
218 | $args = array( 'post_status' => 'all', |
||
219 | 'post_type' => 'shop_order', |
||
220 | '_customer_user' => absint( $order->customer_user ) |
||
221 | ); |
||
222 | printf( '<a href="%s">%s →</a>', |
||
223 | esc_url( add_query_arg( $args, admin_url( 'edit.php' ) ) ), |
||
224 | __( 'View other orders', 'woocommerce' ) |
||
225 | ); |
||
226 | } |
||
227 | ?></label> |
||
228 | <?php |
||
229 | $user_string = ''; |
||
230 | $user_id = ''; |
||
231 | if ( ! empty( $order->customer_user ) ) { |
||
232 | $user_id = absint( $order->customer_user ); |
||
233 | $user = get_user_by( 'id', $user_id ); |
||
234 | $user_string = esc_html( $user->display_name ) . ' (#' . absint( $user->ID ) . ' – ' . esc_html( $user->user_email ) . ')'; |
||
235 | } |
||
236 | ?> |
||
237 | <input type="hidden" class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php esc_attr_e( 'Guest', 'woocommerce' ); ?>" data-selected="<?php echo htmlspecialchars( $user_string ); ?>" value="<?php echo $user_id; ?>" data-allow_clear="true" /> |
||
238 | </p> |
||
239 | <?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?> |
||
240 | </div> |
||
241 | <div class="order_data_column"> |
||
242 | <h3> |
||
243 | <?php _e( 'Billing Details', 'woocommerce' ); ?> |
||
244 | <a href="#" class="edit_address"><?php _e( 'Edit', 'woocommerce' ); ?></a> |
||
245 | <a href="#" class="tips load_customer_billing" data-tip="<?php esc_attr_e( 'Load billing address', 'woocommerce' ); ?>" style="display:none;"><?php _e( 'Load billing address', 'woocommerce' ); ?></a> |
||
246 | </h3> |
||
247 | <?php |
||
248 | // Display values |
||
249 | echo '<div class="address">'; |
||
250 | |||
251 | View Code Duplication | if ( $order->get_formatted_billing_address() ) { |
|
252 | echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>'; |
||
253 | } else { |
||
254 | echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No billing address set.', 'woocommerce' ) . '</p>'; |
||
255 | } |
||
256 | |||
257 | View Code Duplication | foreach ( self::$billing_fields as $key => $field ) { |
|
258 | if ( isset( $field['show'] ) && false === $field['show'] ) { |
||
259 | continue; |
||
260 | } |
||
261 | |||
262 | $field_name = 'billing_' . $key; |
||
263 | |||
264 | if ( $order->$field_name ) { |
||
265 | echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $order->$field_name ) ) . '</p>'; |
||
266 | } |
||
267 | } |
||
268 | |||
269 | echo '</div>'; |
||
270 | |||
271 | // Display form |
||
272 | echo '<div class="edit_address">'; |
||
273 | |||
274 | View Code Duplication | foreach ( self::$billing_fields as $key => $field ) { |
|
275 | if ( ! isset( $field['type'] ) ) { |
||
276 | $field['type'] = 'text'; |
||
277 | } |
||
278 | if ( ! isset( $field['id'] ) ){ |
||
279 | $field['id'] = '_billing_' . $key; |
||
280 | } |
||
281 | switch ( $field['type'] ) { |
||
282 | case 'select' : |
||
283 | woocommerce_wp_select( $field ); |
||
284 | break; |
||
285 | default : |
||
286 | woocommerce_wp_text_input( $field ); |
||
287 | break; |
||
288 | } |
||
289 | } |
||
290 | ?> |
||
291 | <p class="form-field form-field-wide"> |
||
292 | <label><?php _e( 'Payment Method:', 'woocommerce' ); ?></label> |
||
293 | <select name="_payment_method" id="_payment_method" class="first"> |
||
294 | <option value=""><?php _e( 'N/A', 'woocommerce' ); ?></option> |
||
295 | <?php |
||
296 | $found_method = false; |
||
297 | |||
298 | foreach ( $payment_gateways as $gateway ) { |
||
299 | if ( $gateway->enabled == "yes" ) { |
||
300 | echo '<option value="' . esc_attr( $gateway->id ) . '" ' . selected( $payment_method, $gateway->id, false ) . '>' . esc_html( $gateway->get_title() ) . '</option>'; |
||
301 | if ( $payment_method == $gateway->id ) { |
||
302 | $found_method = true; |
||
303 | } |
||
304 | } |
||
305 | } |
||
306 | |||
307 | View Code Duplication | if ( ! $found_method && ! empty( $payment_method ) ) { |
|
308 | echo '<option value="' . esc_attr( $payment_method ) . '" selected="selected">' . __( 'Other', 'woocommerce' ) . '</option>'; |
||
309 | } else { |
||
310 | echo '<option value="other">' . __( 'Other', 'woocommerce' ) . '</option>'; |
||
311 | } |
||
312 | ?> |
||
313 | </select> |
||
314 | </p> |
||
315 | <?php |
||
316 | |||
317 | woocommerce_wp_text_input( array( 'id' => '_transaction_id', 'label' => __( 'Transaction ID', 'woocommerce' ) ) ); |
||
318 | |||
319 | echo '</div>'; |
||
320 | |||
321 | do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); |
||
322 | ?> |
||
323 | </div> |
||
324 | <div class="order_data_column"> |
||
325 | |||
326 | <h3> |
||
327 | <?php _e( 'Shipping Details', 'woocommerce' ); ?> |
||
328 | <a href="#" class="edit_address"><?php _e( 'Edit', 'woocommerce' ); ?></a> |
||
329 | <a href="#" class="tips billing-same-as-shipping" data-tip="<?php esc_attr_e( 'Copy from billing', 'woocommerce' ); ?>" style="display:none;"><?php _e( 'Copy from billing', 'woocommerce' ); ?></a> |
||
330 | <a href="#" class="tips load_customer_shipping" data-tip="<?php esc_attr_e( 'Load shipping address', 'woocommerce' ); ?>" style="display:none;"><?php _e( 'Load shipping address', 'woocommerce' ); ?></a> |
||
331 | </h3> |
||
332 | <?php |
||
333 | // Display values |
||
334 | echo '<div class="address">'; |
||
335 | |||
336 | View Code Duplication | if ( $order->get_formatted_shipping_address() ) { |
|
337 | echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong>' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '</p>'; |
||
338 | } else { |
||
339 | echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No shipping address set.', 'woocommerce' ) . '</p>'; |
||
340 | } |
||
341 | |||
342 | if ( ! empty( self::$shipping_fields ) ) { |
||
343 | View Code Duplication | foreach ( self::$shipping_fields as $key => $field ) { |
|
344 | if ( isset( $field['show'] ) && false === $field['show'] ) { |
||
345 | continue; |
||
346 | } |
||
347 | |||
348 | $field_name = 'shipping_' . $key; |
||
349 | |||
350 | if ( ! empty( $order->$field_name ) ) { |
||
351 | echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $order->$field_name ) ) . '</p>'; |
||
352 | } |
||
353 | } |
||
354 | } |
||
355 | |||
356 | if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) { |
||
357 | echo '<p><strong>' . __( 'Customer Provided Note', 'woocommerce' ) . ':</strong> ' . nl2br( esc_html( $post->post_excerpt ) ) . '</p>'; |
||
358 | } |
||
359 | |||
360 | echo '</div>'; |
||
361 | |||
362 | // Display form |
||
363 | echo '<div class="edit_address">'; |
||
364 | |||
365 | if ( ! empty( self::$shipping_fields ) ) { |
||
366 | View Code Duplication | foreach ( self::$shipping_fields as $key => $field ) { |
|
367 | if ( ! isset( $field['type'] ) ) { |
||
368 | $field['type'] = 'text'; |
||
369 | } |
||
370 | if ( ! isset( $field['id'] ) ){ |
||
371 | $field['id'] = '_shipping_' . $key; |
||
372 | } |
||
373 | |||
374 | switch ( $field['type'] ) { |
||
375 | case 'select' : |
||
376 | woocommerce_wp_select( $field ); |
||
377 | break; |
||
378 | default : |
||
379 | woocommerce_wp_text_input( $field ); |
||
380 | break; |
||
381 | } |
||
382 | } |
||
383 | } |
||
384 | |||
385 | if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) { |
||
386 | ?> |
||
387 | <p class="form-field form-field-wide"><label for="excerpt"><?php _e( 'Customer Provided Note', 'woocommerce' ) ?>:</label> |
||
388 | <textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer\'s notes about the order', 'woocommerce' ); ?>"><?php echo wp_kses_post( $post->post_excerpt ); ?></textarea></p> |
||
389 | <?php |
||
390 | } |
||
391 | |||
392 | echo '</div>'; |
||
393 | |||
394 | do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); |
||
395 | ?> |
||
396 | </div> |
||
397 | </div> |
||
398 | <div class="clear"></div> |
||
399 | </div> |
||
400 | </div> |
||
401 | <?php |
||
402 | } |
||
403 | |||
510 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.