| Conditions | 8 |
| Paths | 33 |
| Total Lines | 71 |
| 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 |
||
| 93 | function render_player( $player_data, $attributes ) { |
||
| 94 | // If there are no tracks (it is possible) then display appropriate user facing error message. |
||
| 95 | if ( empty( $player_data['tracks'] ) ) { |
||
| 96 | return '<p>' . esc_html__( 'No tracks available to play.', 'jetpack' ) . '</p>'; |
||
| 97 | } |
||
| 98 | |||
| 99 | // Only use the amount of tracks requested. |
||
| 100 | $player_data['tracks'] = array_slice( |
||
| 101 | $player_data['tracks'], |
||
| 102 | 0, |
||
| 103 | absint( $attributes['itemsToShow'] ) |
||
| 104 | ); |
||
| 105 | |||
| 106 | // Genereate a unique id for the block instance. |
||
| 107 | $instance_id = wp_unique_id( 'jetpack-podcast-player-block-' ); |
||
| 108 | $player_data['playerId'] = $instance_id; |
||
| 109 | |||
| 110 | // Generate object to be used as props for PodcastPlayer. |
||
| 111 | $player_props = array_merge( |
||
| 112 | // Add all attributes. |
||
| 113 | array( 'attributes' => $attributes ), |
||
| 114 | // Add all player data. |
||
| 115 | $player_data |
||
| 116 | ); |
||
| 117 | |||
| 118 | $block_classname = Jetpack_Gutenberg::block_classes( FEATURE_NAME, $attributes, array( 'is-default' ) ); |
||
| 119 | $is_amp = ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ); |
||
| 120 | |||
| 121 | ob_start(); |
||
| 122 | ?> |
||
| 123 | <div class="<?php echo esc_attr( $block_classname ); ?>" id="<?php echo esc_attr( $instance_id ); ?>"> |
||
| 124 | <ol class="jetpack-podcast-player__episodes"> |
||
| 125 | <?php foreach ( $player_data['tracks'] as $attachment ) : ?> |
||
| 126 | <li class="jetpack-podcast-player__episode"> |
||
| 127 | <a |
||
| 128 | class="jetpack-podcast-player__episode-link" |
||
| 129 | href="<?php echo esc_url( $attachment['link'] ); ?>" |
||
| 130 | role="button" |
||
| 131 | aria-pressed="false" |
||
| 132 | > |
||
| 133 | <span class="jetpack-podcast-player__episode-status-icon"></span> |
||
| 134 | <span class="jetpack-podcast-player__episode-title"><?php echo esc_html( $attachment['title'] ); ?></span> |
||
| 135 | <time class="jetpack-podcast-player__episode-duration"><?php echo ( ! empty( $attachment['duration'] ) ? esc_html( $attachment['duration'] ) : '' ); ?></time> |
||
| 136 | </a> |
||
| 137 | </li> |
||
| 138 | <?php endforeach; ?> |
||
| 139 | </ol> |
||
| 140 | <?php if ( ! $is_amp ) : ?> |
||
| 141 | <script type="application/json"><?php echo wp_json_encode( $player_props ); ?></script> |
||
| 142 | <?php endif; ?> |
||
| 143 | </div> |
||
| 144 | <?php if ( ! $is_amp ) : ?> |
||
| 145 | <script> |
||
| 146 | ( function( instanceId ) { |
||
| 147 | document.getElementById( instanceId ).classList.remove( 'is-default' ); |
||
| 148 | window.jetpackPodcastPlayers=(window.jetpackPodcastPlayers||[]); |
||
| 149 | window.jetpackPodcastPlayers.push( instanceId ); |
||
| 150 | } )( <?php echo wp_json_encode( $instance_id ); ?> ); |
||
| 151 | </script> |
||
| 152 | <?php endif; ?> |
||
| 153 | <?php |
||
| 154 | /** |
||
| 155 | * Enqueue necessary scripts and styles. |
||
| 156 | */ |
||
| 157 | if ( ! $is_amp ) { |
||
| 158 | wp_enqueue_style( 'mediaelement' ); |
||
| 159 | } |
||
| 160 | Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME, array( 'mediaelement' ) ); |
||
| 161 | |||
| 162 | return ob_get_clean(); |
||
| 163 | } |
||
| 164 |
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.