| Conditions | 7 |
| Paths | 8 |
| Total Lines | 61 |
| 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 |
||
| 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 | wp_enqueue_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, true ); |
||
| 132 | 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, true ); |
||
| 133 | |||
| 134 | $script_handles = array( |
||
| 135 | 'mustache', |
||
| 136 | 'underscore', |
||
| 137 | 'backbone', |
||
| 138 | 'jquery', |
||
| 139 | 'jquery-migrate', |
||
| 140 | 'jquery-core', |
||
| 141 | 'wpcom-notes-common', |
||
| 142 | 'wpcom-notes-admin-bar', |
||
| 143 | ); |
||
| 144 | |||
| 145 | $is_amp_request = class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request(); |
||
| 146 | |||
| 147 | add_filter( |
||
| 148 | 'script_loader_tag', |
||
| 149 | function ( $tag, $handle ) use ( $is_amp_request, $script_handles ) { |
||
| 150 | if ( $is_amp_request && in_array( $handle, $script_handles, true ) ) { |
||
| 151 | return preg_replace( '/(?<=<script)(?=\s|>)/i', ' data-ampdevmode', $tag ); |
||
| 152 | } |
||
| 153 | if ( 'underscore' === $handle ) { |
||
| 154 | return $tag . PHP_EOL . '<script> |
||
| 155 | (function(_AtLoad){ |
||
| 156 | console.log({_AtLoad: _AtLoad}); |
||
| 157 | })(window._); |
||
| 158 | </script>'; |
||
| 159 | } |
||
| 160 | return $tag; |
||
| 161 | }, |
||
| 162 | 10, |
||
| 163 | 2 |
||
| 164 | ); |
||
| 165 | } |
||
| 166 | |||
| 220 |
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.