| Conditions | 9 |
| Paths | 41 |
| Total Lines | 94 |
| Code Lines | 52 |
| 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 |
||
| 107 | protected static function add_invoice_meta_boxes( $post_type, $post ) { |
||
| 108 | |||
| 109 | // For invoices... |
||
| 110 | if ( getpaid_is_invoice_post_type( $post_type ) ) { |
||
| 111 | $invoice = new WPInv_Invoice( $post ); |
||
| 112 | |||
| 113 | // Resend invoice. |
||
| 114 | if ( ! $invoice->is_draft() ) { |
||
| 115 | |||
| 116 | add_meta_box( |
||
| 117 | 'wpinv-mb-resend-invoice', |
||
| 118 | sprintf( |
||
| 119 | // translators: %s is the invoice type. |
||
| 120 | __( 'Resend %s', 'invoicing' ), |
||
| 121 | ucfirst( $invoice->get_invoice_quote_type() ) |
||
| 122 | ), |
||
| 123 | 'GetPaid_Meta_Box_Resend_Invoice::output', |
||
| 124 | $post_type, |
||
| 125 | 'side', |
||
| 126 | 'low' |
||
| 127 | ); |
||
| 128 | |||
| 129 | } |
||
| 130 | |||
| 131 | // Subscriptions. |
||
| 132 | $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
||
| 133 | if ( ! empty( $subscriptions ) ) { |
||
| 134 | |||
| 135 | if ( is_array( $subscriptions ) ) { |
||
|
|
|||
| 136 | add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
||
| 137 | } else { |
||
| 138 | add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
||
| 139 | } |
||
| 140 | |||
| 141 | if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
||
| 142 | add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | // Invoice details. |
||
| 147 | add_meta_box( |
||
| 148 | 'wpinv-details', |
||
| 149 | sprintf( |
||
| 150 | // translators: %s is the invoice type. |
||
| 151 | __( '%s Details', 'invoicing' ), |
||
| 152 | ucfirst( $invoice->get_invoice_quote_type() ) |
||
| 153 | ), |
||
| 154 | 'GetPaid_Meta_Box_Invoice_Details::output', |
||
| 155 | $post_type, |
||
| 156 | 'side' |
||
| 157 | ); |
||
| 158 | |||
| 159 | // Payment details. |
||
| 160 | add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
||
| 161 | |||
| 162 | // Billing details. |
||
| 163 | add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
||
| 164 | |||
| 165 | // Invoice items. |
||
| 166 | add_meta_box( |
||
| 167 | 'wpinv-items', |
||
| 168 | sprintf( |
||
| 169 | // translators: %s is the invoice type. |
||
| 170 | __( '%s Items', 'invoicing' ), |
||
| 171 | ucfirst( $invoice->get_invoice_quote_type() ) |
||
| 172 | ), |
||
| 173 | 'GetPaid_Meta_Box_Invoice_Items::output', |
||
| 174 | $post_type, |
||
| 175 | 'normal', |
||
| 176 | 'high' |
||
| 177 | ); |
||
| 178 | |||
| 179 | // Invoice notes. |
||
| 180 | add_meta_box( |
||
| 181 | 'wpinv-notes', |
||
| 182 | sprintf( |
||
| 183 | // translators: %s is the invoice type. |
||
| 184 | __( '%s Notes', 'invoicing' ), |
||
| 185 | ucfirst( $invoice->get_invoice_quote_type() ) |
||
| 186 | ), |
||
| 187 | 'WPInv_Meta_Box_Notes::output', |
||
| 188 | $post_type, |
||
| 189 | 'side', |
||
| 190 | 'low' |
||
| 191 | ); |
||
| 192 | |||
| 193 | // Shipping Address. |
||
| 194 | if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
||
| 195 | add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
||
| 196 | } |
||
| 197 | |||
| 198 | // Payment form information. |
||
| 199 | if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
||
| 200 | add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
||
| 201 | } |
||
| 292 |