Conditions | 12 |
Paths | 128 |
Total Lines | 338 |
Code Lines | 201 |
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 |
||
487 | public static function output2( $post ) { |
||
488 | |||
489 | // Prepare the invoice. |
||
490 | $invoice = new WPInv_Invoice( $post ); |
||
491 | |||
492 | // Invoice items. |
||
493 | $items = $invoice->get_items(); |
||
494 | |||
495 | $totals = array( |
||
496 | |||
497 | 'subtotal' => array( |
||
498 | 'label' => __( 'Items Subtotal', 'invoicing' ), |
||
499 | 'value' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
||
500 | ), |
||
501 | |||
502 | 'discount' => array( |
||
503 | 'label' => __( 'Total Discount', 'invoicing' ), |
||
504 | 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
||
505 | ), |
||
506 | |||
507 | 'tax' => array( |
||
508 | 'label' => __( 'Total Tax', 'invoicing' ), |
||
509 | 'value' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
||
510 | ), |
||
511 | |||
512 | 'total' => array( |
||
513 | 'label' => __( 'Invoice Total', 'invoicing' ), |
||
514 | 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
||
515 | ), |
||
516 | ); |
||
517 | |||
518 | if ( ! wpinv_use_taxes() ) { |
||
519 | unset( $totals['tax'] ); |
||
520 | } |
||
521 | |||
522 | $item_args = array( |
||
523 | 'post_type' => 'wpi_item', |
||
524 | 'orderby' => 'title', |
||
525 | 'order' => 'ASC', |
||
526 | 'posts_per_page' => -1, |
||
527 | 'post_status' => array( 'publish' ), |
||
528 | 'meta_query' => array( |
||
529 | array( |
||
530 | 'key' => '_wpinv_type', |
||
531 | 'compare' => '!=', |
||
532 | 'value' => 'package', |
||
533 | ), |
||
534 | array( |
||
535 | 'key' => '_wpinv_one_time', |
||
536 | 'compare' => 'NOT EXISTS', |
||
537 | ), |
||
538 | ), |
||
539 | ); |
||
540 | |||
541 | ?> |
||
542 | |||
543 | <style> |
||
544 | #poststuff .input-group-text, |
||
545 | #poststuff .form-control { |
||
546 | border-color: #7e8993; |
||
547 | } |
||
548 | |||
549 | #wpinv-details label { |
||
550 | margin-bottom: 3px; |
||
551 | font-weight: 600; |
||
552 | } |
||
553 | </style> |
||
554 | |||
555 | <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;"> |
||
556 | |||
557 | <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
||
558 | <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
||
559 | |||
560 | <div class="row"> |
||
561 | <div class="col-12 col-sm-6"> |
||
562 | <?php |
||
563 | aui()->select( |
||
564 | array( |
||
565 | 'id' => 'wpinv_template', |
||
566 | 'name' => 'wpinv_template', |
||
567 | 'label' => __( 'Template', 'invoicing' ), |
||
568 | 'label_type' => 'vertical', |
||
569 | 'placeholder' => __( 'Choose a template', 'invoicing' ), |
||
570 | 'class' => 'form-control-sm', |
||
571 | 'value' => $invoice->get_template( 'edit' ), |
||
572 | 'options' => array( |
||
573 | 'quantity' => __( 'Quantity', 'invoicing' ), |
||
574 | 'hours' => __( 'Hours', 'invoicing' ), |
||
575 | 'amount' => __( 'Amount Only', 'invoicing' ), |
||
576 | ), |
||
577 | 'data-allow-clear' => 'false', |
||
578 | 'select2' => true, |
||
579 | ), |
||
580 | true |
||
581 | ); |
||
582 | ?> |
||
583 | </div> |
||
584 | <div class="col-12 col-sm-6"> |
||
585 | <?php |
||
586 | |||
587 | // Set currency. |
||
588 | aui()->select( |
||
589 | array( |
||
590 | 'id' => 'wpinv_currency', |
||
591 | 'name' => 'wpinv_currency', |
||
592 | 'label' => __( 'Currency', 'invoicing' ), |
||
593 | 'label_type' => 'vertical', |
||
594 | 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
||
595 | 'class' => 'form-control-sm', |
||
596 | 'value' => $invoice->get_currency( 'edit' ), |
||
597 | 'required' => false, |
||
598 | 'data-allow-clear' => 'false', |
||
599 | 'select2' => true, |
||
600 | 'options' => wpinv_get_currencies(), |
||
601 | ), |
||
602 | true |
||
603 | ); |
||
604 | |||
605 | ?> |
||
606 | </div> |
||
607 | </div> |
||
608 | |||
609 | <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
||
610 | <?php endif; ?> |
||
611 | |||
612 | <table cellpadding="0" cellspacing="0" class="getpaid_invoice_items"> |
||
613 | <thead> |
||
614 | <tr> |
||
615 | <th class="getpaid-item" colspan="2"><?php esc_html_e( 'Item', 'invoicing' ); ?></th> |
||
616 | <th class="getpaid-quantity hide-if-amount text-right"> |
||
617 | <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
||
618 | <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span> |
||
619 | </th> |
||
620 | <th class="getpaid-price hide-if-amount text-right"> |
||
621 | <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Price', 'invoicing' ); ?></span> |
||
622 | <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Rate', 'invoicing' ); ?></span> |
||
623 | </th> |
||
624 | <th class="getpaid-item-subtotal text-right"> |
||
625 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span> |
||
626 | <span class="hide-if-amount"><?php esc_html_e( 'Total', 'invoicing' ); ?></span> |
||
627 | </th> |
||
628 | <th class="getpaid-item-actions hide-if-not-editable" width="70px"> </th> |
||
629 | </tr> |
||
630 | </thead> |
||
631 | <tbody class="getpaid_invoice_line_items"> |
||
632 | <tr class="hide-if-has-items hide-if-not-editable"> |
||
633 | <td colspan="2" class="pt-4 pb-4"> |
||
634 | <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Items', 'invoicing' ); ?></button> |
||
635 | <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button> |
||
636 | </td> |
||
637 | <td class="hide-if-amount"> </th> |
||
638 | <td class="hide-if-amount"> </th> |
||
639 | <td> </th> |
||
640 | <td width="1%"> </th> |
||
641 | </tr> |
||
642 | <tr class="getpaid-invoice-item-template d-none"> |
||
643 | <td class="getpaid-item" colspan="2"> |
||
644 | <span class='item-name'></span> |
||
645 | <small class="form-text text-muted item-description"></small> |
||
646 | </td> |
||
647 | <td class="getpaid-quantity hide-if-amount text-right item-quantity"></td> |
||
648 | <td class="getpaid-price hide-if-amount text-right item-price"></td> |
||
649 | <td class="getpaid-item-subtotal text-right"> |
||
650 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"></span> |
||
651 | <span class="hide-if-amount item-total"></span> |
||
652 | </td> |
||
653 | <td class="getpaid-item-actions hide-if-not-editable" width="70px"> |
||
654 | <span class="dashicons dashicons-edit"></span> |
||
655 | <span class="dashicons dashicons-trash"></span> |
||
656 | </td> |
||
657 | </tr> |
||
658 | |||
659 | </tbody> |
||
660 | </table> |
||
661 | |||
662 | <div class="getpaid-invoice-totals-row"> |
||
663 | <div class="row"> |
||
664 | <div class="col-12 col-sm-6 offset-sm-6"> |
||
665 | <table class="getpaid-invoice-totals text-right w-100"> |
||
666 | <tbody> |
||
667 | <?php foreach ( apply_filters( 'getpaid_invoice_subtotal_rows', $totals, $invoice ) as $key => $data ) : ?> |
||
668 | <tr class="getpaid-totals-<?php echo esc_attr( $key ); ?>"> |
||
669 | <td class="label"><?php echo esc_html( $data['label'] ); ?>:</td> |
||
670 | <td width="1%"></td> |
||
671 | <td class="value"><?php echo wp_kses_post( $data['value'] ); ?></td> |
||
672 | </tr> |
||
673 | <?php endforeach; ?> |
||
674 | </tbody> |
||
675 | </table> |
||
676 | </div> |
||
677 | </div> |
||
678 | </div> |
||
679 | |||
680 | <!-- Actions --> |
||
681 | <div class="getpaid-invoice-item-actions hide-if-no-items hide-if-not-editable"> |
||
682 | <div class="row"> |
||
683 | <div class="text-left col-12 col-sm-8"> |
||
684 | <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Item', 'invoicing' ); ?></button> |
||
685 | <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button> |
||
686 | <?php do_action( 'getpaid-invoice-items-actions', $invoice ); ?> |
||
687 | </div> |
||
688 | <div class="text-right col-12 col-sm-4"> |
||
689 | <button type="button" class="button button-primary recalculate-totals-button"><?php esc_html_e( 'Recalculate Totals', 'invoicing' ); ?></button> |
||
690 | </div> |
||
691 | </div> |
||
692 | </div> |
||
693 | |||
694 | <div class="getpaid-invoice-item-actions hide-if-editable"> |
||
695 | <p class="description m-2 text-right text-muted"><?php esc_html_e( 'This invoice is no longer editable', 'invoicing' ); ?></p> |
||
696 | </div> |
||
697 | |||
698 | <!-- Add items to an invoice --> |
||
699 | <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"> |
||
700 | <div class="modal-dialog modal-dialog-centered" role="document"> |
||
701 | <div class="modal-content"> |
||
702 | <div class="modal-header"> |
||
703 | <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php esc_html_e( 'Add Item(s)', 'invoicing' ); ?></h5> |
||
704 | <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
||
705 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
||
706 | <span aria-hidden="true">×</span> |
||
707 | <?php endif; ?> |
||
708 | </button> |
||
709 | </div> |
||
710 | <div class="modal-body"> |
||
711 | <table class="widefat"> |
||
712 | <thead> |
||
713 | <tr> |
||
714 | <th class="pl-0 text-left"><?php esc_html_e( 'Item', 'invoicing' ); ?></th> |
||
715 | <th class="pr-0 text-right hide-if-amount"> |
||
716 | <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
||
717 | <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span> |
||
718 | </th> |
||
719 | </tr> |
||
720 | </thead> |
||
721 | <tbody> |
||
722 | <tr> |
||
723 | <td class="pl-0 text-left"> |
||
724 | <select class="regular-text getpaid-add-invoice-item-select"> |
||
725 | <option value="" selected="selected" disabled><?php esc_html_e( 'Select an item…', 'invoicing' ); ?></option> |
||
726 | <?php foreach ( get_posts( $item_args ) as $item ) : ?> |
||
727 | <option value="<?php echo (int) $item->ID; ?>"><?php echo esc_html( $item->post_title ); ?></option> |
||
728 | <?php endforeach; ?> |
||
729 | </select> |
||
730 | </td> |
||
731 | <td class="pr-0 text-right hide-if-amount"> |
||
732 | <input type="number" class="w100" step="1" min="1" autocomplete="off" value="1" placeholder="1"> |
||
733 | </td> |
||
734 | </tr> |
||
735 | </tbody> |
||
736 | </table> |
||
737 | </div> |
||
738 | <div class="modal-footer"> |
||
739 | <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
||
740 | <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php esc_html_e( 'Add', 'invoicing' ); ?></button> |
||
741 | </div> |
||
742 | </div> |
||
743 | </div> |
||
744 | </div> |
||
745 | |||
746 | <!-- Create invoice item --> |
||
747 | <div class="modal fade" id="getpaid-create-invoice-item" tabindex="-1" role="dialog" aria-labelledby="getpaid-create-invoice-item-label" aria-hidden="true"> |
||
748 | <div class="modal-dialog modal-dialog-centered" role="document"> |
||
749 | <div class="modal-content"> |
||
750 | <div class="modal-header"> |
||
751 | <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php esc_html_e( 'Create Item', 'invoicing' ); ?></h5> |
||
752 | <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
||
753 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
||
754 | <span aria-hidden="true">×</span> |
||
755 | <?php endif; ?> |
||
756 | </button> |
||
757 | </div> |
||
758 | <div class="modal-body"> |
||
759 | <div class="getpaid-create-item-div"> |
||
760 | <input type="hidden" name="id" value="new" class="form-control form-control-sm item-id"> |
||
761 | <label class="form-group mb-3 w-100"> |
||
762 | <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span> |
||
763 | <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
||
764 | </label> |
||
765 | <label class="form-group mb-3 w-100"> |
||
766 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span> |
||
767 | <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span> |
||
768 | <input type="text" name="price" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control form-control-sm item-price"> |
||
769 | </label> |
||
770 | <label class="form-group mb-3 w-100 hide-if-amount"> |
||
771 | <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
||
772 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
||
773 | </label> |
||
774 | <label class="form-group mb-3 w-100"> |
||
775 | <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span> |
||
776 | <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
||
777 | </label> |
||
778 | </div> |
||
779 | </div> |
||
780 | <div class="modal-footer"> |
||
781 | <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
||
782 | <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Create', 'invoicing' ); ?></button> |
||
783 | </div> |
||
784 | </div> |
||
785 | </div> |
||
786 | </div> |
||
787 | |||
788 | <!-- Edit invoice item --> |
||
789 | <div class="modal fade" id="getpaid-edit-invoice-item" tabindex="-1" role="dialog" aria-labelledby="getpaid-edit-invoice-item-label" aria-hidden="true"> |
||
790 | <div class="modal-dialog modal-dialog-centered" role="document"> |
||
791 | <div class="modal-content"> |
||
792 | <div class="modal-header"> |
||
793 | <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php esc_html_e( 'Edit Item', 'invoicing' ); ?></h5> |
||
794 | <button type="button" class="close close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
||
795 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
||
796 | <span aria-hidden="true">×</span> |
||
797 | <?php endif; ?> |
||
798 | </button> |
||
799 | </div> |
||
800 | <div class="modal-body"> |
||
801 | <div class="getpaid-edit-item-div"> |
||
802 | <input type="hidden" name="id" class="form-control form-control-sm item-id"> |
||
803 | <label class="form-group mb-3 w-100"> |
||
804 | <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span> |
||
805 | <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
||
806 | </label> |
||
807 | <label class="form-group mb-3 w-100"> |
||
808 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span> |
||
809 | <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span> |
||
810 | <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price"> |
||
811 | </label> |
||
812 | <label class="form-group mb-3 w-100 hide-if-amount"> |
||
813 | <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
||
814 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
||
815 | </label> |
||
816 | <label class="form-group mb-3 w-100"> |
||
817 | <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span> |
||
818 | <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
||
819 | </label> |
||
820 | </div> |
||
821 | </div> |
||
822 | <div class="modal-footer"> |
||
823 | <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
||
824 | <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Save', 'invoicing' ); ?></button> |
||
825 | </div> |
||
834 |
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.