Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 13 | class Tracking { |
||
| 14 | private $product_name; |
||
| 15 | private $connection; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Creates the Tracking object. |
||
| 19 | * |
||
| 20 | * @param String $product_name the slug of the product that we are tracking. |
||
| 21 | * @param Automattic\Jetpack\Connection\Manager $manager the connection manager object. |
||
|
|
|||
| 22 | */ |
||
| 23 | function __construct( $product_name = 'jetpack', $manager = null ) { |
||
| 31 | |||
| 32 | View Code Duplication | function enqueue_tracks_scripts() { |
|
| 43 | |||
| 44 | function record_user_event( $event_type, $data = array(), $user = null ) { |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Record an event in Tracks - this is the preferred way to record events from PHP. |
||
| 68 | * |
||
| 69 | * @param mixed $identity username, user_id, or WP_user object |
||
| 70 | * @param string $event_name The name of the event |
||
| 71 | * @param array $properties Custom properties to send with the event |
||
| 72 | * @param int $event_timestamp_millis The time in millis since 1970-01-01 00:00:00 when the event occurred |
||
| 73 | * |
||
| 74 | * @return bool true for success | \WP_Error if the event pixel could not be fired |
||
| 75 | */ |
||
| 76 | View Code Duplication | function tracks_record_event( $user, $event_name, $properties = array(), $event_timestamp_millis = false ) { |
|
| 91 | |||
| 92 | /** |
||
| 93 | * Procedurally build a Tracks Event Object. |
||
| 94 | * NOTE: Use this only when the simpler Automattic\Jetpack\Tracking->jetpack_tracks_record_event() function won't work for you. |
||
| 95 | * |
||
| 96 | * @param $identity WP_user object |
||
| 97 | * @param string $event_name The name of the event |
||
| 98 | * @param array $properties Custom properties to send with the event |
||
| 99 | * @param int $event_timestamp_millis The time in millis since 1970-01-01 00:00:00 when the event occurred |
||
| 100 | * |
||
| 101 | * @return \Jetpack_Tracks_Event|\WP_Error |
||
| 102 | */ |
||
| 103 | View Code Duplication | function tracks_build_event_obj( $user, $event_name, $properties = array(), $event_timestamp_millis = false ) { |
|
| 127 | |||
| 128 | /** |
||
| 129 | * Get the identity to send to tracks. |
||
| 130 | * |
||
| 131 | * @param int $user_id The user id of the local user |
||
| 132 | * |
||
| 133 | * @return array $identity |
||
| 134 | */ |
||
| 135 | function tracks_get_identity( $user_id ) { |
||
| 174 | } |
||
| 175 |
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.