| Conditions | 7 |
| Paths | 17 |
| Total Lines | 88 |
| 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 |
||
| 108 | function render_player( $player_data, $attributes ) { |
||
| 109 | // If there are no tracks (it is possible) then display appropriate user facing error message. |
||
| 110 | if ( empty( $player_data['tracks'] ) ) { |
||
| 111 | return render_error( __( 'No tracks available to play.', 'jetpack' ) ); |
||
| 112 | } |
||
| 113 | |||
| 114 | // Only use the amount of tracks requested. |
||
| 115 | $player_data['tracks'] = array_slice( |
||
| 116 | $player_data['tracks'], |
||
| 117 | 0, |
||
| 118 | absint( $attributes['itemsToShow'] ) |
||
| 119 | ); |
||
| 120 | |||
| 121 | // Generate a unique id for the block instance. |
||
| 122 | $instance_id = wp_unique_id( 'jetpack-podcast-player-block-' . get_the_ID() . '-' ); |
||
| 123 | $player_data['playerId'] = $instance_id; |
||
| 124 | |||
| 125 | // Generate object to be used as props for PodcastPlayer. |
||
| 126 | $player_props = array_merge( |
||
| 127 | // Add all attributes. |
||
| 128 | array( 'attributes' => $attributes ), |
||
| 129 | // Add all player data. |
||
| 130 | $player_data |
||
| 131 | ); |
||
| 132 | |||
| 133 | $primary_colors = get_colors( 'primary', $attributes, 'color' ); |
||
| 134 | $secondary_colors = get_colors( 'secondary', $attributes, 'color' ); |
||
| 135 | $background_colors = get_colors( 'background', $attributes, 'background-color' ); |
||
| 136 | |||
| 137 | $player_classes_name = trim( "{$secondary_colors['class']} {$background_colors['class']}" ); |
||
| 138 | $player_inline_style = trim( "{$secondary_colors['style']} ${background_colors['style']}" ); |
||
| 139 | $player_inline_style .= get_css_vars( $attributes ); |
||
| 140 | |||
| 141 | $block_classname = Jetpack_Gutenberg::block_classes( FEATURE_NAME, $attributes, array( 'is-default' ) ); |
||
| 142 | $is_amp = ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ); |
||
| 143 | |||
| 144 | ob_start(); |
||
| 145 | ?> |
||
| 146 | <div class="<?php echo esc_attr( $block_classname ); ?>" id="<?php echo esc_attr( $instance_id ); ?>"> |
||
| 147 | <section |
||
| 148 | class="jetpack-podcast-player <?php echo esc_attr( $player_classes_name ); ?>" |
||
| 149 | style="<?php echo esc_attr( $player_inline_style ); ?>" |
||
| 150 | > |
||
| 151 | <?php |
||
| 152 | render( |
||
| 153 | 'podcast-header', |
||
| 154 | array_merge( |
||
| 155 | $player_props, |
||
| 156 | array( |
||
| 157 | 'primary_colors' => $primary_colors, |
||
| 158 | 'player_id' => $player_data['playerId'], |
||
| 159 | ) |
||
| 160 | ) |
||
| 161 | ); |
||
| 162 | ?> |
||
| 163 | <?php if ( count( $player_data['tracks'] ) > 1 ) : ?> |
||
| 164 | <ol class="jetpack-podcast-player__tracks"> |
||
| 165 | <?php foreach ( $player_data['tracks'] as $track_index => $attachment ) : ?> |
||
| 166 | <?php |
||
| 167 | render( |
||
| 168 | 'playlist-track', |
||
| 169 | array( |
||
| 170 | 'is_active' => 0 === $track_index, |
||
| 171 | 'attachment' => $attachment, |
||
| 172 | 'primary_colors' => $primary_colors, |
||
| 173 | 'secondary_colors' => $secondary_colors, |
||
| 174 | ) |
||
| 175 | ); |
||
| 176 | ?> |
||
| 177 | <?php endforeach; ?> |
||
| 178 | </ol> |
||
| 179 | <?php endif; ?> |
||
| 180 | </section> |
||
| 181 | <?php if ( ! $is_amp ) : ?> |
||
| 182 | <script type="application/json"><?php echo wp_json_encode( $player_props ); ?></script> |
||
| 183 | <?php endif; ?> |
||
| 184 | </div> |
||
| 185 | <?php |
||
| 186 | /** |
||
| 187 | * Enqueue necessary scripts and styles. |
||
| 188 | */ |
||
| 189 | if ( ! $is_amp ) { |
||
| 190 | wp_enqueue_style( 'wp-mediaelement' ); |
||
| 191 | } |
||
| 192 | Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME, array( 'mediaelement' ) ); |
||
| 193 | |||
| 194 | return ob_get_clean(); |
||
| 195 | } |
||
| 196 | |||
| 303 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.