Conditions | 24 |
Paths | 3072 |
Total Lines | 93 |
Code Lines | 71 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
8 | public static function output( $post ) { |
||
9 | $currency_symbol = wpinv_currency_symbol(); |
||
|
|||
10 | $statuses = wpinv_get_invoice_statuses( true ); |
||
11 | |||
12 | $post_id = !empty( $post->ID ) ? $post->ID : 0; |
||
13 | $invoice = new WPInv_Invoice( $post_id ); |
||
14 | |||
15 | $status = $invoice->get_status( false ); // Current status |
||
16 | $discount = $invoice->get_discount(); |
||
17 | $discount_code = $discount > 0 ? $invoice->get_discount_code() : ''; |
||
18 | $invoice_number = $invoice->get_number(); |
||
19 | |||
20 | $date_created = $invoice->get_created_date(); |
||
21 | $datetime_created = strtotime( $date_created ); |
||
22 | $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : ''; |
||
23 | $date_completed = $invoice->get_completed_date(); |
||
24 | $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a'; |
||
25 | $title['status'] = __( 'Invoice Status:', 'invoicing' ); |
||
26 | $title['number'] = __( 'Invoice Number:', 'invoicing' ); |
||
27 | $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user’s email address.', 'invoicing' ); |
||
28 | |||
29 | $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice); |
||
30 | $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice); |
||
31 | $mail_notice = apply_filters('wpinv_metabox_mail_notice', $mail_notice, $invoice); |
||
32 | $post_obj = get_post_type_object($invoice->post_type); |
||
33 | ?> |
||
34 | <div class="gdmbx2-wrap form-table"> |
||
35 | <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details"> |
||
36 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created"> |
||
37 | <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div> |
||
38 | <div class="gdmbx-td"><?php echo $date_created;?></div> |
||
39 | </div> |
||
40 | <?php if ( $invoice->post_type == 'wpi_invoice' && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft', 'draft' ) ) ) ) { ?> |
||
41 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue"> |
||
42 | <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div> |
||
43 | <div class="gdmbx-td"> |
||
44 | <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd"> |
||
45 | <p class="wpi-meta-row wpi-meta-desc"><?php _e( 'Leave blank to disable sending auto reminder for this invoice.', 'invoicing' );?></p> |
||
46 | </div> |
||
47 | </div> |
||
48 | <?php } ?> |
||
49 | <?php do_action( 'wpinv_meta_box_details_after_due_date', $post_id ); ?> |
||
50 | <?php if ( $date_completed && $date_completed != 'n/a' ) { ?> |
||
51 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed"> |
||
52 | <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div> |
||
53 | <div class="gdmbx-td"><?php echo $date_completed;?></div> |
||
54 | </div> |
||
55 | <?php } ?> |
||
56 | <?php $is_viewed = wpinv_is_invoice_viewed( $post_id ); ?> |
||
57 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-customer-viewed"> |
||
58 | <div class="gdmbx-th"><label><?php _e( 'Viewed by Customer:', 'invoicing' );?></label></div> |
||
59 | <div class="gdmbx-td"><?php ( 1 == $is_viewed ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?></div> |
||
60 | </div> |
||
61 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status"> |
||
62 | <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div> |
||
63 | <div class="gdmbx-td"> |
||
64 | <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select wpi_select2"> |
||
65 | <?php foreach ( $statuses as $value => $label ) { ?> |
||
66 | <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option> |
||
67 | <?php } ?> |
||
68 | </select> |
||
69 | </div> |
||
70 | </div> |
||
71 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout"> |
||
72 | <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div> |
||
73 | <div class="gdmbx-td"> |
||
74 | <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly> |
||
75 | </div> |
||
76 | </div> |
||
77 | <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); |
||
78 | $disable_discount = apply_filters('wpinv_disable_apply_discount', false, $invoice, $post_id); |
||
79 | ?> |
||
80 | <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) && !$disable_discount || $discount_code ) { ?> |
||
81 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout"> |
||
82 | <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div> |
||
83 | <div class="gdmbx-td"> |
||
84 | <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid && !$disable_discount ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
||
85 | </div> |
||
86 | </div> |
||
87 | <?php } ?> |
||
88 | </div> |
||
89 | </div> |
||
90 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout"> |
||
91 | <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label> |
||
92 | <select id="wpi_save_send" name="wpi_save_send" class="wpi_select2"> |
||
93 | <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option> |
||
94 | <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option> |
||
95 | </select> |
||
96 | </p> |
||
97 | <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p> |
||
98 | </div> |
||
99 | <?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?> |
||
100 | <?php |
||
101 | } |
||
254 |