| Conditions | 14 |
| Paths | 122 |
| Total Lines | 50 |
| 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 |
||
| 62 | function process_anchor_params() { |
||
| 63 | $current_screen = \get_current_screen(); |
||
| 64 | // TODO: Replace `$current_screen->is_block_editor()` with `wp_should_load_block_editor_scripts_and_styles()` that is introduced in WP 5.6. |
||
| 65 | if ( method_exists( $current_screen, 'is_block_editor' ) && ! $current_screen->is_block_editor() ) { |
||
| 66 | // Return early if we are not in the block editor. |
||
| 67 | return; |
||
| 68 | } |
||
| 69 | |||
| 70 | $post = get_post(); |
||
| 71 | if ( ! $post || ! $post->ID ) { |
||
| 72 | return; |
||
| 73 | } |
||
| 74 | |||
| 75 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
||
| 76 | $podcast_id = isset( $_GET['anchor_podcast'] ) ? sanitize_text_field( $_GET['anchor_podcast'] ) : null; |
||
| 77 | $episode_id = isset( $_GET['anchor_episode'] ) ? sanitize_text_field( $_GET['anchor_episode'] ) : null; |
||
| 78 | $spotify_show_url = isset( $_GET['spotify_show_url'] ) ? esc_url_raw( $_GET['spotify_show_url'] ) : null; |
||
| 79 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
||
| 80 | |||
| 81 | $data = array(); |
||
| 82 | |||
| 83 | if ( ! empty( $podcast_id ) ) { |
||
| 84 | $feed = 'https://anchor.fm/s/' . $podcast_id . '/podcast/rss'; |
||
| 85 | $rss = Jetpack_Podcast_Helper::load_feed( $feed ); |
||
| 86 | if ( ! \is_wp_error( $rss ) ) { |
||
| 87 | $data['podcastId'] = $podcast_id; |
||
| 88 | update_post_meta( $post->ID, 'jetpack_anchor_podcast', $podcast_id ); |
||
| 89 | |||
| 90 | if ( ! empty( $episode_id ) ) { |
||
| 91 | $track = Jetpack_Podcast_Helper::get_track_data( $feed, $episode_id ); |
||
| 92 | if ( ! \is_wp_error( $track ) ) { |
||
| 93 | $data['episodeId'] = $episode_id; |
||
| 94 | $data['track'] = $track; |
||
| 95 | update_post_meta( $post->ID, 'jetpack_anchor_episode', $episode_id ); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | if ( ! empty( $spotify_show_url ) ) { |
||
| 102 | $data['spotifyShowUrl'] = $spotify_show_url; |
||
| 103 | if ( get_post_meta( $post->ID, 'jetpack_anchor_spotify_show', true ) !== $spotify_show_url ) { |
||
| 104 | update_post_meta( $post->ID, 'jetpack_anchor_spotify_show', $spotify_show_url ); |
||
| 105 | $data['action'] = 'insert-spotify-badge'; |
||
| 106 | $data['image'] = Assets::staticize_subdomain( 'https://wordpress.com/i/spotify-badge.svg' ); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | wp_localize_script( 'jetpack-blocks-editor', 'Jetpack_AnchorFm', $data ); |
||
| 111 | } |
||
| 112 | |||
| 115 |