| Total Complexity | 60 |
| Total Lines | 231 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
Complex classes like WPInv_Meta_Box_Details often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WPInv_Meta_Box_Details, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class WPInv_Meta_Box_Details { |
||
| 8 | public static function output( $post ) { |
||
| 101 | } |
||
| 102 | |||
| 103 | public static function resend_invoice( $post ) { |
||
| 104 | global $wpi_mb_invoice; |
||
| 105 | |||
| 106 | if ( empty( $wpi_mb_invoice ) ) { |
||
| 107 | return; |
||
| 108 | } |
||
| 109 | |||
| 110 | $text = array( |
||
| 111 | 'message' => esc_attr__( 'This will send a copy of the invoice to the customer’s email address.', 'invoicing' ), |
||
| 112 | 'button_text' => __( 'Resend Invoice', 'invoicing' ), |
||
| 113 | ); |
||
| 114 | |||
| 115 | $text = apply_filters('wpinv_resend_invoice_metabox_text', $text); |
||
| 116 | do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice ); |
||
| 117 | |||
| 118 | if ( $email = $wpi_mb_invoice->get_email() ) { |
||
| 119 | $email_actions = array(); |
||
| 120 | $email_actions['email_url'] = remove_query_arg( 'wpinv-message', add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ); |
||
| 121 | $email_actions['reminder_url'] = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) ); |
||
| 122 | |||
| 123 | $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions ); |
||
| 124 | ?> |
||
| 125 | <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p> |
||
| 126 | <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
||
| 127 | <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?> |
||
| 128 | <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p> |
||
| 129 | <?php } ?> |
||
| 130 | <?php |
||
| 131 | } |
||
| 132 | |||
| 133 | do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice ); |
||
| 134 | } |
||
| 135 | |||
| 136 | public static function subscriptions( $post ) { |
||
| 137 | $invoice = wpinv_get_invoice( $post->ID ); |
||
| 138 | |||
| 139 | if ( ! empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) { |
||
| 140 | $subscription = wpinv_get_subscription( $invoice ); |
||
| 141 | |||
| 142 | if ( empty( $subscription ) ) { |
||
| 143 | ?> |
||
| 144 | <p class="wpi-meta-row"><?php echo wp_sprintf( __( 'New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing' ), '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', '</a>' ); ?></p> |
||
| 145 | <?php |
||
| 146 | return; |
||
| 147 | } |
||
| 148 | $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency ); |
||
| 149 | $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
||
| 150 | $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
||
| 151 | $payments = $subscription->get_child_payments(); |
||
| 152 | ?> |
||
| 153 | <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . $subscription->status; ?>"><?php _e('Recurring Payment', 'invoicing'); ?></p> |
||
| 154 | <?php if ( ! empty( $subscription ) && ! empty( $subscription->id ) ) { ?> |
||
| 155 | <p class="wpi-meta-row wpi-sub-id"> |
||
| 156 | <label><?php _e( 'Subscription ID:', 'invoicing' ); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p> |
||
| 157 | <?php } ?> |
||
| 158 | <p class="wpi-meta-row wpi-bill-cycle"> |
||
| 159 | <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label><?php printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); ?> |
||
| 160 | </p> |
||
| 161 | <p class="wpi-meta-row wpi-billed-times"> |
||
| 162 | <label><?php _e( 'Times Billed:', 'invoicing' ); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?> |
||
| 163 | </p> |
||
| 164 | <p class="wpi-meta-row wpi-start-date"> |
||
| 165 | <label><?php _e( 'Start Date:', 'invoicing' ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?> |
||
| 166 | </p> |
||
| 167 | <p class="wpi-meta-row wpi-end-date"> |
||
| 168 | <label><?php echo ( 'trialling' == $subscription->status ? __( 'Trialling Until:', 'invoicing' ) : __( 'Expiration Date:', 'invoicing' ) ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?> |
||
| 169 | </p> |
||
| 170 | <?php if ( $subscription->status ) { ?> |
||
| 171 | <p class="wpi-meta-row wpi-sub-status"> |
||
| 172 | <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
||
| 173 | </p> |
||
| 174 | <?php } ?> |
||
| 175 | <?php if ( !empty( $payments ) ) { ?> |
||
| 176 | <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p> |
||
| 177 | <ul id="wpi-sub-payments"> |
||
| 178 | <?php foreach ( $payments as $payment ) { |
||
| 179 | $invoice_id = $payment->ID; |
||
| 180 | ?> |
||
| 181 | <li> |
||
| 182 | <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a> – |
||
| 183 | <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?> – </span> |
||
| 184 | <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span> |
||
| 185 | </li> |
||
| 186 | <?php } ?> |
||
| 187 | </ul> |
||
| 188 | <?php } |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | public static function renewals( $post ) { |
||
| 193 | $invoice = wpinv_get_invoice( $post->ID ); |
||
| 194 | |||
| 195 | if ( wpinv_is_subscription_payment( $invoice ) ) { |
||
| 196 | $parent_url = get_edit_post_link( $invoice->parent_invoice ); |
||
| 197 | $parent_id = wpinv_get_invoice_number( $invoice->parent_invoice ); |
||
| 198 | $subscription = wpinv_get_subscription( $invoice ); |
||
| 199 | ?> |
||
| 200 | <?php if ( ! empty( $subscription ) ) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?> |
||
| 201 | <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p> |
||
| 202 | <?php |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | public static function payment_meta( $post ) { |
||
| 238 | } |
||
| 239 | } |
||
| 240 |