Conditions | 7 |
Paths | 4 |
Total Lines | 55 |
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 |
||
77 | function jetpack_responsive_videos_maybe_wrap_oembed( $html, $url = null ) { |
||
78 | if ( empty( $html ) || ! is_string( $html ) || ! $url ) { |
||
79 | return $html; |
||
80 | } |
||
81 | |||
82 | $jetpack_video_wrapper = '<div class="jetpack-video-wrapper">'; |
||
83 | |||
84 | $already_wrapped = strpos( $html, $jetpack_video_wrapper ); |
||
85 | |||
86 | // If the oEmbed has already been wrapped, return the html. |
||
87 | if ( false !== $already_wrapped ) { |
||
88 | return $html; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * oEmbed Video Providers. |
||
93 | * |
||
94 | * A whitelist of oEmbed video provider Regex patterns to check against before wrapping the output. |
||
95 | * |
||
96 | * @module theme-tools |
||
97 | * |
||
98 | * @since 3.8.0 |
||
99 | * |
||
100 | * @param array $video_patterns oEmbed video provider Regex patterns. |
||
101 | */ |
||
102 | $video_patterns = apply_filters( |
||
103 | 'jetpack_responsive_videos_oembed_videos', |
||
104 | array( |
||
105 | 'https?://((m|www)\.)?youtube\.com/watch', |
||
106 | 'https?://((m|www)\.)?youtube\.com/playlist', |
||
107 | 'https?://youtu\.be/', |
||
108 | 'https?://(.+\.)?vimeo\.com/', |
||
109 | 'https?://(www\.)?dailymotion\.com/', |
||
110 | 'https?://dai.ly/', |
||
111 | 'https?://(www\.)?hulu\.com/watch/', |
||
112 | 'https?://wordpress.tv/', |
||
113 | 'https?://(www\.)?funnyordie\.com/videos/', |
||
114 | 'https?://vine.co/v/', |
||
115 | 'https?://(www\.)?collegehumor\.com/video/', |
||
116 | 'https?://(www\.|embed\.)?ted\.com/talks/', |
||
117 | ) |
||
118 | ); |
||
119 | |||
120 | // Merge patterns to run in a single preg_match call. |
||
121 | $video_patterns = '(' . implode( '|', $video_patterns ) . ')'; |
||
122 | |||
123 | $is_video = preg_match( $video_patterns, $url ); |
||
124 | |||
125 | // If the oEmbed is a video, wrap it in the responsive wrapper. |
||
126 | if ( false === $already_wrapped && 1 === $is_video ) { |
||
127 | return jetpack_responsive_videos_embed_html( $html ); |
||
128 | } |
||
129 | |||
130 | return $html; |
||
131 | } |
||
132 | |||
153 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.