Conditions | 9 |
Paths | 16 |
Total Lines | 326 |
Code Lines | 169 |
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 |
||
341 | public static function output2( $post ) { |
||
342 | |||
343 | // Prepare the invoice. |
||
344 | $invoice = new WPInv_Invoice( $post ); |
||
345 | |||
346 | // Invoice items. |
||
347 | $items = $invoice->get_items(); |
||
348 | |||
349 | $totals = array( |
||
350 | |||
351 | 'subtotal' => array( |
||
352 | 'label' => __( 'Items Subtotal', 'invoicing' ), |
||
353 | 'value' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
||
354 | ), |
||
355 | |||
356 | 'discount' => array( |
||
357 | 'label' => __( 'Total Discount', 'invoicing' ), |
||
358 | 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
||
359 | ), |
||
360 | |||
361 | 'tax' => array( |
||
362 | 'label' => __( 'Total Tax', 'invoicing' ), |
||
363 | 'value' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
||
364 | ), |
||
365 | |||
366 | 'total' => array( |
||
367 | 'label' => __( 'Invoice Total', 'invoicing' ), |
||
368 | 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
||
369 | ) |
||
370 | ); |
||
371 | |||
372 | if ( ! wpinv_use_taxes() ) { |
||
373 | unset( $totals['tax'] ); |
||
374 | } |
||
375 | |||
376 | $item_args = array( |
||
377 | 'post_type' => 'wpi_item', |
||
378 | 'orderby' => 'title', |
||
379 | 'order' => 'ASC', |
||
380 | 'posts_per_page' => -1, |
||
381 | 'post_status' => array( 'publish' ), |
||
382 | 'meta_query' => array( |
||
383 | array( |
||
384 | 'key' => '_wpinv_type', |
||
385 | 'compare' => '!=', |
||
386 | 'value' => 'package' |
||
387 | ) |
||
388 | ) |
||
389 | ); |
||
390 | |||
391 | ?> |
||
392 | |||
393 | <style> |
||
394 | #poststuff .input-group-text, |
||
395 | #poststuff .form-control { |
||
396 | border-color: #7e8993; |
||
397 | } |
||
398 | |||
399 | #wpinv-details label { |
||
400 | margin-bottom: 3px; |
||
401 | font-weight: 600; |
||
402 | } |
||
403 | </style> |
||
404 | |||
405 | <div class="bsui getpaid-invoice-items-inner <?php echo empty( $items ) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem; padding: 0 12px 12px;"> |
||
406 | |||
407 | <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
||
408 | <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
||
409 | |||
410 | <div class="row"> |
||
411 | <div class="col-12 col-sm-6"> |
||
412 | <?php |
||
413 | echo aui()->select( |
||
414 | array( |
||
415 | 'id' => 'wpinv_template', |
||
416 | 'name' => 'wpinv_template', |
||
417 | 'label' => __( 'Template', 'invoicing' ), |
||
418 | 'label_type' => 'vertical', |
||
419 | 'placeholder' => __( 'Choose a template', 'invoicing' ), |
||
420 | 'class' => 'form-control-sm', |
||
421 | 'value' => $invoice->get_template( 'edit' ), |
||
422 | 'options' => array( |
||
423 | 'quantity' => __( 'Quantity', 'invoicing' ), |
||
424 | 'hours' => __( 'Hours', 'invoicing' ), |
||
425 | 'amount' => __( 'Amount Only', 'invoicing' ), |
||
426 | ), |
||
427 | 'data-allow-clear' => 'false', |
||
428 | 'select2' => true, |
||
429 | ) |
||
430 | ); |
||
431 | ?> |
||
432 | </div> |
||
433 | <div class="col-12 col-sm-6"> |
||
434 | <?php |
||
435 | |||
436 | // Set currency. |
||
437 | echo aui()->select( |
||
438 | array( |
||
439 | 'id' => 'wpinv_currency', |
||
440 | 'name' => 'wpinv_currency', |
||
441 | 'label' => __( 'Currency', 'invoicing' ), |
||
442 | 'label_type' => 'vertical', |
||
443 | 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
||
444 | 'class' => 'form-control-sm', |
||
445 | 'value' => $invoice->get_currency( 'edit' ), |
||
446 | 'required' => false, |
||
447 | 'data-allow-clear' => 'false', |
||
448 | 'select2' => true, |
||
449 | 'options' => wpinv_get_currencies(), |
||
450 | ) |
||
451 | ); |
||
452 | |||
453 | ?> |
||
454 | </div> |
||
455 | </div> |
||
456 | |||
457 | <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
||
458 | <?php endif; ?> |
||
459 | |||
460 | <table cellpadding="0" cellspacing="0" class="getpaid_invoice_items"> |
||
461 | <thead> |
||
462 | <tr> |
||
463 | <th class="getpaid-item" colspan="2"><?php _e( 'Item', 'invoicing' ) ?></th> |
||
464 | <th class="getpaid-quantity hide-if-amount text-right"> |
||
465 | <span class="getpaid-hide-if-hours"><?php _e( 'Quantity', 'invoicing' ) ?></span> |
||
466 | <span class="getpaid-hide-if-quantity"><?php _e( 'Hours', 'invoicing' ) ?></span> |
||
467 | </th> |
||
468 | <th class="getpaid-price hide-if-amount text-right"> |
||
469 | <span class="getpaid-hide-if-hours"><?php _e( 'Price', 'invoicing' ) ?></span> |
||
470 | <span class="getpaid-hide-if-quantity"><?php _e( 'Rate', 'invoicing' ) ?></span> |
||
471 | </th> |
||
472 | <th class="getpaid-item-subtotal text-right"> |
||
473 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php _e( 'Amount', 'invoicing' ) ?></span> |
||
474 | <span class="hide-if-amount"><?php _e( 'Total', 'invoicing' ) ?></span> |
||
475 | </th> |
||
476 | <th class="getpaid-item-actions hide-if-not-editable" width="70px"> </th> |
||
477 | </tr> |
||
478 | </thead> |
||
479 | <tbody class="getpaid_invoice_line_items"> |
||
480 | <tr class="hide-if-has-items hide-if-not-editable"> |
||
481 | <td colspan="2" class="pt-4 pb-4"> |
||
482 | <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php _e( 'Add Existing Items', 'invoicing' ) ?></button> |
||
483 | <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php _e( 'Create New Item', 'invoicing' ) ?></button> |
||
484 | </td> |
||
485 | <td class="hide-if-amount"> </th> |
||
486 | <td class="hide-if-amount"> </th> |
||
487 | <td> </th> |
||
488 | <td width="1%"> </th> |
||
489 | </tr> |
||
490 | <tr class="getpaid-invoice-item-template d-none"> |
||
491 | <td class="getpaid-item" colspan="2"> |
||
492 | <span class='item-name'></span> |
||
493 | <small class="form-text text-muted item-description"></small> |
||
494 | </td> |
||
495 | <td class="getpaid-quantity hide-if-amount text-right item-quantity"></td> |
||
496 | <td class="getpaid-price hide-if-amount text-right item-price"></td> |
||
497 | <td class="getpaid-item-subtotal text-right"> |
||
498 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"></span> |
||
499 | <span class="hide-if-amount item-total"></span> |
||
500 | </td> |
||
501 | <td class="getpaid-item-actions hide-if-not-editable" width="70px"> |
||
502 | <span class="dashicons dashicons-edit"></span> |
||
503 | <span class="dashicons dashicons-trash"></span> |
||
504 | </td> |
||
505 | </tr> |
||
506 | |||
507 | </tbody> |
||
508 | </table> |
||
509 | |||
510 | <div class="getpaid-invoice-totals-row"> |
||
511 | <div class="row"> |
||
512 | <div class="col-12 col-sm-6 offset-sm-6"> |
||
513 | <table class="getpaid-invoice-totals text-right w-100"> |
||
514 | <tbody> |
||
515 | <?php foreach ( apply_filters( 'getpaid_invoice_subtotal_rows', $totals, $invoice ) as $key => $data ) : ?> |
||
516 | <tr class="getpaid-totals-<?php echo sanitize_html_class( $key ); ?>"> |
||
517 | <td class="label"><?php echo sanitize_text_field( $data['label'] ) ?>:</td> |
||
518 | <td width="1%"></td> |
||
519 | <td class="value"><?php echo wp_kses_post( $data['value'] ) ?></td> |
||
520 | </tr> |
||
521 | <?php endforeach; ?> |
||
522 | </tbody> |
||
523 | </table> |
||
524 | </div> |
||
525 | </div> |
||
526 | </div> |
||
527 | |||
528 | <!-- Actions --> |
||
529 | <div class="getpaid-invoice-item-actions hide-if-no-items hide-if-not-editable"> |
||
530 | <div class="row"> |
||
531 | <div class="text-left col-12 col-sm-8"> |
||
532 | <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php _e( 'Add Existing Item', 'invoicing' ) ?></button> |
||
533 | <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php _e( 'Create New Item', 'invoicing' ) ?></button> |
||
534 | <?php do_action( 'getpaid-invoice-items-actions', $invoice ); ?> |
||
535 | </div> |
||
536 | <div class="text-right col-12 col-sm-4"> |
||
537 | <button type="button" class="button button-primary recalculate-totals-button"><?php _e( 'Recalculate Totals', 'invoicing' ) ?></button> |
||
538 | </div> |
||
539 | </div> |
||
540 | </div> |
||
541 | |||
542 | <div class="getpaid-invoice-item-actions hide-if-editable"> |
||
543 | <p class="description m-2 text-right text-muted"><?php _e( 'This invoice is no longer editable', 'invoicing' ); ?></p> |
||
544 | </div> |
||
545 | |||
546 | <!-- Add items to an invoice --> |
||
547 | <div class="modal fade" id="getpaid-add-items-to-invoice" tabindex="-1" role="dialog" aria-labelledby="getpaid-add-item-to-invoice-label" aria-hidden="true"> |
||
548 | <div class="modal-dialog modal-dialog-centered" role="document"> |
||
549 | <div class="modal-content"> |
||
550 | <div class="modal-header"> |
||
551 | <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php _e( "Add Item(s)", 'invoicing' ); ?></h5> |
||
552 | <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e( "Close", 'invoicing' ); ?>"> |
||
553 | <span aria-hidden="true">×</span> |
||
554 | </button> |
||
555 | </div> |
||
556 | <div class="modal-body"> |
||
557 | <table class="widefat"> |
||
558 | <thead> |
||
559 | <tr> |
||
560 | <th class="pl-0 text-left"><?php _e( 'Item', 'invoicing' ) ?></th> |
||
561 | <th class="pr-0 text-right hide-if-amount"> |
||
562 | <span class="getpaid-hide-if-hours"><?php _e( 'Quantity', 'invoicing' ) ?></span> |
||
563 | <span class="getpaid-hide-if-quantity"><?php _e( 'Hours', 'invoicing' ) ?></span> |
||
564 | </th> |
||
565 | </tr> |
||
566 | </thead> |
||
567 | <tbody> |
||
568 | <tr> |
||
569 | <td class="pl-0 text-left"> |
||
570 | <select class="regular-text getpaid-add-invoice-item-select"> |
||
571 | <option value="" selected="selected" disabled><?php esc_html_e( 'Select an item…', 'invoicing' ); ?></option> |
||
572 | <?php foreach ( get_posts( $item_args ) as $item ) : ?> |
||
573 | <option value="<?php echo (int) $item->ID; ?>"><?php echo strip_tags( $item->post_title ); ?></option> |
||
574 | <?php endforeach; ?> |
||
575 | </select> |
||
576 | </td> |
||
577 | <td class="pr-0 text-right hide-if-amount"> |
||
578 | <input type="number" class="w100" step="1" min="1" autocomplete="off" value="1" placeholder="1"> |
||
579 | </td> |
||
580 | </tr> |
||
581 | </tbody> |
||
582 | </table> |
||
583 | </div> |
||
584 | <div class="modal-footer"> |
||
585 | <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e( 'Cancel', 'invoicing' ); ?></button> |
||
586 | <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php _e( 'Add', 'invoicing' ); ?></button> |
||
587 | </div> |
||
588 | </div> |
||
589 | </div> |
||
590 | </div> |
||
591 | |||
592 | <!-- Create invoice item --> |
||
593 | <div class="modal fade" id="getpaid-create-invoice-item" tabindex="-1" role="dialog" aria-labelledby="getpaid-create-invoice-item-label" aria-hidden="true"> |
||
594 | <div class="modal-dialog modal-dialog-centered" role="document"> |
||
595 | <div class="modal-content"> |
||
596 | <div class="modal-header"> |
||
597 | <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php _e( "Create Item", 'invoicing' ); ?></h5> |
||
598 | <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e( "Close", 'invoicing' ); ?>"> |
||
599 | <span aria-hidden="true">×</span> |
||
600 | </button> |
||
601 | </div> |
||
602 | <div class="modal-body"> |
||
603 | <div class="getpaid-create-item-div"> |
||
604 | <input type="hidden" name="id" value="new" class="form-control form-control-sm item-id"> |
||
605 | <label class="form-group w-100"> |
||
606 | <span><?php _e( 'Name', 'invoicing' ); ?></span> |
||
607 | <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
||
608 | </label> |
||
609 | <label class="form-group w-100"> |
||
610 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php _e( 'Amount', 'invoicing' ); ?></span> |
||
611 | <span class="hide-if-amount"><?php _e( 'Price', 'invoicing' ); ?></span> |
||
612 | <input type="text" name="price" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price"> |
||
613 | </label> |
||
614 | <label class="form-group w-100 hide-if-amount"> |
||
615 | <span><?php _e( 'Quantity', 'invoicing' ); ?></span> |
||
616 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
||
617 | </label> |
||
618 | <label class="form-group w-100"> |
||
619 | <span><?php _e( 'Item Description', 'invoicing' ); ?></span> |
||
620 | <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
||
621 | </label> |
||
622 | </div> |
||
623 | </div> |
||
624 | <div class="modal-footer"> |
||
625 | <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e( 'Cancel', 'invoicing' ); ?></button> |
||
626 | <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php _e( 'Create', 'invoicing' ); ?></button> |
||
627 | </div> |
||
628 | </div> |
||
629 | </div> |
||
630 | </div> |
||
631 | |||
632 | <!-- Edit invoice item --> |
||
633 | <div class="modal fade" id="getpaid-edit-invoice-item" tabindex="-1" role="dialog" aria-labelledby="getpaid-edit-invoice-item-label" aria-hidden="true"> |
||
634 | <div class="modal-dialog modal-dialog-centered" role="document"> |
||
635 | <div class="modal-content"> |
||
636 | <div class="modal-header"> |
||
637 | <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php _e( "Edit Item", 'invoicing' ); ?></h5> |
||
638 | <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e( "Close", 'invoicing' ); ?>"> |
||
639 | <span aria-hidden="true">×</span> |
||
640 | </button> |
||
641 | </div> |
||
642 | <div class="modal-body"> |
||
643 | <div class="getpaid-edit-item-div"> |
||
644 | <input type="hidden" name="id" class="form-control form-control-sm item-id"> |
||
645 | <label class="form-group w-100"> |
||
646 | <span><?php _e( 'Name', 'invoicing' ); ?></span> |
||
647 | <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
||
648 | </label> |
||
649 | <label class="form-group w-100"> |
||
650 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php _e( 'Amount', 'invoicing' ); ?></span> |
||
651 | <span class="hide-if-amount"><?php _e( 'Price', 'invoicing' ); ?></span> |
||
652 | <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price"> |
||
653 | </label> |
||
654 | <label class="form-group w-100 hide-if-amount"> |
||
655 | <span><?php _e( 'Quantity', 'invoicing' ); ?></span> |
||
656 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
||
657 | </label> |
||
658 | <label class="form-group w-100"> |
||
659 | <span><?php _e( 'Item Description', 'invoicing' ); ?></span> |
||
660 | <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
||
661 | </label> |
||
662 | </div> |
||
663 | </div> |
||
664 | <div class="modal-footer"> |
||
665 | <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e( 'Cancel', 'invoicing' ); ?></button> |
||
666 | <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php _e( 'Save', 'invoicing' ); ?></button> |
||
667 | </div> |
||
676 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.