| Conditions | 10 |
| Paths | 11 |
| Total Lines | 47 |
| Code Lines | 25 |
| 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 |
||
| 67 | function jetpack_tracks_get_identity( $user_id ) { |
||
| 68 | |||
| 69 | // Meta is set, and user is still connected. Use WPCOM ID |
||
| 70 | $wpcom_id = get_user_meta( $user_id, 'jetpack_tracks_wpcom_id', true ); |
||
| 71 | if ( $wpcom_id && Jetpack::is_user_connected( $user_id ) ) { |
||
| 72 | return array( |
||
| 73 | '_ut' => 'wpcom:user_id', |
||
| 74 | '_ui' => $wpcom_id |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | // User is connected, but no meta is set yet. Use WPCOM ID and set meta. |
||
| 79 | if ( Jetpack::is_user_connected( $user_id ) ) { |
||
| 80 | $wpcom_user_data = Jetpack::get_connected_user_data( $user_id ); |
||
| 81 | add_user_meta( $user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'], true ); |
||
| 82 | |||
| 83 | return array( |
||
| 84 | '_ut' => 'wpcom:user_id', |
||
| 85 | '_ui' => $wpcom_user_data['ID'] |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ( 0 === $user_id ) { |
||
| 90 | return array(); |
||
| 91 | } |
||
| 92 | |||
| 93 | // User isn't linked at all. Fall back to anonymous ID. |
||
| 94 | $anon_id = get_user_meta( $user_id, 'jetpack_tracks_anon_id', true ); |
||
| 95 | if ( ! $anon_id ) { |
||
| 96 | $anon_id = Jetpack_Tracks_Client::get_anon_id(); |
||
| 97 | update_user_meta( $user_id, 'jetpack_tracks_anon_id', $anon_id ); |
||
| 98 | } |
||
| 99 | |||
| 100 | if ( isset( $_COOKIE['tk_ai'] ) && $anon_id !== $_COOKIE['tk_ai'] ) { |
||
| 101 | unset( $_COOKIE['tk_ai'] ); |
||
| 102 | } |
||
| 103 | |||
| 104 | if ( ! isset( $_COOKIE[ 'tk_ai' ] ) && ! headers_sent() ) { |
||
| 105 | setcookie( 'tk_ai', $anon_id, 0, '/' ); |
||
| 106 | } |
||
| 107 | |||
| 108 | return array( |
||
| 109 | '_ut' => 'anon', |
||
| 110 | '_ui' => $anon_id |
||
| 111 | ); |
||
| 112 | |||
| 113 | } |
||
| 114 | |||
| 139 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.