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