Conditions | 11 |
Paths | 272 |
Total Lines | 51 |
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 |
||
24 | function jetpack_gif_block_render( $attr ) { |
||
25 | $padding_top = isset( $attr['paddingTop'] ) ? $attr['paddingTop'] : 0; |
||
26 | $style = 'padding-top:' . $padding_top; |
||
27 | $giphy_url = isset( $attr['giphyUrl'] ) ? $attr['giphyUrl'] : null; |
||
28 | $search_text = isset( $attr['searchText'] ) ? $attr['searchText'] : ''; |
||
29 | $caption = isset( $attr['caption'] ) ? $attr['caption'] : null; |
||
30 | |||
31 | if ( ! $giphy_url ) { |
||
32 | return null; |
||
33 | } |
||
34 | |||
35 | /* TODO: replace with centralized block_class function */ |
||
36 | $align = isset( $attr['align'] ) ? $attr['align'] : 'center'; |
||
37 | $type = 'gif'; |
||
38 | $classes = array( |
||
39 | 'wp-block-jetpack-' . $type, |
||
40 | 'align' . $align, |
||
41 | ); |
||
42 | if ( isset( $attr['className'] ) ) { |
||
43 | array_push( $classes, $attr['className'] ); |
||
44 | } |
||
45 | $classes = implode( $classes, ' ' ); |
||
46 | $placeholder = sprintf( '<a href="%s">%s</a>', esc_url( $giphy_url ), esc_attr( $search_text ) ); |
||
47 | |||
48 | ob_start(); |
||
49 | ?> |
||
50 | <div class="<?php echo esc_attr( $classes ); ?>"> |
||
51 | <figure> |
||
52 | <?php if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) : ?> |
||
53 | <amp-iframe src="<?php echo esc_url( $giphy_url ); ?>" width="100" height="<?php echo absint( $padding_top ); ?>" sandbox="allow-scripts allow-same-origin" layout="responsive"> |
||
54 | <div placeholder> |
||
55 | <?php echo wp_kses_post( $placeholder ); ?> |
||
56 | </div> |
||
57 | </amp-iframe> |
||
58 | <?php else : ?> |
||
59 | <div class="wp-block-jetpack-gif-wrapper" style="<?php echo esc_attr( $style ); ?>"> |
||
60 | <iframe src="<?php echo esc_url( $giphy_url ); ?>" title="<?php echo esc_attr( $search_text ); ?>"></iframe> |
||
61 | </div> |
||
62 | <?php endif; ?> |
||
63 | <?php if ( $caption ) : ?> |
||
64 | <figcaption class="wp-block-jetpack-gif-caption gallery-caption"><?php echo wp_kses_post( $caption ); ?></figcaption> |
||
65 | <?php endif; ?> |
||
66 | </figure> |
||
67 | </div> |
||
68 | <?php |
||
69 | $html = ob_get_clean(); |
||
70 | |||
71 | Jetpack_Gutenberg::load_assets_as_required( 'gif' ); |
||
72 | |||
73 | return $html; |
||
74 | } |
||
75 |