Conditions | 9 |
Paths | 68 |
Total Lines | 127 |
Code Lines | 88 |
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 | global $wpinv_euvat, $ajax_cart_details; |
||
16 | |||
17 | $post_id = ! empty( $post->ID ) ? $post->ID : 0; |
||
|
|||
18 | $items = get_post_meta( $post->ID, 'wpinv_payment_items', true ); |
||
19 | $supports_discounts = (int) get_post_meta( $post->ID, 'wpinv_form_supports_discounts', true ); |
||
20 | $supports_quantities = (int) get_post_meta( $post->ID, 'wpinv_form_supports_quantities', true ); |
||
21 | $enable_taxes = (int) get_post_meta( $post->ID, 'wpinv_form_supports_quantities', true ); |
||
22 | $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
||
23 | |||
24 | if ( empty( $items ) || ! is_array( $items ) ) { |
||
25 | $items = array(); |
||
26 | } |
||
27 | |||
28 | ?> |
||
29 | |||
30 | <div class="wpinv-items-wrap-pending" id="wpinv_items_wrap"> |
||
31 | <table |
||
32 | id="wpinv_items" |
||
33 | class="wpinv-items" |
||
34 | cellspacing="0" |
||
35 | cellpadding="0" |
||
36 | data-supports-discouts="<?php echo $supports_discounts; ?>" |
||
37 | data-supports-discouts="<?php echo $supports_quantities; ?>" |
||
38 | data-supports-discouts="<?php echo $enable_taxes; ?>" |
||
39 | data-decimal-places="<?php echo esc_attr( wpinv_decimals() ); ?>" |
||
40 | data-currency-symbol="<?php echo esc_attr( wpinv_currency_symbol() ); ?>" |
||
41 | data-currency-position="<?php echo esc_attr( wpinv_currency_position() ); ?>" |
||
42 | > |
||
43 | |||
44 | <thead> |
||
45 | <tr> |
||
46 | <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
||
47 | <th class="title"><?php _e( 'Name', 'invoicing' );?></th> |
||
48 | <th class="desc"><?php _e( 'Description', 'invoicing' );?></th> |
||
49 | <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
||
50 | <th class="action"></th> |
||
51 | </tr> |
||
52 | </thead> |
||
53 | |||
54 | <tbody class="wpinv-line-items"> |
||
55 | <?php |
||
56 | |||
57 | foreach ( $items as $item ) { |
||
58 | $id = isset( $item['id'] ) ? (int) $item['id'] : 0; |
||
59 | $name = isset( $item['name'] ) ? sanitize_text_field( $item['name'] ) : __( 'No name', 'invoicing' ); |
||
60 | $price = isset( $item['price'] ) ? wpinv_format_amount( $item['price'] ) : 0.00; |
||
61 | $description = isset( $item['description'] ) ? esc_textarea( $item['description'] ) : ''; |
||
62 | |||
63 | ?> |
||
64 | |||
65 | <tr class="item" data-item-id="<?php echo $id; ?>"> |
||
66 | <td class="id"><?php echo $id; ?></td> |
||
67 | <td class="title"> |
||
68 | <a href="<?php echo esc_url( get_edit_post_link( $id ) ); ?>" target="_blank"><?php echo $name ; ?></a> |
||
69 | <?php echo wpinv_get_item_suffix( $id ); ?> |
||
70 | </td> |
||
71 | <td class="meta"> |
||
72 | <?php echo $description ; ?> |
||
73 | </td> |
||
74 | <td class="price"> |
||
75 | <?php echo $price ; ?> |
||
76 | </td> |
||
77 | </tr> |
||
78 | |||
79 | <?php } ?> |
||
80 | |||
81 | </tbody> |
||
82 | </table> |
||
83 | <div id="wpinv-quick-add" style="display: none;"> |
||
84 | <table cellspacing="0" cellpadding="0"> |
||
85 | <tr> |
||
86 | <td class="id"> |
||
87 | </td> |
||
88 | <td class="title"> |
||
89 | <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]"> |
||
90 | |||
91 | <div class="wp-clearfix"> |
||
92 | <label class="wpi-item-type"> |
||
93 | <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
||
94 | </label> |
||
95 | </div> |
||
96 | |||
97 | <div class="wp-clearfix"> |
||
98 | <?php |
||
99 | echo wpinv_html_textarea( array( |
||
100 | 'name' => '_wpinv_quick[excerpt]', |
||
101 | 'id' => '_wpinv_quick_excerpt', |
||
102 | 'value' => '', |
||
103 | 'class' => 'large-text', |
||
104 | 'label' => __( 'Item description', 'invoicing' ), |
||
105 | ) ); |
||
106 | ?> |
||
107 | </div> |
||
108 | |||
109 | <div class="wp-clearfix"> |
||
110 | <label class="wpi-item-actions"> |
||
111 | <span class="input-text-wrap"> |
||
112 | <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
||
113 | </span> |
||
114 | </label> |
||
115 | </div> |
||
116 | </td> |
||
117 | |||
118 | <td class="price"> |
||
119 | <input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /> |
||
120 | </td> |
||
121 | |||
122 | <td class="action"></td> |
||
123 | </tr> |
||
124 | </table> |
||
125 | </div> |
||
126 | <div class="wpinv-actions"> |
||
127 | |||
128 | <?php |
||
129 | |||
130 | echo wpinv_item_dropdown( array( |
||
131 | 'name' => 'wpinv_invoice_item', |
||
132 | 'id' => 'wpinv_invoice_item', |
||
133 | 'show_recurring' => true, |
||
134 | 'class' => 'wpi_select2', |
||
135 | ) ); |
||
136 | |||
137 | ?> |
||
138 | |||
139 | <input type="button" value="<?php esc_attr_e( 'Add item to form', 'invoicing'); ?>" class="button button-primary" id="wpinv-add-item" /> |
||
140 | <input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item" /> |
||
141 | |||
253 |