Conditions | 17 |
Paths | > 20000 |
Total Lines | 191 |
Code Lines | 118 |
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 | global $wpinv_euvat, $ajax_cart_details; |
||
10 | |||
11 | $post_id = !empty( $post->ID ) ? $post->ID : 0; |
||
12 | $invoice = new WPInv_Invoice( $post_id ); |
||
13 | $ajax_cart_details = $invoice->get_cart_details(); |
||
14 | $subtotal = $invoice->get_subtotal( true ); |
||
15 | $discount_raw = $invoice->get_discount(); |
||
16 | $discount = wpinv_price( $discount_raw, $invoice->get_currency() ); |
||
|
|||
17 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : ''; |
||
18 | $tax = $invoice->get_tax( true ); |
||
19 | $total = $invoice->get_total( true ); |
||
20 | $item_quantities = wpinv_item_quantities_enabled(); |
||
21 | $use_taxes = wpinv_use_taxes(); |
||
22 | $item_types = wpinv_get_item_types(); |
||
23 | $is_recurring = $invoice->is_recurring(); |
||
24 | $post_type_object = get_post_type_object($invoice->post_type); |
||
25 | $type_title = $post_type_object->labels->singular_name; |
||
26 | |||
27 | if (isset($item_types['package'])) { |
||
28 | unset($item_types['package']); |
||
29 | } |
||
30 | |||
31 | $cols = 5; |
||
32 | if ( $item_quantities ) { |
||
33 | $cols++; |
||
34 | } |
||
35 | if ( $use_taxes ) { |
||
36 | $cols++; |
||
37 | } |
||
38 | $class = ''; |
||
39 | if ( $invoice->is_paid() ) { |
||
40 | $class .= ' wpinv-paid'; |
||
41 | } |
||
42 | if ( $is_recurring ) { |
||
43 | $class .= ' wpi-recurring'; |
||
44 | } |
||
45 | ?> |
||
46 | <div class="wpinv-items-wrap<?php echo $class; ?>" id="wpinv_items_wrap" data-status="<?php echo $invoice->status; ?>"> |
||
47 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
||
48 | <thead> |
||
49 | <tr> |
||
50 | <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
||
51 | <th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
||
52 | <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
||
53 | <?php if ( $item_quantities ) { ?> |
||
54 | <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
||
55 | <?php } ?> |
||
56 | <th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
||
57 | <?php if ( $use_taxes ) { ?> |
||
58 | <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
||
59 | <?php } ?> |
||
60 | <th class="action"></th> |
||
61 | </tr> |
||
62 | </thead> |
||
63 | <tbody class="wpinv-line-items"> |
||
64 | <?php echo wpinv_admin_get_line_items( $invoice ); ?> |
||
65 | </tbody> |
||
66 | <tfoot class="wpinv-totals"> |
||
67 | <tr> |
||
68 | <td colspan="<?php echo $cols; ?>" style="padding:0;border:0"> |
||
69 | <div id="wpinv-quick-add"> |
||
70 | <table cellspacing="0" cellpadding="0"> |
||
71 | <tr> |
||
72 | <td class="id"> |
||
73 | </td> |
||
74 | <td class="title"> |
||
75 | <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]"> |
||
76 | <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
||
77 | <div class="wp-clearfix"> |
||
78 | <label class="wpi-vat-rule"> |
||
79 | <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
||
80 | <span class="input-text-wrap"> |
||
81 | <?php echo wpinv_html_select( array( |
||
82 | 'options' => $wpinv_euvat->get_rules(), |
||
83 | 'name' => '_wpinv_quick[vat_rule]', |
||
84 | 'id' => '_wpinv_quick_vat_rule', |
||
85 | 'show_option_all' => false, |
||
86 | 'show_option_none' => false, |
||
87 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
||
88 | ) ); ?> |
||
89 | </span> |
||
90 | </label> |
||
91 | </div> |
||
92 | <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
||
93 | <div class="wp-clearfix"> |
||
94 | <label class="wpi-vat-class"> |
||
95 | <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
||
96 | <span class="input-text-wrap"> |
||
97 | <?php echo wpinv_html_select( array( |
||
98 | 'options' => $wpinv_euvat->get_all_classes(), |
||
99 | 'name' => '_wpinv_quick[vat_class]', |
||
100 | 'id' => '_wpinv_quick_vat_class', |
||
101 | 'show_option_all' => false, |
||
102 | 'show_option_none' => false, |
||
103 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
||
104 | ) ); ?> |
||
105 | </span> |
||
106 | </label> |
||
107 | </div> |
||
108 | <?php } ?> |
||
109 | <div class="wp-clearfix"> |
||
110 | <label class="wpi-item-type"> |
||
111 | <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
||
112 | <span class="input-text-wrap"> |
||
113 | <?php echo wpinv_html_select( array( |
||
114 | 'options' => $item_types, |
||
115 | 'name' => '_wpinv_quick[type]', |
||
116 | 'id' => '_wpinv_quick_type', |
||
117 | 'selected' => 'custom', |
||
118 | 'show_option_all' => false, |
||
119 | 'show_option_none' => false, |
||
120 | 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
||
121 | ) ); ?> |
||
122 | </span> |
||
123 | </label> |
||
124 | </div> |
||
125 | <div class="wp-clearfix"> |
||
126 | <label class="wpi-item-actions"> |
||
127 | <span class="input-text-wrap"> |
||
128 | <input type="button" value="Save" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
||
129 | </span> |
||
130 | </label> |
||
131 | </div> |
||
132 | </td> |
||
133 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
||
134 | <?php if ( $item_quantities ) { ?> |
||
135 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
||
136 | <?php } ?> |
||
137 | <td class="total"></td> |
||
138 | <?php if ( $use_taxes ) { ?> |
||
139 | <td class="tax"></td> |
||
140 | <?php } ?> |
||
141 | <td class="action"></td> |
||
142 | </tr> |
||
143 | </table> |
||
144 | </div> |
||
145 | </td> |
||
146 | </tr> |
||
147 | <tr class="clear"> |
||
148 | <td colspan="<?php echo $cols; ?>"></td> |
||
149 | </tr> |
||
150 | <tr class="totals"> |
||
151 | <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
||
152 | <td colspan="4"> |
||
153 | <table cellspacing="0" cellpadding="0"> |
||
154 | <tr class="subtotal"> |
||
155 | <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
||
156 | <td class="total"><?php echo $subtotal;?></td> |
||
157 | <td class="action"></td> |
||
158 | </tr> |
||
159 | <tr class="discount"> |
||
160 | <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
||
161 | <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
||
162 | <td class="action"></td> |
||
163 | </tr> |
||
164 | <?php if ( $use_taxes ) { ?> |
||
165 | <tr class="tax"> |
||
166 | <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
||
167 | <td class="total"><?php echo $tax;?></td> |
||
168 | <td class="action"></td> |
||
169 | </tr> |
||
170 | <?php } ?> |
||
171 | <tr class="total"> |
||
172 | <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td> |
||
173 | <td class="total"><?php echo $total;?></td> |
||
174 | <td class="action"></td> |
||
175 | </tr> |
||
176 | </table> |
||
177 | </td> |
||
178 | </tr> |
||
179 | </tfoot> |
||
180 | </table> |
||
181 | <div class="wpinv-actions"> |
||
182 | <?php |
||
183 | if ( !$invoice->is_paid() ) { |
||
184 | if ( !$invoice->is_recurring() ) { |
||
185 | echo wpinv_item_dropdown( array( |
||
186 | 'name' => 'wpinv_invoice_item', |
||
187 | 'id' => 'wpinv_invoice_item', |
||
188 | 'with_packages' => false, |
||
189 | 'show_recurring' => true, |
||
190 | ) ); |
||
191 | ?> |
||
192 | <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
||
193 | <?php } ?> |
||
194 | <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
||
195 | </div> |
||
196 | </div> |
||
197 | <?php |
||
198 | } |
||
199 | |||
426 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.