Conditions | 9 |
Paths | 24 |
Total Lines | 65 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
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 |
||
27 | public static function output( $post ) { |
||
28 | global $theorder; |
||
29 | |||
30 | // This is used by some callbacks attached to hooks such as woocommerce_order_actions which rely on the global to determine if actions should be displayed for certain orders. |
||
31 | if ( ! is_object( $theorder ) ) { |
||
32 | $theorder = wc_get_order( $post->ID ); |
||
33 | } |
||
34 | |||
35 | $order_type_object = get_post_type_object( $post->post_type ); |
||
36 | ?> |
||
37 | <ul class="order_actions submitbox"> |
||
38 | |||
39 | <?php do_action( 'woocommerce_order_actions_start', $post->ID ); ?> |
||
40 | |||
41 | <li class="wide" id="actions"> |
||
42 | <select name="wc_order_action"> |
||
43 | <option value=""><?php _e( 'Actions', 'woocommerce' ); ?></option> |
||
44 | <optgroup label="<?php esc_attr_e( 'Resend order emails', 'woocommerce' ); ?>"> |
||
45 | <?php |
||
46 | $mailer = WC()->mailer(); |
||
47 | $available_emails = apply_filters( 'woocommerce_resend_order_emails_available', array( 'new_order', 'cancelled_order', 'customer_processing_order', 'customer_completed_order', 'customer_invoice', 'customer_refunded_order' ) ); |
||
48 | $mails = $mailer->get_emails(); |
||
49 | |||
50 | if ( ! empty( $mails ) ) { |
||
51 | foreach ( $mails as $mail ) { |
||
52 | if ( in_array( $mail->id, $available_emails ) && 'no' !== $mail->enabled ) { |
||
53 | echo '<option value="send_email_'. esc_attr( $mail->id ) .'">' . esc_html( $mail->title ) . '</option>'; |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | ?> |
||
58 | </optgroup> |
||
59 | |||
60 | <option value="regenerate_download_permissions"><?php _e( 'Regenerate download permissions', 'woocommerce' ); ?></option> |
||
61 | |||
62 | <?php foreach( apply_filters( 'woocommerce_order_actions', array() ) as $action => $title ) { ?> |
||
63 | <option value="<?php echo $action; ?>"><?php echo $title; ?></option> |
||
64 | <?php } ?> |
||
65 | </select> |
||
66 | |||
67 | <button class="button wc-reload" title="<?php esc_attr_e( 'Apply', 'woocommerce' ); ?>"><span><?php _e( 'Apply', 'woocommerce' ); ?></span></button> |
||
68 | </li> |
||
69 | |||
70 | <li class="wide"> |
||
71 | <div id="delete-action"><?php |
||
72 | |||
73 | if ( current_user_can( 'delete_post', $post->ID ) ) { |
||
74 | |||
75 | if ( ! EMPTY_TRASH_DAYS ) { |
||
76 | $delete_text = __( 'Delete Permanently', 'woocommerce' ); |
||
77 | } else { |
||
78 | $delete_text = __( 'Move to Trash', 'woocommerce' ); |
||
79 | } |
||
80 | ?><a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo $delete_text; ?></a><?php |
||
81 | } |
||
82 | ?></div> |
||
83 | |||
84 | <input type="submit" class="button save_order button-primary tips" name="save" value="<?php printf( __( 'Save %s', 'woocommerce' ), $order_type_object->labels->singular_name ); ?>" data-tip="<?php printf( __( 'Save/update the %s', 'woocommerce' ), $order_type_object->labels->singular_name ); ?>" /> |
||
85 | </li> |
||
86 | |||
87 | <?php do_action( 'woocommerce_order_actions_end', $post->ID ); ?> |
||
88 | |||
89 | </ul> |
||
90 | <?php |
||
91 | } |
||
92 | |||
174 |
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.