| Conditions | 8 |
| Paths | 25 |
| Total Lines | 57 |
| 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 //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
| 56 | public static function render_upgrade_nudge( $props ) { |
||
| 57 | $plan_slug = $props['plan']; |
||
| 58 | jetpack_require_lib( 'plans' ); |
||
| 59 | $plan = Jetpack_Plans::get_plan( $plan_slug ); |
||
| 60 | |||
| 61 | if ( ! $plan ) { |
||
| 62 | return self::render_component( |
||
| 63 | 'upgrade-nudge', |
||
| 64 | array( |
||
| 65 | 'planName' => __( 'a paid plan', 'jetpack' ), |
||
| 66 | 'upgradeUrl' => '', |
||
| 67 | ) |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | |||
| 71 | // WP.com plan objects have a dedicated `path_slug` field, Jetpack plan objects don't |
||
| 72 | // For Jetpack, we thus use the plan slug with the 'jetpack_' prefix removed. |
||
| 73 | $plan_path_slug = wp_startswith( $plan_slug, 'jetpack_' ) |
||
| 74 | ? substr( $plan_slug, strlen( 'jetpack_' ) ) |
||
| 75 | : $plan->path_slug; |
||
| 76 | |||
| 77 | $post_id = get_the_ID(); |
||
| 78 | $post_type = get_post_type(); |
||
| 79 | |||
| 80 | // The editor for CPTs has an `edit/` route fragment prefixed. |
||
| 81 | $post_type_editor_route_prefix = in_array( $post_type, array( 'page', 'post' ), true ) ? '' : 'edit'; |
||
|
|
|||
| 82 | |||
| 83 | if ( method_exists( 'Jetpack', 'build_raw_urls' ) ) { |
||
| 84 | $site_slug = Jetpack::build_raw_urls( home_url() ); |
||
| 85 | } elseif ( class_exists( 'WPCOM_Masterbar' ) && method_exists( 'WPCOM_Masterbar', 'get_calypso_site_slug' ) ) { |
||
| 86 | $site_slug = WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); |
||
| 87 | } |
||
| 88 | |||
| 89 | // Post-checkout: redirect back to the editor. |
||
| 90 | $redirect_to = add_query_arg( |
||
| 91 | array( |
||
| 92 | 'plan_upgraded' => 1, |
||
| 93 | ), |
||
| 94 | get_edit_post_link( $post_id ) |
||
| 95 | ); |
||
| 96 | |||
| 97 | $upgrade_url = |
||
| 98 | $plan_path_slug |
||
| 99 | ? add_query_arg( |
||
| 100 | 'redirect_to', |
||
| 101 | $redirect_to, |
||
| 102 | "https://wordpress.com/checkout/${site_slug}/${plan_path_slug}" |
||
| 103 | ) : ''; |
||
| 104 | |||
| 105 | return self::render_component( |
||
| 106 | 'upgrade-nudge', |
||
| 107 | array( |
||
| 108 | 'planName' => $plan->product_name, |
||
| 109 | 'upgradeUrl' => $upgrade_url, |
||
| 110 | ) |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | } |
||
| 114 |
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.