| Conditions | 12 |
| Paths | 10 |
| Total Lines | 26 |
| 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 |
||
| 88 | public function show_admin_notice() |
||
| 89 | { |
||
| 90 | if ( (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cachesize_notice', false ) && current_user_can( 'manage_options' ) ) { |
||
| 91 | echo '<div class="notice notice-warning"><p>'; |
||
| 92 | _e( '<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize' ); |
||
| 93 | echo '</p></div>'; |
||
| 94 | autoptimizeOptionWrapper::update_option( 'autoptimize_cachesize_notice', false ); |
||
| 95 | } |
||
| 96 | |||
| 97 | // Notice for image proxy usage. |
||
| 98 | $_imgopt_notice = autoptimizeImages::instance()->get_imgopt_status_notice_wrapper(); |
||
| 99 | if ( current_user_can( 'manage_options' ) && is_array( $_imgopt_notice ) && array_key_exists( 'status', $_imgopt_notice ) && in_array( $_imgopt_notice['status'], array( 1, -1, -2, -3 ) ) ) { |
||
| 100 | $_dismissible = 'ao-img-opt-notice-'; |
||
| 101 | $_hide_notice = '7'; |
||
| 102 | |||
| 103 | if ( -1 == $_imgopt_notice['status'] || -2 == $_imgopt_notice['status'] || -3 == $_imgopt_notice['status'] ) { |
||
| 104 | $_hide_notice = '1'; |
||
| 105 | } |
||
| 106 | |||
| 107 | $_imgopt_notice_dismissible = apply_filters( 'autoptimize_filter_imgopt_notice_dismissable', $_dismissible . $_hide_notice ); |
||
| 108 | |||
| 109 | if ( $_imgopt_notice && PAnD::is_admin_notice_active( $_imgopt_notice_dismissible ) ) { |
||
|
|
|||
| 110 | echo '<div class="notice notice-warning is-dismissible" data-dismissible="' . $_imgopt_notice_dismissible . '"><p><strong>' . __( 'Autoptimize', 'autoptimize' ) . '</strong>: ' . $_imgopt_notice['notice'] . '</p></div>'; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.