| Conditions | 10 |
| Paths | 28 |
| Total Lines | 64 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 27 | function wpbo_mc_display_groups() { |
||
| 28 | |||
| 29 | /* Make sure we have a list ID to check */ |
||
| 30 | if ( ! isset( $_POST['mc_list_id'] ) ) { |
||
| 31 | echo '<div class="form-invalid" style="padding: 1em;">' . __( 'An error occurred during the request. The list ID is missing.', 'betteroptin' ) . '</div>'; |
||
| 32 | wp_die(); |
||
| 33 | } |
||
| 34 | |||
| 35 | $list_id = sanitize_key( $_POST['mc_list_id'] ); |
||
| 36 | $post_id = (int) $_POST['mc_post_id']; |
||
| 37 | |||
| 38 | /* Get the groups */ |
||
| 39 | $groups = WPBO_MC()->get_groups( $list_id ); |
||
| 40 | |||
| 41 | if ( is_wp_error( $groups ) ) { |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var WP_Error $groups |
||
| 45 | */ |
||
| 46 | |||
| 47 | echo '<div class="form-invalid" style="padding: 1em;">' . $groups->get_error_message() . '</div>'; |
||
| 48 | wp_die(); |
||
| 49 | } |
||
| 50 | |||
| 51 | if ( is_array( $groups ) && ! empty( $groups ) ) { |
||
| 52 | |||
| 53 | foreach ( $groups as $group ) { |
||
| 54 | |||
| 55 | $show_groups = new WPMC_MailChimp_Groups( $group['id'], $group['groups'], $post_id ); |
||
| 56 | $group_name = $group['name']; |
||
| 57 | $group_options = $group['form_field']; |
||
| 58 | |||
| 59 | echo "<p>$group_name</p>"; |
||
| 60 | |||
| 61 | switch ( $group_options ) { |
||
| 62 | |||
| 63 | case 'checkboxes': |
||
| 64 | $show_groups->show_group_type_checkboxes(); |
||
| 65 | break; |
||
| 66 | |||
| 67 | case 'radio': |
||
| 68 | $show_groups->show_group_type_radio(); |
||
| 69 | break; |
||
| 70 | |||
| 71 | case 'dropdown': |
||
| 72 | $show_groups->show_group_type_dropdown(); |
||
| 73 | break; |
||
| 74 | |||
| 75 | case 'hidden': |
||
| 76 | $show_groups->show_group_type_checkboxes(); |
||
| 77 | break; |
||
| 78 | |||
| 79 | } |
||
| 80 | |||
| 81 | } |
||
| 82 | |||
| 83 | wp_die(); |
||
| 84 | |||
| 85 | } else { |
||
| 86 | echo '<div class="form-invalid" style="padding: 1em;">' . __( 'This list does not have any groups.', 'betteroptin' ) . '</div>'; |
||
| 87 | wp_die(); |
||
| 88 | } |
||
| 89 | |||
| 90 | } |