Conditions | 6 |
Paths | 6 |
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 |
||
34 | public static function jetpack_tweet_shortcode( $atts ) { |
||
35 | global $wp_embed; |
||
36 | $default_atts = array( |
||
37 | 'tweet' => '', |
||
38 | 'align' => 'none', |
||
39 | 'width' => '', |
||
40 | 'lang' => 'en', |
||
41 | 'hide_thread' => 'false', |
||
42 | 'hide_media' => 'false', |
||
43 | ); |
||
44 | |||
45 | $attr = shortcode_atts( $default_atts, $atts ); |
||
46 | |||
47 | self::$provider_args = $attr; |
||
48 | |||
49 | // figure out the tweet id for the requested tweet |
||
50 | // supporting both omitted attributes and tweet="tweet_id" |
||
51 | // and supporting both an id and a URL |
||
52 | if ( empty( $attr['tweet'] ) && ! empty( $atts[0] ) ) { |
||
53 | $attr['tweet'] = $atts[0]; |
||
54 | } |
||
55 | |||
56 | if ( ctype_digit( $attr['tweet'] ) ) { |
||
57 | $id = 'https://twitter.com/jetpack/status/' . $attr['tweet']; |
||
58 | } else { |
||
59 | preg_match( '/^http(s|):\/\/twitter\.com(\/\#\!\/|\/)([a-zA-Z0-9_]{1,20})\/status(es)*\/(\d+)$/', $attr['tweet'], $urlbits ); |
||
60 | |||
61 | if ( isset( $urlbits[5] ) && intval( $urlbits[5] ) ) { |
||
62 | $id = 'https://twitter.com/' . $urlbits[3] . '/status/' . intval( $urlbits[5] ); |
||
63 | } else { |
||
64 | return '<!-- Invalid tweet id -->'; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | // Add shortcode arguments to provider URL |
||
69 | add_filter( 'oembed_fetch_url', array( 'Jetpack_Tweet', 'jetpack_tweet_url_extra_args' ), 10, 3 ); |
||
70 | |||
71 | // Fetch tweet |
||
72 | $output = $wp_embed->shortcode( $atts, $id ); |
||
73 | |||
74 | // Clean up filter |
||
75 | remove_filter( 'oembed_fetch_url', array( 'Jetpack_Tweet', 'jetpack_tweet_url_extra_args' ), 10 ); |
||
76 | |||
77 | // Add Twitter widgets.js script to the footer. |
||
78 | add_action( 'wp_footer', array( 'Jetpack_Tweet', 'jetpack_tweet_shortcode_script' ) ); |
||
79 | |||
80 | /** This action is documented in modules/widgets/social-media-icons.php */ |
||
81 | do_action( 'jetpack_bump_stats_extras', 'embeds', 'tweet' ); |
||
82 | |||
83 | return $output; |
||
84 | } |
||
85 | |||
147 |