| Conditions | 10 |
| Paths | 26 |
| Total Lines | 38 |
| Lines | 24 |
| Ratio | 63.16 % |
| 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 |
||
| 32 | public static function cdnize_assets() { |
||
| 33 | global $wp_scripts, $wp_styles; |
||
| 34 | $jetpack_version = JETPACK__VERSION; |
||
| 35 | |||
| 36 | // $known_core_files = self::get_core_checksums(); |
||
| 37 | |||
| 38 | // If Jetpack is running a known version that we have the assets CDN'd for... |
||
| 39 | // @todo: Abstract this out to make it easy to run for multiple plugins, like WooCommerce. |
||
| 40 | if ( in_array( $jetpack_version, self::get_plugin_versions( 'jetpack' ) ) ) { |
||
| 41 | $jetpack_asset_hashes = self::get_plugin_checksums( $jetpack_version, 'jetpack' ); |
||
| 42 | $jetpack_directory_url = plugins_url( '/', JETPACK__PLUGIN_FILE ); |
||
| 43 | |||
| 44 | View Code Duplication | foreach ( $wp_scripts->registered as $handle => $thing ) { |
|
| 45 | if ( wp_startswith( $thing->src, 'https://c0.wp.com/' ) ) { |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | if ( wp_startswith( $thing->src, $jetpack_directory_url ) ) { |
||
| 49 | $local_path = substr( $thing->src, strlen( $jetpack_directory_url ) ); |
||
| 50 | if ( isset( $jetpack_asset_hashes[ $local_path ] ) ) { |
||
| 51 | $wp_scripts->registered[ $handle ]->src = sprintf('https://c0.wp.com/p/jetpack/%1$s/%2$s', $jetpack_version, $local_path ); |
||
| 52 | wp_script_add_data( $handle, 'integrity', 'sha256-' . base64_encode( $jetpack_asset_hashes[ $local_path ] ) ); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | View Code Duplication | foreach ( $wp_styles->registered as $handle => $thing ) { |
|
| 57 | if ( wp_startswith( $thing->src, 'https://c0.wp.com/' ) ) { |
||
| 58 | continue; |
||
| 59 | } |
||
| 60 | if ( wp_startswith( $thing->src, $jetpack_directory_url ) ) { |
||
| 61 | $local_path = substr( $thing->src, strlen( $jetpack_directory_url ) ); |
||
| 62 | if ( isset( $jetpack_asset_hashes[ $local_path ] ) ) { |
||
| 63 | $wp_styles->registered[ $handle ]->src = sprintf('https://c0.wp.com/p/jetpack/%1$s/%2$s', $jetpack_version, $local_path ); |
||
| 64 | wp_style_add_data( $handle, 'integrity', 'sha256-' . base64_encode( $jetpack_asset_hashes[ $local_path ] ) ); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 115 |