| Conditions | 13 |
| Paths | 4 |
| Total Lines | 63 |
| Code Lines | 36 |
| Lines | 9 |
| Ratio | 14.29 % |
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 |
||
| 48 | function add_assets( $return, $loaded_scripts, $loaded_styles ) { |
||
| 49 | global $wp_scripts, $wp_styles; |
||
| 50 | // scripts first, just cuz |
||
| 51 | if ( count( $loaded_scripts ) > 0 ) { |
||
| 52 | $scripts = array(); |
||
| 53 | foreach ( $loaded_scripts as $handle ) { |
||
| 54 | if ( !isset( $wp_scripts->registered[ $handle ] ) ) |
||
| 55 | continue; |
||
| 56 | |||
| 57 | $src = $wp_scripts->registered[ $handle ]->src; |
||
| 58 | |||
| 59 | // attach version and an extra query parameters |
||
| 60 | $ver = $this->get_version( $wp_scripts->registered[ $handle ]->ver, $wp_scripts->default_version ); |
||
| 61 | View Code Duplication | if ( isset( $wp_scripts->args[ $handle ] ) ) { |
|
| 62 | $ver = $ver ? $ver . '&' . $wp_scripts->args[$handle] : $wp_scripts->args[$handle]; |
||
| 63 | } |
||
| 64 | $src = add_query_arg( 'ver', $ver, $src ); |
||
| 65 | |||
| 66 | // add to an aray so we can return all this info |
||
| 67 | $scripts[ $handle ] = array( |
||
| 68 | 'src' => $src, |
||
| 69 | ); |
||
| 70 | $extra = $wp_scripts->print_extra_script( $handle, false ); |
||
| 71 | if ( !empty( $extra ) ) { |
||
| 72 | $scripts[$handle]['extra'] = $extra; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | $return['scripts'] = $scripts; |
||
| 76 | } |
||
| 77 | // now styles |
||
| 78 | if ( count( $loaded_styles ) > 0 ) { |
||
| 79 | $styles = array(); |
||
| 80 | foreach ( $loaded_styles as $handle ) { |
||
| 81 | if ( !isset( $wp_styles->registered[ $handle ] ) ) |
||
| 82 | continue; |
||
| 83 | |||
| 84 | $src = $wp_styles->registered[ $handle ]->src; |
||
| 85 | |||
| 86 | // attach version and an extra query parameters |
||
| 87 | $ver = $this->get_version( $wp_styles->registered[ $handle ]->ver, $wp_styles->default_version ); |
||
| 88 | View Code Duplication | if ( isset( $wp_styles->args[ $handle ] ) ) { |
|
| 89 | $ver = $ver ? $ver . '&' . $wp_styles->args[$handle] : $wp_styles->args[$handle]; |
||
| 90 | } |
||
| 91 | $src = add_query_arg( 'ver', $ver, $src ); |
||
| 92 | |||
| 93 | // is there a special media (print, screen, etc) for this? if not, default to 'all' |
||
| 94 | $media = 'all'; |
||
| 95 | View Code Duplication | if ( isset( $wp_styles->registered[ $handle ]->args ) ) { |
|
| 96 | $media = esc_attr( $wp_styles->registered[ $handle ]->args ); |
||
| 97 | } |
||
| 98 | |||
| 99 | // add to an array so we can return all this info |
||
| 100 | $styles[ $handle ] = array ( |
||
| 101 | 'src' => $src, |
||
| 102 | 'media' => $media, |
||
| 103 | ); |
||
| 104 | } |
||
| 105 | |||
| 106 | $return['styles'] = $styles; |
||
| 107 | } |
||
| 108 | |||
| 109 | return $return; |
||
| 110 | } |
||
| 111 | |||
| 145 | } |