| Conditions | 11 |
| Paths | 6 |
| Total Lines | 43 |
| 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 |
||
| 46 | * Render the core video block replacing the src attribute with the VideoPress URL |
||
| 47 | * |
||
| 48 | * @param array $attributes Array containing the video block attributes. |
||
| 49 | * @param string $content String containing the video block content. |
||
| 50 | * |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | public static function render_video_block_with_videopress( $attributes, $content ) { |
||
| 54 | if ( ! isset( $attributes['id'] ) || isset( $attributes['guid'] ) ) { |
||
| 55 | return $content; |
||
| 56 | } |
||
| 57 | |||
| 58 | View Code Duplication | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 59 | $blog_id = get_current_blog_id(); |
||
| 60 | } else { |
||
| 61 | $blog_id = Jetpack_Options::get_option( 'id' ); |
||
| 62 | } |
||
| 63 | |||
| 64 | $post_id = absint( $attributes['id'] ); |
||
| 65 | $videopress_id = video_get_info_by_blogpostid( $blog_id, $post_id )->guid; |
||
| 66 | $videopress_data = videopress_get_video_details( $videopress_id ); |
||
| 67 | |||
| 68 | if ( empty( $videopress_data->file_url_base->https ) || empty( $videopress_data->files->hd->mp4 ) ) { |
||
| 69 | return $content; |
||
| 70 | } |
||
| 71 | |||
| 72 | $videopress_url = $videopress_data->file_url_base->https . $videopress_data->files->hd->mp4; |
||
| 73 | |||
| 74 | $pattern = '/(\s)src=([\'"])(?:(?!\2).)+?\2/'; |
||
| 75 | |||
| 76 | return preg_replace( |
||
| 77 | $pattern, |
||
| 78 | sprintf( |
||
| 79 | '\1src="%1$s"', |
||
| 80 | esc_url_raw( $videopress_url ) |
||
| 81 | ), |
||
| 82 | $content, |
||
| 83 | 1 |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | VideoPress_Gutenberg::init(); |
||
| 89 |