| Conditions | 5 |
| Paths | 10 |
| 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 |
||
| 70 | function render_player( $track_list ) { |
||
| 71 | global $content_width; |
||
| 72 | |||
| 73 | $player_data = array( |
||
| 74 | 'type' => 'audio', |
||
| 75 | // Don't pass strings to JSON, will be truthy in JS. |
||
| 76 | 'tracklist' => true, |
||
| 77 | 'tracknumbers' => true, |
||
| 78 | 'images' => true, |
||
| 79 | 'artists' => true, |
||
| 80 | 'tracks' => $track_list, |
||
| 81 | ); |
||
| 82 | |||
| 83 | $outer = 22; // Default padding and border of wrapper. |
||
| 84 | $default_width = 640; |
||
| 85 | $theme_width = empty( $content_width ) ? $default_width : ( $content_width - $outer ); |
||
| 86 | |||
| 87 | // If there are no tracks (it is possible) then display appropriate user facing error message. |
||
| 88 | if ( empty( $track_list ) ) { |
||
| 89 | return '<p>' . __( 'No tracks available to play.', 'jetpack' ) . '</p>'; |
||
| 90 | } |
||
| 91 | |||
| 92 | ob_start(); |
||
| 93 | wp_playlist_scripts( 'audio' ); |
||
| 94 | /** |
||
| 95 | * Prints and enqueues playlist scripts, styles, and JavaScript templates. |
||
| 96 | * |
||
| 97 | * @since 3.9.0 |
||
| 98 | * |
||
| 99 | * @param string $type Type of playlist. Possible values are 'audio' or 'video'. |
||
| 100 | * @param string $style The 'theme' for the playlist. Core provides 'light' and 'dark'. |
||
| 101 | */ |
||
| 102 | do_action( 'wp_playlist_scripts', 'audio', 'light' ); |
||
| 103 | |||
| 104 | $initial_track_src = ! empty( $track_list[0]['src'] ) ? $track_list[0]['src'] : ''; |
||
| 105 | |||
| 106 | ?> |
||
| 107 | <div class="wp-block-<?php echo esc_attr( $initial_track_src ); ?> wp-playlist wp-audio-playlist wp-playlist-light"> |
||
| 108 | <div class="wp-playlist-current-item"></div> |
||
| 109 | <audio src="<?php echo esc_url( $track_list[0]['src'] ); ?>" controls="controls" preload="none" width="<?php echo esc_attr( (int) $theme_width ); ?>"></audio> |
||
| 110 | <div class="wp-playlist-next"></div> |
||
| 111 | <div class="wp-playlist-prev"></div> |
||
| 112 | <noscript> |
||
| 113 | <ol> |
||
| 114 | <?php |
||
| 115 | foreach ( $track_list as $track ) : |
||
| 116 | printf( '<li>%s</li>', esc_url( $track['src'] ) ); |
||
| 117 | endforeach; |
||
| 118 | ?> |
||
| 119 | </ol> |
||
| 120 | </noscript> |
||
| 121 | <script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode( $player_data ); ?></script> |
||
| 122 | </div> |
||
| 123 | <?php |
||
| 124 | /* |
||
| 125 | * Enqueue necessary scripts and styles. |
||
| 126 | */ |
||
| 127 | \Jetpack_Gutenberg::load_assets_as_required( 'podcast-player' ); |
||
| 128 | |||
| 129 | return ob_get_clean(); |
||
| 130 | } |
||
| 131 | |||
| 190 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.