Conditions | 13 |
Paths | 1024 |
Total Lines | 212 |
Code Lines | 140 |
Lines | 30 |
Ratio | 14.15 % |
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 |
||
131 | function wpinv_discount_metabox_details( $post ) { |
||
132 | $discount_id = $post->ID; |
||
133 | $discount = wpinv_get_discount( $discount_id ); |
||
134 | |||
135 | $type = wpinv_get_discount_type( $discount_id ); |
||
136 | $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
||
137 | $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
||
138 | $min_total = wpinv_get_discount_min_total( $discount_id ); |
||
139 | $max_total = wpinv_get_discount_max_total( $discount_id ); |
||
140 | $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
||
141 | $single_use = wpinv_discount_is_single_use( $discount_id ); |
||
142 | $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
||
143 | $start_date = wpinv_get_discount_start_date( $discount_id ); |
||
144 | $expiration_date = wpinv_get_discount_expiration( $discount_id ); |
||
145 | |||
146 | View Code Duplication | if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) { |
|
147 | $start_time = strtotime( $start_date ); |
||
148 | $start_h = date_i18n( 'H', $start_time ); |
||
149 | $start_m = date_i18n( 'i', $start_time ); |
||
150 | $start_date = date_i18n( 'Y-m-d', $start_time ); |
||
151 | } else { |
||
152 | $start_h = '00'; |
||
153 | $start_m = '00'; |
||
154 | } |
||
155 | |||
156 | View Code Duplication | if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) { |
|
157 | $expiration_time = strtotime( $expiration_date ); |
||
158 | $expiration_h = date_i18n( 'H', $expiration_time ); |
||
159 | $expiration_m = date_i18n( 'i', $expiration_time ); |
||
160 | $expiration_date = date_i18n( 'Y-m-d', $expiration_time ); |
||
161 | } else { |
||
162 | $expiration_h = '23'; |
||
163 | $expiration_m = '59'; |
||
164 | } |
||
165 | |||
166 | $min_total = $min_total > 0 ? $min_total : ''; |
||
167 | $max_total = $max_total > 0 ? $max_total : ''; |
||
168 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
||
169 | ?> |
||
170 | <?php do_action( 'wpinv_discount_form_top', $post ); ?> |
||
171 | <?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
||
172 | <table class="form-table wpi-form-table"> |
||
173 | <tbody> |
||
174 | <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
||
175 | <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
||
176 | <tr> |
||
177 | <th valign="top" scope="row"> |
||
178 | <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
||
179 | </th> |
||
180 | <td> |
||
181 | <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
||
182 | <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
||
183 | </td> |
||
184 | </tr> |
||
185 | <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
||
186 | <tr> |
||
187 | <th valign="top" scope="row"> |
||
188 | <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
||
189 | </th> |
||
190 | <td> |
||
191 | <select id="wpinv_discount_type" name="type" class="medium-text"> |
||
192 | <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
||
193 | <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
||
194 | <?php } ?> |
||
195 | </select> |
||
196 | <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
||
197 | </td> |
||
198 | </tr> |
||
199 | <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
||
200 | <tr> |
||
201 | <th valign="top" scope="row"> |
||
202 | <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
||
203 | </th> |
||
204 | <td> |
||
205 | <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font> |
||
206 | <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
||
207 | <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
||
208 | </td> |
||
209 | </tr> |
||
210 | <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
||
211 | <tr> |
||
212 | <th valign="top" scope="row"> |
||
213 | <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
||
214 | </th> |
||
215 | <td> |
||
216 | <p><?php echo wpinv_item_dropdown( array( |
||
217 | 'name' => 'items[]', |
||
218 | 'id' => 'items', |
||
219 | 'selected' => $item_reqs, |
||
220 | 'multiple' => true, |
||
221 | 'class' => 'medium-text', |
||
222 | 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
||
223 | 'show_recurring' => true, |
||
224 | ) ); ?> |
||
225 | </p> |
||
226 | <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p> |
||
227 | </td> |
||
228 | </tr> |
||
229 | <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
||
230 | <tr> |
||
231 | <th valign="top" scope="row"> |
||
232 | <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
||
233 | </th> |
||
234 | <td> |
||
235 | <p><?php echo wpinv_item_dropdown( array( |
||
236 | 'name' => 'excluded_items[]', |
||
237 | 'id' => 'excluded_items', |
||
238 | 'selected' => $excluded_items, |
||
239 | 'multiple' => true, |
||
240 | 'class' => 'medium-text', |
||
241 | 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
||
242 | 'show_recurring' => true, |
||
243 | ) ); ?> |
||
244 | </p> |
||
245 | <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
||
246 | </td> |
||
247 | </tr> |
||
248 | <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
||
249 | <tr> |
||
250 | <th valign="top" scope="row"> |
||
251 | <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label> |
||
252 | </th> |
||
253 | <td> |
||
254 | <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
||
255 | View Code Duplication | <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
256 | <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option> |
||
257 | <?php } ?> |
||
258 | </select> : <select id="wpinv_discount_start_m" name="start_m"> |
||
259 | View Code Duplication | <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
260 | <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option> |
||
261 | <?php } ?> |
||
262 | </select> |
||
263 | <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p> |
||
264 | </td> |
||
265 | </tr> |
||
266 | <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
||
267 | <tr> |
||
268 | <th valign="top" scope="row"> |
||
269 | <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label> |
||
270 | </th> |
||
271 | <td> |
||
272 | <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
||
273 | View Code Duplication | <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
274 | <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option> |
||
275 | <?php } ?> |
||
276 | </select> : <select id="wpinv_discount_expiration_m" name="expiration_m"> |
||
277 | View Code Duplication | <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
278 | <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option> |
||
279 | <?php } ?> |
||
280 | </select> |
||
281 | <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p> |
||
282 | </td> |
||
283 | </tr> |
||
284 | <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
||
285 | <tr> |
||
286 | <th valign="top" scope="row"> |
||
287 | <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
||
288 | </th> |
||
289 | <td> |
||
290 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
||
291 | <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
||
292 | </td> |
||
293 | </tr> |
||
294 | <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
||
295 | <tr> |
||
296 | <th valign="top" scope="row"> |
||
297 | <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
||
298 | </th> |
||
299 | <td> |
||
300 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
||
301 | <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
||
302 | </td> |
||
303 | </tr> |
||
304 | <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
||
305 | <tr> |
||
306 | <th valign="top" scope="row"> |
||
307 | <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
||
308 | </th> |
||
309 | <td> |
||
310 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text"> |
||
311 | <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
||
312 | <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
||
313 | </select> |
||
314 | <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p> |
||
315 | </td> |
||
316 | </tr> |
||
317 | <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
||
318 | <tr> |
||
319 | <th valign="top" scope="row"> |
||
320 | <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
||
321 | </th> |
||
322 | <td> |
||
323 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
||
324 | <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
||
325 | </td> |
||
326 | </tr> |
||
327 | <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
||
328 | <tr> |
||
329 | <th valign="top" scope="row"> |
||
330 | <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
||
331 | </th> |
||
332 | <td> |
||
333 | <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
||
334 | <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
||
335 | </td> |
||
336 | </tr> |
||
337 | <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
||
338 | </tbody> |
||
339 | </table> |
||
340 | <?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
||
341 | <?php |
||
342 | } |
||
343 | |||
373 | add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: