| Conditions | 13 |
| Paths | 204 |
| Total Lines | 72 |
| Code Lines | 27 |
| 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 |
||
| 43 | public static function add_meta_boxes( $post_type, $post ) { |
||
| 44 | global $wpinv_euvat; |
||
| 45 | |||
| 46 | // For invoices... |
||
| 47 | if ( $post_type == 'wpi_invoice' ) { |
||
| 48 | $invoice = new WPInv_Invoice( $post ); |
||
| 49 | |||
| 50 | // Resend invoice. |
||
| 51 | if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) { |
||
| 52 | add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' ); |
||
| 53 | } |
||
| 54 | |||
| 55 | // Subscriptions. |
||
| 56 | $subscription = getpaid_get_invoice_subscription( $invoice ); |
||
| 57 | if ( ! empty( $subscription ) ) { |
||
| 58 | add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced' ); |
||
| 59 | add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced' ); |
||
| 60 | } |
||
| 61 | |||
| 62 | // Invoice details. |
||
| 63 | add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' ); |
||
| 64 | |||
| 65 | // Payment details. |
||
| 66 | if ( ! $invoice->is_draft() ) { |
||
| 67 | add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' ); |
||
| 68 | } |
||
| 69 | |||
| 70 | // Billing details. |
||
| 71 | add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' ); |
||
| 72 | |||
| 73 | // Invoice items. |
||
| 74 | add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' ); |
||
| 75 | |||
| 76 | // Invoice notes. |
||
| 77 | add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low' ); |
||
| 78 | |||
| 79 | // Payment form information. |
||
| 80 | if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
||
| 81 | add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | // For payment forms. |
||
| 86 | if ( $post_type == 'wpi_payment_form' ) { |
||
| 87 | |||
| 88 | // Design payment form. |
||
| 89 | add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
||
| 90 | |||
| 91 | // Payment form information. |
||
| 92 | add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
||
| 93 | |||
| 94 | } |
||
| 95 | |||
| 96 | // For invoice items. |
||
| 97 | if ( $post_type == 'wpi_item' ) { |
||
| 98 | |||
| 99 | // Item details. |
||
| 100 | add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
||
| 101 | |||
| 102 | // If taxes are enabled, register the tax metabox. |
||
| 103 | if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
||
| 104 | add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
||
| 105 | } |
||
| 106 | |||
| 107 | // Item info. |
||
| 108 | add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
||
| 109 | |||
| 110 | } |
||
| 111 | |||
| 112 | // For invoice discounts. |
||
| 113 | if ( $post_type == 'wpi_discount' ) { |
||
| 114 | add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
||
| 115 | } |
||
| 198 |