Conditions | 14 |
Paths | 6 |
Total Lines | 68 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 3 |
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 |
||
201 | public function html() { |
||
202 | |||
203 | global $current_tab; |
||
204 | |||
205 | // Get current tab/section |
||
206 | $current_tab = empty( $_GET['tab'] ) ? $this->tab : sanitize_title( $_GET['tab'] ); |
||
207 | $this->tab = $current_tab; |
||
208 | |||
209 | ?> |
||
210 | <div class="wrap" id="simcal-settings-page"> |
||
211 | <form id="simcal-settings-page-form" |
||
212 | method="post" |
||
213 | action="options.php"> |
||
214 | <?php |
||
215 | |||
216 | // Include settings pages |
||
217 | $settings_pages = self::get_settings(); |
||
218 | if ( ! empty( $settings_pages ) && is_array( $settings_pages ) ) { |
||
219 | |||
220 | echo '<h2 class="nav-tab-wrapper simcal-nav-tab-wrapper">'; |
||
221 | |||
222 | // Get tabs for the settings page |
||
223 | if ( ! empty( $settings_pages ) && is_array( $settings_pages ) ) { |
||
224 | |||
225 | foreach ( $settings_pages as $id => $settings ) { |
||
226 | |||
227 | $tab_id = isset( $id ) ? $id : ''; |
||
228 | $tab_label = isset( $settings['label'] ) ? $settings['label'] : ''; |
||
229 | $tab_link = admin_url( 'edit.php?post_type=calendar&page=simple-calendar_' . $this->page . '&tab=' . $tab_id ); |
||
230 | |||
231 | echo '<a href="' . $tab_link . '" class="nav-tab ' . ( $current_tab == $tab_id ? 'nav-tab-active' : '' ) . '">' . $tab_label . '</a>'; |
||
232 | } |
||
233 | |||
234 | } |
||
235 | |||
236 | do_action( 'simcal_admin_page_' . $this->page . '_tabs' ); |
||
237 | |||
238 | echo '</h2>'; |
||
239 | |||
240 | settings_errors(); |
||
241 | |||
242 | foreach ( $settings_pages as $tab_id => $contents ) { |
||
243 | |||
244 | if ( $tab_id === $current_tab ) { |
||
245 | |||
246 | echo isset( $contents['description'] ) ? '<p>' . $contents['description'] . '</p>' : ''; |
||
247 | |||
248 | do_action( 'simcal_admin_page_' . $this->page . '_' . $current_tab . '_start' ); |
||
249 | |||
250 | settings_fields( 'simple-calendar_' . $this->page . '_' . $tab_id ); |
||
251 | do_settings_sections( 'simple-calendar_' . $this->page . '_' . $tab_id ); |
||
252 | |||
253 | do_action( 'simcal_admin_page_' . $this->page . '_' . $current_tab . '_end' ); |
||
254 | |||
255 | $submit = apply_filters( 'simcal_admin_page_' . $this->page . '_' . $current_tab . '_submit', true ); |
||
256 | if ( true === $submit ) { |
||
257 | submit_button(); |
||
258 | } |
||
259 | } |
||
260 | } |
||
261 | } |
||
262 | |||
263 | ?> |
||
264 | </form> |
||
265 | </div> |
||
266 | <?php |
||
267 | |||
268 | } |
||
269 | |||
271 |