Conditions | 14 |
Paths | 20 |
Total Lines | 244 |
Code Lines | 129 |
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 |
||
48 | function wpinv_recurring_subscription_details() { |
||
49 | |||
50 | $render = true; |
||
|
|||
51 | |||
52 | if ( ! current_user_can( 'manage_invoicing' ) ) { |
||
53 | die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
||
54 | } |
||
55 | |||
56 | if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
||
57 | die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
||
58 | } |
||
59 | |||
60 | $sub_id = (int) $_GET['id']; |
||
61 | $sub = new WPInv_Subscription( $sub_id ); |
||
62 | |||
63 | if ( empty( $sub ) ) { |
||
64 | die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
||
65 | } |
||
66 | |||
67 | ?> |
||
68 | <div class="wrap"> |
||
69 | <h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
||
70 | |||
71 | <?php if ( $sub ) : ?> |
||
72 | |||
73 | <div id="wpinv-item-card-wrapper"> |
||
74 | |||
75 | <?php do_action( 'wpinv_subscription_card_top', $sub ); ?> |
||
76 | |||
77 | <div class="info-wrapper item-section"> |
||
78 | |||
79 | <form id="edit-item-info" method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $sub->id ); ?>"> |
||
80 | |||
81 | <div class="item-info"> |
||
82 | |||
83 | <table class="widefat striped"> |
||
84 | <tbody> |
||
85 | <tr> |
||
86 | <td class="row-title"> |
||
87 | <label for="tablecell"><?php _e( 'Billing Cycle:', 'invoicing' ); ?></label> |
||
88 | </td> |
||
89 | <td> |
||
90 | <?php |
||
91 | $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
||
92 | $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
||
93 | $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
||
94 | printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
||
95 | ?> |
||
96 | </td> |
||
97 | </tr> |
||
98 | <tr> |
||
99 | <td class="row-title"> |
||
100 | <label for="tablecell"><?php _e( 'Times Billed:', 'invoicing' ); ?></label> |
||
101 | </td> |
||
102 | <td><?php echo $sub->get_times_billed() . ' / ' . ( ( $sub->bill_times == 0 ) ? 'Until Cancelled' : $sub->bill_times ); ?></td> |
||
103 | </tr> |
||
104 | <tr> |
||
105 | <td class="row-title"> |
||
106 | <label for="tablecell"><?php _e( 'Customer:', 'invoicing' ); ?></label> |
||
107 | </td> |
||
108 | <td> |
||
109 | <?php $subscriber = get_userdata( $sub->customer_id ); ?> |
||
110 | <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&view=overview&id=' . $subscriber->ID ) ); ?>" target="_blank"><?php echo ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; ?></a> |
||
111 | </td> |
||
112 | </tr> |
||
113 | <tr> |
||
114 | <td class="row-title"> |
||
115 | <label for="tablecell"><?php _e( 'Initial Invoice:', 'invoicing' ); ?></label> |
||
116 | </td> |
||
117 | <td> |
||
118 | <a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $sub->parent_payment_id ) ); ?>"><?php echo wpinv_get_invoice_number( $sub->parent_payment_id ); ?></a> <?php echo wp_sprintf( __( '( ID: %s )', 'invoicing' ), '<a title="' . esc_attr( __( 'View invoice details', 'invoicing' ) ) . '" href="' . get_edit_post_link( $sub->parent_payment_id ) . '" target="_blank">' . $sub->parent_payment_id . '</a>' ); ?></td> |
||
119 | </tr> |
||
120 | <tr> |
||
121 | <td class="row-title"> |
||
122 | <label for="tablecell"><?php _e( 'Item:', 'invoicing' ); ?></label> |
||
123 | </td> |
||
124 | <td> |
||
125 | <?php |
||
126 | echo wpinv_item_dropdown( array( |
||
127 | 'name' => 'product_id', |
||
128 | 'id' => 'wpinv_invoice_item', |
||
129 | 'with_packages' => false, |
||
130 | 'show_recurring' => true, |
||
131 | 'selected' => $sub->product_id, |
||
132 | 'class' => 'wpinv-sub-product-id', |
||
133 | ) ); |
||
134 | |||
135 | ?> |
||
136 | <a href="<?php echo esc_url( add_query_arg( array( |
||
137 | 'post' => $sub->product_id, |
||
138 | 'action' => 'edit' |
||
139 | ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
||
140 | </td> |
||
141 | </tr> |
||
142 | <tr> |
||
143 | <td class="row-title"> |
||
144 | <label for="tablecell"><?php _e( 'Payment Method:', 'invoicing' ); ?></label> |
||
145 | </td> |
||
146 | <td><?php echo wpinv_get_gateway_admin_label( wpinv_get_payment_gateway( $sub->parent_payment_id ) ); ?></td> |
||
147 | </tr> |
||
148 | <tr> |
||
149 | <td class="row-title"> |
||
150 | <label for="tablecell"><?php _e( 'Profile ID:', 'invoicing' ); ?></label> |
||
151 | </td> |
||
152 | <td> |
||
153 | <span class="wpinv-sub-profile-id"> |
||
154 | <?php echo apply_filters( 'wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub ); ?> |
||
155 | </span> |
||
156 | <input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr( $sub->profile_id ); ?>" /> |
||
157 | <span> – </span> |
||
158 | <a href="#" class="wpinv-edit-sub-profile-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
||
159 | </td> |
||
160 | </tr> |
||
161 | <tr> |
||
162 | <td class="row-title"> |
||
163 | <label for="tablecell"><?php _e( 'Transaction ID:', 'invoicing' ); ?></label> |
||
164 | </td> |
||
165 | <td> |
||
166 | <span class="wpinv-sub-transaction-id"><?php echo $sub->get_transaction_id(); ?></span> |
||
167 | <input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr( $sub->get_transaction_id() ); ?>" /> |
||
168 | <span> – </span> |
||
169 | <a href="#" class="wpinv-edit-sub-transaction-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
||
170 | </td> |
||
171 | </tr> |
||
172 | <tr> |
||
173 | <td class="row-title"> |
||
174 | <label for="tablecell"><?php _e( 'Date Created:', 'invoicing' ); ?></label> |
||
175 | </td> |
||
176 | <td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->created, current_time( 'timestamp' ) ) ); ?></td> |
||
177 | </tr> |
||
178 | <tr> |
||
179 | <td class="row-title"> |
||
180 | <label for="tablecell"> |
||
181 | <?php if( 'trialling' == $sub->status ) : ?> |
||
182 | <?php _e( 'Trialling Until:', 'invoicing' ); ?> |
||
183 | <?php else: ?> |
||
184 | <?php _e( 'Expiration Date:', 'invoicing' ); ?> |
||
185 | <?php endif; ?> |
||
186 | </label> |
||
187 | </td> |
||
188 | <td> |
||
189 | <span class="wpinv-sub-expiration"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->expiration, current_time( 'timestamp' ) ) ); ?></span> |
||
190 | </td> |
||
191 | </tr> |
||
192 | <tr> |
||
193 | <td class="row-title"> |
||
194 | <label for="tablecell"><?php _e( 'Subscription Status:', 'invoicing' ); ?></label> |
||
195 | </td> |
||
196 | <td> |
||
197 | <select name="status"> |
||
198 | <option value="pending"<?php selected( 'pending', $sub->status ); ?>><?php _e( 'Pending', 'invoicing' ); ?></option> |
||
199 | <option value="active"<?php selected( 'active', $sub->status ); ?>><?php _e( 'Active', 'invoicing' ); ?></option> |
||
200 | <option value="cancelled"<?php selected( 'cancelled', $sub->status ); ?>><?php _e( 'Cancelled', 'invoicing' ); ?></option> |
||
201 | <option value="expired"<?php selected( 'expired', $sub->status ); ?>><?php _e( 'Expired', 'invoicing' ); ?></option> |
||
202 | <option value="trialling"<?php selected( 'trialling', $sub->status ); ?>><?php _e( 'Trialling', 'invoicing' ); ?></option> |
||
203 | <option value="failing"<?php selected( 'failing', $sub->status ); ?>><?php _e( 'Failing', 'invoicing' ); ?></option> |
||
204 | <option value="completed"<?php selected( 'completed', $sub->status ); ?>><?php _e( 'Completed', 'invoicing' ); ?></option> |
||
205 | </select> |
||
206 | </td> |
||
207 | </tr> |
||
208 | </tbody> |
||
209 | </table> |
||
210 | </div> |
||
211 | <div id="wpinv-sub-notices"> |
||
212 | <div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e( 'Changing the product assigned will not automatically adjust any pricing.', 'invoicing' ); ?></p></div> |
||
213 | <div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e( 'Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing' ); ?></p></div> |
||
214 | </div> |
||
215 | <div id="item-edit-actions" class="edit-item" style="float:right; margin: 10px 0 0; display: block;"> |
||
216 | <?php wp_nonce_field( 'wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true ); ?> |
||
217 | <input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e( 'Update Subscription', 'invoicing' ); ?>"/> |
||
218 | <input type="hidden" name="sub_id" value="<?php echo absint( $sub->id ); ?>" /> |
||
219 | <?php if( $sub->can_cancel() ) : ?> |
||
220 | <a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e( 'Cancel Subscription', 'invoicing' ); ?></a> |
||
221 | <?php endif; ?> |
||
222 | <input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e( 'Delete Subscription', 'invoicing' ); ?>"/> |
||
223 | </div> |
||
224 | |||
225 | </form> |
||
226 | </div> |
||
227 | |||
228 | <?php do_action( 'wpinv_subscription_before_stats', $sub ); ?> |
||
229 | |||
230 | <?php do_action( 'wpinv_subscription_before_tables_wrapper', $sub ); ?> |
||
231 | |||
232 | <div id="item-tables-wrapper" class="item-section"> |
||
233 | |||
234 | <?php do_action( 'wpinv_subscription_before_tables', $sub ); ?> |
||
235 | |||
236 | <h3><?php _e( 'Renewal Payments:', 'invoicing' ); ?></h3> |
||
237 | <?php $payments = $sub->get_child_payments(); ?> |
||
238 | <?php if ( 'manual' == $sub->gateway ) : ?> |
||
239 | <p><strong><?php _e( 'Note:', 'invoicing' ); ?></strong> <?php _e( 'Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing' ); ?></p> |
||
240 | <?php endif; ?> |
||
241 | <table class="wp-list-table widefat striped payments"> |
||
242 | <thead> |
||
243 | <tr> |
||
244 | <th><?php _e( 'ID', 'invoicing' ); ?></th> |
||
245 | <th><?php _e( 'Amount', 'invoicing' ); ?></th> |
||
246 | <th><?php _e( 'Date', 'invoicing' ); ?></th> |
||
247 | <th><?php _e( 'Status', 'invoicing' ); ?></th> |
||
248 | <th><?php _e( 'Invoice', 'invoicing' ); ?></th> |
||
249 | <th class="column-wpi_actions"><?php _e( 'Actions', 'invoicing' ); ?></th> |
||
250 | </tr> |
||
251 | </thead> |
||
252 | <tbody> |
||
253 | <?php if ( ! empty( $payments ) ) : ?> |
||
254 | <?php foreach ( $payments as $payment ) : $invoice = wpinv_get_invoice( $payment->ID ); if ( empty( $invoice->ID ) ) continue; ?> |
||
255 | <tr> |
||
256 | <td><?php echo $payment->ID; ?></td> |
||
257 | <td><?php echo $invoice->get_total( true ); ?></td> |
||
258 | <td><?php echo $invoice->get_invoice_date(); ?></td> |
||
259 | <td><?php echo $invoice->get_status( true ); ?></td> |
||
260 | <td> |
||
261 | <a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $payment->ID ) ); ?>"><?php echo $invoice->get_number(); ?></a> |
||
262 | <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
||
263 | </td> |
||
264 | <td class="column-wpi_actions"> |
||
265 | <a title="<?php echo esc_attr( wp_sprintf( __( 'View details for invoice: %s', 'invoicing' ), $invoice->get_number() ) ); ?>" href="<?php echo get_edit_post_link( $payment->ID ); ?>"><?php _e( 'View Details', 'invoicing' ); ?> |
||
266 | </a> |
||
267 | <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
||
268 | </td> |
||
269 | </tr> |
||
270 | <?php endforeach; ?> |
||
271 | <?php else: ?> |
||
272 | <tr> |
||
273 | <td colspan="5"><?php _e( 'No Invoices Found.', 'invoicing' ); ?></td> |
||
274 | </tr> |
||
275 | <?php endif; ?> |
||
276 | </tbody> |
||
277 | <tfoot></tfoot> |
||
278 | </table> |
||
279 | |||
280 | <?php do_action( 'wpinv_subscription_after_tables', $sub ); ?> |
||
281 | |||
282 | </div> |
||
283 | |||
284 | <?php do_action( 'wpinv_subscription_card_bottom', $sub ); ?> |
||
285 | </div> |
||
286 | |||
287 | <?php endif; ?> |
||
288 | |||
289 | </div> |
||
290 | <?php |
||
291 | } |
||
292 | |||
394 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.