Conditions | 64 |
Paths | > 20000 |
Total Lines | 181 |
Code Lines | 99 |
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 |
||
155 | function youtube_id( $url ) { |
||
156 | if ( ! $id = jetpack_get_youtube_id( $url ) ) |
||
157 | return '<!--YouTube Error: bad URL entered-->'; |
||
158 | |||
159 | $url = youtube_sanitize_url( $url ); |
||
160 | $url = parse_url( $url ); |
||
161 | |||
162 | if ( ! isset( $url['query'] ) ) |
||
163 | return false; |
||
164 | |||
165 | if ( isset( $url['fragment'] ) ) { |
||
166 | wp_parse_str( $url['fragment'], $fargs ); |
||
167 | } else { |
||
168 | $fargs = array(); |
||
169 | } |
||
170 | wp_parse_str( $url['query'], $qargs ); |
||
171 | |||
172 | $qargs = array_merge( $fargs, $qargs ); |
||
173 | |||
174 | // calculate the width and height, taking content_width into consideration |
||
175 | global $content_width; |
||
176 | |||
177 | $input_w = ( isset( $qargs['w'] ) && intval( $qargs['w'] ) ) ? intval( $qargs['w'] ) : 0; |
||
178 | $input_h = ( isset( $qargs['h'] ) && intval( $qargs['h'] ) ) ? intval( $qargs['h'] ) : 0; |
||
179 | |||
180 | $default_width = get_option('embed_size_w'); |
||
181 | |||
182 | if ( empty( $default_width ) ) { |
||
183 | if ( ! empty( $content_width ) ) { |
||
184 | $default_width = $content_width; |
||
185 | } else { |
||
186 | $default_width = 640; |
||
187 | } |
||
188 | } |
||
189 | |||
190 | if ( $input_w > 0 && $input_h > 0 ) { |
||
191 | $w = $input_w; |
||
192 | $h = $input_h; |
||
193 | } elseif ( 0 == $input_w && 0 == $input_h ) { |
||
194 | if ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) { |
||
195 | $w = ( ! empty( $content_width ) ? min( $content_width, 480 ) : 480 ); |
||
196 | } else { |
||
197 | $w = ( ! empty( $content_width ) ? min( $content_width, $default_width ) : $default_width ); |
||
198 | $h = ceil( ( $w / 16 ) * 9 ) + 30; |
||
199 | } |
||
200 | } elseif ( $input_w > 0 ) { |
||
201 | $w = $input_w; |
||
202 | $h = ceil( ( $w / 16 ) * 9 ) + 30; |
||
203 | } else { |
||
204 | if ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) { |
||
205 | $w = ( ! empty( $content_width ) ? min( $content_width, 480 ) : 480 ); |
||
206 | } else { |
||
207 | $w = ( ! empty( $content_width ) ? min( $content_width, $default_width ) : $default_width ); |
||
208 | $h = $input_h; |
||
209 | } |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * Filter the YouTube player width. |
||
214 | * |
||
215 | * @module shortcodes |
||
216 | * |
||
217 | * @since 1.1.0 |
||
218 | * |
||
219 | * @param int $w Width of the YouTube player in pixels. |
||
220 | */ |
||
221 | $w = (int) apply_filters( 'youtube_width', $w ); |
||
222 | |||
223 | /** |
||
224 | * Filter the YouTube player height. |
||
225 | * |
||
226 | * @module shortcodes |
||
227 | * |
||
228 | * @since 1.1.0 |
||
229 | * |
||
230 | * @param int $h Height of the YouTube player in pixels. |
||
231 | */ |
||
232 | $h = (int) apply_filters( 'youtube_height', $h ); |
||
233 | |||
234 | $rel = ( isset( $qargs['rel'] ) && 0 == $qargs['rel'] ) ? 0 : 1; |
||
235 | $search = ( isset( $qargs['showsearch'] ) && 1 == $qargs['showsearch'] ) ? 1 : 0; |
||
236 | $info = ( isset( $qargs['showinfo'] ) && 0 == $qargs['showinfo'] ) ? 0 : 1; |
||
237 | $iv = ( isset( $qargs['iv_load_policy'] ) && 3 == $qargs['iv_load_policy'] ) ? 3 : 1; |
||
238 | |||
239 | $fmt = ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) ? '&fmt=' . (int) $qargs['fmt'] : ''; |
||
240 | |||
241 | if ( ! isset( $qargs['autohide'] ) || ( $qargs['autohide'] < 0 || 2 < $qargs['autohide'] ) ) { |
||
242 | $autohide = '&autohide=2'; |
||
243 | } else { |
||
244 | $autohide = '&autohide=' . absint( $qargs['autohide'] ); |
||
245 | } |
||
246 | |||
247 | $start = 0; |
||
248 | if ( isset( $qargs['start'] ) ) { |
||
249 | $start = intval( $qargs['start'] ); |
||
250 | } else if ( isset( $qargs['t'] ) ) { |
||
251 | $time_pieces = preg_split( '/(?<=\D)(?=\d+)/', $qargs['t'] ); |
||
252 | |||
253 | foreach ( $time_pieces as $time_piece ) { |
||
254 | $int = (int) $time_piece; |
||
255 | switch ( substr( $time_piece, -1 ) ) { |
||
256 | case 'h' : |
||
257 | $start += $int * 3600; |
||
258 | break; |
||
259 | case 'm' : |
||
260 | $start += $int * 60; |
||
261 | break; |
||
262 | case 's' : |
||
263 | $start += $int; |
||
264 | break; |
||
265 | } |
||
266 | } |
||
267 | } |
||
268 | |||
269 | $start = $start ? '&start=' . $start : ''; |
||
270 | $end = ( isset( $qargs['end'] ) && intval( $qargs['end'] ) ) ? '&end=' . (int) $qargs['end'] : ''; |
||
271 | $hd = ( isset( $qargs['hd'] ) && intval( $qargs['hd'] ) ) ? '&hd=' . (int) $qargs['hd'] : ''; |
||
272 | |||
273 | $vq = ( isset( $qargs['vq'] ) && in_array( $qargs['vq'], array('hd720','hd1080') ) ) ? '&vq=' . $qargs['vq'] : ''; |
||
274 | |||
275 | $cc = ( isset( $qargs['cc_load_policy'] ) ) ? '&cc_load_policy=1' : ''; |
||
276 | $cc_lang = ( isset( $qargs['cc_lang_pref'] ) ) ? '&cc_lang_pref=' . preg_replace( '/[^_a-z0-9-]/i', '', $qargs['cc_lang_pref'] ) : ''; |
||
277 | |||
278 | $wmode = ( isset( $qargs['wmode'] ) && in_array( strtolower( $qargs['wmode'] ), array( 'opaque', 'window', 'transparent' ) ) ) ? $qargs['wmode'] : 'transparent'; |
||
279 | |||
280 | $theme = ( isset( $qargs['theme'] ) && in_array( strtolower( $qargs['theme'] ), array( 'dark', 'light' ) ) ) ? '&theme=' . $qargs['theme'] : ''; |
||
281 | |||
282 | $autoplay = ''; |
||
283 | /** |
||
284 | * Allow YouTube videos to start playing automatically. |
||
285 | * |
||
286 | * @module shortcodes |
||
287 | * |
||
288 | * @since 2.2.2 |
||
289 | * |
||
290 | * @param bool false Enable autoplay for YouTube videos. |
||
291 | */ |
||
292 | if ( apply_filters( 'jetpack_youtube_allow_autoplay', false ) && isset( $qargs['autoplay'] ) ) |
||
293 | $autoplay = '&autoplay=' . (int)$qargs['autoplay']; |
||
294 | |||
295 | if ( ( isset( $url['path'] ) && '/videoseries' == $url['path'] ) || isset( $qargs['list'] ) ) { |
||
296 | $html = "<iframe class='youtube-player' type='text/html' width='$w' height='$h' src='" . esc_url( set_url_scheme( "http://www.youtube.com/embed/videoseries?list=$id&hl=en_US" ) ) . "' allowfullscreen='true' style='border:0;'></iframe>"; |
||
297 | } else { |
||
298 | $html = "<iframe class='youtube-player' type='text/html' width='$w' height='$h' src='" . esc_url( set_url_scheme( "http://www.youtube.com/embed/$id?version=3&rel=$rel&fs=1$fmt$autohide&showsearch=$search&showinfo=$info&iv_load_policy=$iv$start$end$hd&wmode=$wmode$theme$autoplay{$cc}{$cc_lang}" ) ) . "' allowfullscreen='true' style='border:0;'></iframe>"; |
||
299 | } |
||
300 | |||
301 | // Let's do some alignment wonder in a span, unless we're producing a feed |
||
302 | if ( ! is_feed() ) { |
||
303 | $alignmentcss = 'text-align:center;'; |
||
304 | if ( isset( $qargs['align'] ) ) { |
||
305 | switch ( $qargs['align'] ) { |
||
306 | case 'left': |
||
307 | $alignmentcss = "float:left; width:{$w}px; height:{$h}px; margin-right:10px; margin-bottom: 10px;"; |
||
308 | break; |
||
309 | case 'right': |
||
310 | $alignmentcss = "float:right; width:{$w}px; height:{$h}px; margin-left:10px; margin-bottom: 10px;"; |
||
311 | break; |
||
312 | } |
||
313 | } |
||
314 | |||
315 | $html = sprintf( |
||
316 | '<span class="embed-youtube" style="%s display: block;">%s</span>', |
||
317 | esc_attr( $alignmentcss ), |
||
318 | $html |
||
319 | ); |
||
320 | |||
321 | } |
||
322 | |||
323 | /** |
||
324 | * Filter the YouTube video HTML output. |
||
325 | * |
||
326 | * @module shortcodes |
||
327 | * |
||
328 | * @since 1.2.3 |
||
329 | * |
||
330 | * @param string $html YouTube video HTML output. |
||
331 | */ |
||
332 | $html = apply_filters( 'video_embed_html', $html ); |
||
333 | |||
334 | return $html; |
||
335 | } |
||
336 | |||
390 |
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignore
annotation.See also the PhpDoc documentation for @ignore.