| Conditions | 18 |
| Paths | 99 |
| Total Lines | 67 |
| 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 |
||
| 89 | function process_anchor_params() { |
||
| 90 | if ( |
||
| 91 | ! function_exists( 'get_current_screen' ) |
||
| 92 | || is_null( \get_current_screen() ) |
||
| 93 | ) { |
||
| 94 | return; |
||
| 95 | } |
||
| 96 | |||
| 97 | $current_screen = \get_current_screen(); |
||
| 98 | // TODO: Replace `$current_screen->is_block_editor()` with `wp_should_load_block_editor_scripts_and_styles()` that is introduced in WP 5.6. |
||
| 99 | if ( method_exists( $current_screen, 'is_block_editor' ) && ! $current_screen->is_block_editor() ) { |
||
| 100 | // Return early if we are not in the block editor. |
||
| 101 | return; |
||
| 102 | } |
||
| 103 | |||
| 104 | $post = get_post(); |
||
| 105 | if ( ! $post || ! $post->ID ) { |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | |||
| 109 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
||
| 110 | $podcast_id = isset( $_GET['anchor_podcast'] ) ? sanitize_text_field( wp_unslash( $_GET['anchor_podcast'] ) ) : null; |
||
| 111 | $episode_id = isset( $_GET['anchor_episode'] ) ? sanitize_text_field( wp_unslash( $_GET['anchor_episode'] ) ) : null; |
||
| 112 | $spotify_show_url = isset( $_GET['spotify_show_url'] ) ? esc_url_raw( wp_unslash( $_GET['spotify_show_url'] ) ) : null; |
||
| 113 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
||
| 114 | |||
| 115 | $data = array( |
||
| 116 | 'actions' => array(), |
||
| 117 | ); |
||
| 118 | |||
| 119 | if ( ! empty( $podcast_id ) ) { |
||
| 120 | $feed = 'https://anchor.fm/s/' . $podcast_id . '/podcast/rss'; |
||
| 121 | $podcast_helper = new Jetpack_Podcast_Helper( $feed ); |
||
| 122 | $rss = $podcast_helper->load_feed(); |
||
| 123 | if ( ! \is_wp_error( $rss ) ) { |
||
| 124 | update_post_meta( $post->ID, 'jetpack_anchor_podcast', $podcast_id ); |
||
| 125 | |||
| 126 | if ( ! empty( $episode_id ) ) { |
||
| 127 | $track = $podcast_helper->get_track_data( $episode_id ); |
||
| 128 | if ( ! \is_wp_error( $track ) ) { |
||
| 129 | update_post_meta( $post->ID, 'jetpack_anchor_episode', $episode_id ); |
||
| 130 | |||
| 131 | if ( 'post-new.php' === $GLOBALS['pagenow'] ) { |
||
| 132 | $data['actions'][] = array( |
||
| 133 | 'set-episode-title', |
||
| 134 | array( |
||
| 135 | 'title' => $track['title'], |
||
| 136 | ), |
||
| 137 | ); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | // Display an outbound link after publishing a post (only to English-speaking users since Anchor |
||
| 145 | // is English only). |
||
| 146 | if ( |
||
| 147 | 'post' === get_post_type() && |
||
| 148 | ! get_post_meta( $post->ID, 'jetpack_anchor_spotify_show', true ) && |
||
| 149 | 0 === strpos( get_user_locale(), 'en' ) |
||
| 150 | ) { |
||
| 151 | $data['actions'][] = 'show-post-publish-outbound-link'; |
||
| 152 | } |
||
| 153 | |||
| 154 | wp_localize_script( 'jetpack-blocks-editor', 'Jetpack_AnchorFm', $data ); |
||
| 155 | } |
||
| 156 | |||
| 159 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.