Conditions | 10 |
Paths | 38 |
Total Lines | 100 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
14 | public static function output( $post ) { |
||
15 | |||
16 | $items = get_post_meta( $post->ID, 'wpinv_payment_form_items', true ); |
||
17 | |||
18 | if ( empty( $items ) || ! is_array( $items ) ) { |
||
19 | $items = array(); |
||
20 | } |
||
21 | |||
22 | ?> |
||
23 | |||
24 | <div class="wpinv-items-wrap-pending" id="wpinv_items_wrap"> |
||
25 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
||
26 | |||
27 | <thead> |
||
28 | <tr> |
||
29 | <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
||
30 | <th class="title"><?php _e( 'Name', 'invoicing' );?></th> |
||
31 | <th class="desc"><?php _e( 'Description', 'invoicing' );?></th> |
||
32 | <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
||
33 | <th class="action"></th> |
||
34 | </tr> |
||
35 | </thead> |
||
36 | |||
37 | <tbody class="wpinv-line-items"> |
||
38 | <?php |
||
39 | |||
40 | foreach ( $items as $item_data ) { |
||
41 | |||
42 | $id = isset( $item['id'] ) ? (int) $item['id'] : 0; |
||
43 | $item = new WPInv_Item( $id ); |
||
44 | |||
45 | if ( empty( $item ) || $item->post_type != 'wpi_item' ) { |
||
|
|||
46 | continue; |
||
47 | } |
||
48 | |||
49 | $name = isset( $item_data['name'] ) ? sanitize_text_field( $item_data['name'] ) : $item->get_name(); |
||
50 | $price = isset( $item_data['price'] ) ? wpinv_format_amount( $item_data['price'] ) : $item->get_price(); |
||
51 | $description = isset( $item_data['description'] ) ? esc_textarea( $item_data['description'] ) : $item->get_summary(); |
||
52 | |||
53 | ?> |
||
54 | |||
55 | <tr class="item" data-item-id="<?php echo $id; ?>"> |
||
56 | <td class="id"><?php echo $id; ?></td> |
||
57 | <td class="title"> |
||
58 | <a href="<?php echo esc_url( get_edit_post_link( $id ) ); ?>" target="_blank"><?php echo $name ; ?></a> |
||
59 | <?php echo wpinv_get_item_suffix( $id ); ?> |
||
60 | </td> |
||
61 | <td class="meta"> |
||
62 | <?php echo $description ; ?> |
||
63 | </td> |
||
64 | <td class="price"> |
||
65 | <?php echo $price ; ?> |
||
66 | </td> |
||
67 | </tr> |
||
68 | |||
69 | <?php } ?> |
||
70 | |||
71 | <tr class="item create-item" style="display:none;" id="wpinv-payment-form-quick-add"> |
||
72 | <td class="id"></td> |
||
73 | |||
74 | <td class="title"> |
||
75 | <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" id="wpinv_create_payment_form_item_name" /> |
||
76 | |||
77 | <div class="wp-clearfix"> |
||
78 | <label class="wpi-item-actions"> |
||
79 | <span class="input-text-wrap"> |
||
80 | <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-payment-form-save-item"> |
||
81 | <input type="button" value="Cancel" class="button button-secondary" id="wpinv-payment-form-cancel-item"> |
||
82 | </span> |
||
83 | </label> |
||
84 | </div> |
||
85 | </td> |
||
86 | |||
87 | <td class="meta"> |
||
88 | <textarea placeholder="<?php esc_attr_e( 'Item description', 'invoicing' ) ?>" id="wpinv_create_payment_form_item_description" class="large-text" rows="3"></textarea> |
||
89 | </td> |
||
90 | |||
91 | <td class="price"> |
||
92 | <input type="text" placeholder="0.00" class="wpi-field-price wpi-price" id="wpinv_create_payment_form_item_price" /> |
||
93 | </td> |
||
94 | |||
95 | </tr> |
||
96 | </tbody> |
||
97 | </table> |
||
98 | |||
99 | <div class="wpinv-actions"> |
||
100 | |||
101 | <?php |
||
102 | |||
103 | echo wpinv_item_dropdown( array( |
||
104 | 'name' => 'wpinv_payment_form_item', |
||
105 | 'id' => 'wpinv_payment_form_item', |
||
106 | 'show_recurring' => true, |
||
107 | 'class' => 'wpi_select2', |
||
108 | ) ); |
||
109 | |||
110 | ?> |
||
111 | |||
112 | <input type="button" value="<?php esc_attr_e( 'Add item to form', 'invoicing'); ?>" class="button button-primary" id="wpinv-payment-form-add-item" /> |
||
113 | <input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-payment-form-new-item" /> |
||
114 | |||
280 |