| Conditions | 12 |
| Paths | 128 |
| Total Lines | 90 |
| Code Lines | 53 |
| 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 |
||
| 78 | public function add_settings_meta_panel( $post_id ) { |
||
| 79 | |||
| 80 | ?> |
||
| 81 | <div id="grouped-calendars-settings-panel" class="simcal-panel"> |
||
| 82 | <table> |
||
| 83 | <thead> |
||
| 84 | <tr><th colspan="2"><?php _e( 'Grouped Calendar Settings', 'google-calendar-events' ); ?></th></tr> |
||
| 85 | </thead> |
||
| 86 | <tbody class="simcal-panel-section"> |
||
| 87 | <tr class="simcal-panel-field"> |
||
| 88 | <th><label for="_grouped_calendars_source"><?php _e( 'Get Calendars From', 'google-calendar-events' ); ?></label></th> |
||
| 89 | <td> |
||
| 90 | <?php |
||
| 91 | |||
| 92 | $source = esc_attr( get_post_meta( $post_id, '_grouped_calendars_source', true ) ); |
||
| 93 | $source = empty( $source ) ? 'ids' : $source; |
||
| 94 | |||
| 95 | ?> |
||
| 96 | <select name="_grouped_calendars_source" |
||
| 97 | id="_grouped_calendars_source" |
||
| 98 | class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-other" |
||
| 99 | data-show-field-on-choice="true"> |
||
| 100 | <option value="ids" data-show-field="_grouped_calendars_ids" <?php selected( 'ids', $source, true ); ?>><?php _e( 'Manual selection', 'google-calendar-events' ); ?></option> |
||
| 101 | <option value="category" data-show-field="_grouped_calendars_category" <?php selected( 'category', $source, true ); ?>><?php _e( 'Category', 'google-calendar-events' ); ?></option> |
||
| 102 | </select> |
||
| 103 | <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'Choose from which calendar feeds you want to get events from. Choose them individually or select all those belonging to calendar feed categories.', 'google-calendar-events' ); ?>"></i> |
||
| 104 | <br><br> |
||
| 105 | <?php |
||
| 106 | |||
| 107 | $cals = simcal_get_calendars( $post_id ); |
||
| 108 | $meta = get_post_meta( $post_id, '_grouped_calendars_ids', true ); |
||
| 109 | $ids = $meta && is_array( $meta ) ? implode( ',', array_map( 'absint', $meta ) ) : absint( $meta ); |
||
| 110 | |||
| 111 | simcal_print_field( array( |
||
| 112 | 'type' => 'select', |
||
| 113 | 'multiselect' => 'multiselect', |
||
| 114 | 'name' => '_grouped_calendars_ids', |
||
| 115 | 'id' => '_grouped_calendars_ids', |
||
| 116 | 'value' => $ids !== 0 ? $ids : '', |
||
| 117 | 'options' => $cals, |
||
| 118 | 'enhanced' => 'enhanced', |
||
| 119 | 'style' => 'ids' == $source ? '' : array( 'display' => 'none' ), |
||
| 120 | 'attributes' => array( |
||
| 121 | 'data-noresults' => __( 'No results found.', 'google-calendar-events' ), |
||
| 122 | ), |
||
| 123 | )); |
||
| 124 | |||
| 125 | $meta = get_post_meta( $post_id, '_grouped_calendars_category', true ); |
||
| 126 | $category = $meta && is_array( $meta ) ? implode( ',', array_map( 'absint', $meta ) ): ''; |
||
| 127 | |||
| 128 | $terms = get_terms( 'calendar_category' ); |
||
| 129 | |||
| 130 | if ( ! empty( $terms ) ) { |
||
| 131 | |||
| 132 | $categories = array(); |
||
| 133 | foreach ( $terms as $term ) { |
||
| 134 | $categories[ $term->term_id ] = $term->name; |
||
| 135 | } |
||
| 136 | |||
| 137 | simcal_print_field( array( |
||
| 138 | 'type' => 'select', |
||
| 139 | 'multiselect' => 'multiselect', |
||
| 140 | 'name' => '_grouped_calendars_category', |
||
| 141 | 'id' => '_grouped_calendars_category', |
||
| 142 | 'value' => $category, |
||
| 143 | 'options' => $categories, |
||
| 144 | 'enhanced' => 'enhanced', |
||
| 145 | 'style' => 'category' == $source ? '' : array( 'display' => 'none' ), |
||
| 146 | 'attributes' => array( |
||
| 147 | 'data-noresults' => __( 'No results found.', 'google-calendar-events' ), |
||
| 148 | ), |
||
| 149 | ) ); |
||
| 150 | |||
| 151 | } else { |
||
| 152 | |||
| 153 | $style = 'category' == $source ? '' : 'display: none;'; |
||
| 154 | $style .= ' width: 100%; max-width: 500px'; |
||
| 155 | echo '<input type="text" disabled="disabled" name="_grouped_calendars_category" id="_grouped_calendars_category" style="' . $style . '" placeholder="' . __( 'There are no calendar categories yet.', 'google-calendar-events' ) . '" />'; |
||
| 156 | |||
| 157 | } |
||
| 158 | |||
| 159 | ?> |
||
| 160 | </td> |
||
| 161 | </tr> |
||
| 162 | </tbody> |
||
| 163 | </table> |
||
| 164 | </div> |
||
| 165 | <?php |
||
| 166 | |||
| 167 | } |
||
| 168 | |||
| 190 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.