| Conditions | 9 |
| Paths | 64 |
| Total Lines | 63 |
| Lines | 6 |
| Ratio | 9.52 % |
| 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 |
||
| 105 | function styles_and_scripts() { |
||
| 106 | $is_rtl = is_rtl(); |
||
| 107 | |||
| 108 | if ( Jetpack::is_module_active( 'masterbar' ) ) { |
||
| 109 | /** |
||
| 110 | * Can be used to force Notifications to display in RTL style. |
||
| 111 | * |
||
| 112 | * @module notes |
||
| 113 | * |
||
| 114 | * @since 4.8.0 |
||
| 115 | * |
||
| 116 | * @param bool true Should notifications be displayed in RTL style. Defaults to false. |
||
| 117 | */ |
||
| 118 | $is_rtl = apply_filters( 'a8c_wpcom_masterbar_enqueue_rtl_notification_styles', false ); |
||
| 119 | } |
||
| 120 | |||
| 121 | if ( ! $is_rtl ) { |
||
| 122 | wp_enqueue_style( 'wpcom-notes-admin-bar', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/admin-bar-v2.css' ), array( 'admin-bar' ), JETPACK_NOTES__CACHE_BUSTER ); |
||
| 123 | } else { |
||
| 124 | wp_enqueue_style( 'wpcom-notes-admin-bar', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/rtl/admin-bar-v2-rtl.css' ), array( 'admin-bar' ), JETPACK_NOTES__CACHE_BUSTER ); |
||
| 125 | } |
||
| 126 | |||
| 127 | wp_enqueue_style( 'noticons', $this->wpcom_static_url( '/i/noticons/noticons.css' ), array( 'wpcom-notes-admin-bar' ), JETPACK_NOTES__CACHE_BUSTER ); |
||
| 128 | |||
| 129 | $this->print_js(); |
||
| 130 | |||
| 131 | // attempt to use core or plugin libraries if registered |
||
| 132 | $script_handles = array(); |
||
| 133 | if ( !wp_script_is( 'mustache', 'registered' ) ) { |
||
| 134 | wp_register_script( 'mustache', $this->wpcom_static_url( '/wp-content/js/mustache.js' ), null, JETPACK_NOTES__CACHE_BUSTER ); |
||
| 135 | } |
||
| 136 | $script_handles[] = 'mustache'; |
||
| 137 | View Code Duplication | if ( !wp_script_is( 'underscore', 'registered' ) ) { |
|
| 138 | wp_register_script( 'underscore', $this->wpcom_static_url( '/wp-includes/js/underscore.min.js' ), null, JETPACK_NOTES__CACHE_BUSTER ); |
||
| 139 | } |
||
| 140 | $script_handles[] = 'underscore'; |
||
| 141 | View Code Duplication | if ( !wp_script_is( 'backbone', 'registered' ) ) { |
|
| 142 | wp_register_script( 'backbone', $this->wpcom_static_url( '/wp-includes/js/backbone.min.js' ), array( 'underscore' ), JETPACK_NOTES__CACHE_BUSTER ); |
||
| 143 | } |
||
| 144 | $script_handles[] = 'backbone'; |
||
| 145 | |||
| 146 | wp_register_script( 'wpcom-notes-common', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/notes-common-v2.js' ), array( 'jquery', 'underscore', 'backbone', 'mustache' ), JETPACK_NOTES__CACHE_BUSTER ); |
||
| 147 | $script_handles[] = 'wpcom-notes-common'; |
||
| 148 | $script_handles[] = 'jquery'; |
||
| 149 | $script_handles[] = 'jquery-migrate'; |
||
| 150 | $script_handles[] = 'jquery-core'; |
||
| 151 | wp_enqueue_script( 'wpcom-notes-admin-bar', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/admin-bar-v2.js' ), array( 'wpcom-notes-common' ), JETPACK_NOTES__CACHE_BUSTER ); |
||
| 152 | $script_handles[] = 'wpcom-notes-admin-bar'; |
||
| 153 | |||
| 154 | if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { |
||
| 155 | add_filter( |
||
| 156 | 'script_loader_tag', |
||
| 157 | function ( $tag, $handle ) use ( $script_handles ) { |
||
| 158 | if ( in_array( $handle, $script_handles, true ) ) { |
||
| 159 | $tag = preg_replace( '/(?<=<script)(?=\s|>)/i', ' data-ampdevmode', $tag ); |
||
| 160 | } |
||
| 161 | return $tag; |
||
| 162 | }, |
||
| 163 | 10, |
||
| 164 | 2 |
||
| 165 | ); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 222 |
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.