Conditions | 16 |
Paths | 12 |
Total Lines | 85 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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'] ); |
||
1 ignored issue
–
show
|
|||
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>'; |
||
3 ignored issues
–
show
|
|||
232 | } |
||
1 ignored issue
–
show
|
|||
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>' : ''; |
||
2 ignored issues
–
show
|
|||
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 | // Add option to show we ran through default settings |
||
264 | // We also run a check here for the main settings page option. This is to determine if this is a fresh install or if they already had |
||
265 | // the plugin installed. The main feed settings page would give the best idea of that since user's have to enter an API key on this page to get it working. |
||
266 | if ( false === get_option( 'simple-calendar_defaults' ) && false === get_option( 'simple-calendar_settings_feeds' ) ) { |
||
267 | |||
268 | $default_advanced = array ( |
||
269 | 'assets' => array ( |
||
270 | 'always_enqueue' => 'yes', |
||
271 | ), |
||
272 | ); |
||
273 | |||
274 | update_option( 'simple-calendar_settings_advanced', $default_advanced ); |
||
275 | |||
276 | add_option( 'simple-calendar_defaults', 1 ); |
||
277 | } |
||
278 | |||
279 | |||
280 | ?> |
||
281 | </form> |
||
282 | </div> |
||
283 | <?php |
||
284 | |||
285 | } |
||
286 | |||
288 |