| Conditions | 2 |
| Paths | 2 |
| Total Lines | 88 |
| 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 |
||
| 266 | public function settings_page() { |
||
| 267 | if ( !current_user_can( 'manage_options' ) ) { |
||
| 268 | wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
||
| 269 | } |
||
| 270 | ?> |
||
| 271 | <div class="wrap"> |
||
| 272 | <h1><?php echo $this->name; ?></h1> |
||
| 273 | <form method="post" action="options.php"> |
||
| 274 | <?php |
||
| 275 | settings_fields( 'wp-font-awesome-settings' ); |
||
| 276 | do_settings_sections( 'wp-font-awesome-settings' ); |
||
| 277 | ?> |
||
| 278 | <table class="form-table"> |
||
| 279 | <tr valign="top"> |
||
| 280 | <th scope="row"><label for="wpfas-type"><?php _e('Type');?></label></th> |
||
| 281 | <td> |
||
| 282 | <select name="wp-font-awesome-settings[type]" id="wpfas-type"> |
||
| 283 | <option value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e('CSS (default)');?></option> |
||
| 284 | <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
||
| 285 | </select> |
||
| 286 | </td> |
||
| 287 | </tr> |
||
| 288 | |||
| 289 | <tr valign="top"> |
||
| 290 | <th scope="row"><label for="wpfas-version"><?php _e('Version');?></label></th> |
||
| 291 | <td> |
||
| 292 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
||
| 293 | <option value="" <?php selected( $this->settings['version'], '' ); ?>><?php _e('Latest (default)');?></option> |
||
| 294 | <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>>5.5.0</option> |
||
| 295 | <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>>5.4.0</option> |
||
| 296 | <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>>5.3.0</option> |
||
| 297 | <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>>5.2.0</option> |
||
| 298 | <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>>5.1.0</option> |
||
| 299 | <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>>4.7.1 (CSS only)</option> |
||
| 300 | </select> |
||
| 301 | </td> |
||
| 302 | </tr> |
||
| 303 | |||
| 304 | <tr valign="top"> |
||
| 305 | <th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue');?></label></th> |
||
| 306 | <td> |
||
| 307 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
||
| 308 | <option value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e('Frontend + Backend (default)');?></option> |
||
| 309 | <option value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e('Frontend');?></option> |
||
| 310 | <option value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e('Backend');?></option> |
||
| 311 | </select> |
||
| 312 | </td> |
||
| 313 | </tr> |
||
| 314 | |||
| 315 | <tr valign="top"> |
||
| 316 | <th scope="row"><label for="wpfas-shims"><?php _e('Enable v4 shims compatibility');?></label></th> |
||
| 317 | <td> |
||
| 318 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0" /> |
||
| 319 | <input type="checkbox" name="wp-font-awesome-settings[shims]" value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims" /> |
||
| 320 | <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.');?></span> |
||
| 321 | </td> |
||
| 322 | </tr> |
||
| 323 | |||
| 324 | <tr valign="top"> |
||
| 325 | <th scope="row"><label for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)');?></label></th> |
||
| 326 | <td> |
||
| 327 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0" /> |
||
| 328 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> id="wpfas-js-pseudo" /> |
||
| 329 | <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.');?></span> |
||
| 330 | </td> |
||
| 331 | </tr> |
||
| 332 | |||
| 333 | <tr valign="top"> |
||
| 334 | <th scope="row"><label for="wpfas-dequeue"><?php _e('Dequeue');?></label></th> |
||
| 335 | <td> |
||
| 336 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0" /> |
||
| 337 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> id="wpfas-dequeue" /> |
||
| 338 | <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.');?></span> |
||
| 339 | </td> |
||
| 340 | </tr> |
||
| 341 | |||
| 342 | |||
| 343 | </table> |
||
| 344 | <?php |
||
| 345 | submit_button(); |
||
| 346 | ?> |
||
| 347 | </form> |
||
| 348 | |||
| 349 | <div id="wpfas-version"><?php echo $this->version;?></div> |
||
| 350 | </div> |
||
| 351 | |||
| 352 | <?php |
||
| 353 | } |
||
| 354 | |||
| 362 | } |
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.