Code Duplication    Length = 25-27 lines in 2 locations

packages/connection/src/Manager.php 1 location

@@ 524-550 (lines=27) @@
521
	 * @param Integer $user_id the user identifier.
522
	 * @return Object the user object.
523
	 */
524
	public function get_connected_user_data( $user_id = null ) {
525
		if ( ! $user_id ) {
526
			$user_id = get_current_user_id();
527
		}
528
529
		$transient_key    = "jetpack_connected_user_data_$user_id";
530
		$cached_user_data = get_transient( $transient_key );
531
532
		if ( $cached_user_data ) {
533
			return $cached_user_data;
534
		}
535
536
		\Jetpack::load_xml_rpc_client();
537
		$xml = new \Jetpack_IXR_Client(
538
			array(
539
				'user_id' => $user_id,
540
			)
541
		);
542
		$xml->query( 'wpcom.getUser' );
543
		if ( ! $xml->isError() ) {
544
			$user_data = $xml->getResponse();
545
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
546
			return $user_data;
547
		}
548
549
		return false;
550
	}
551
552
	/**
553
	 * Returns true if the provided user is the Jetpack connection owner.

class.jetpack.php 1 location

@@ 1677-1701 (lines=25) @@
1674
	/**
1675
	 * Get the wpcom user data of the current|specified connected user.
1676
	 */
1677
	public static function get_connected_user_data( $user_id = null ) {
1678
		// TODO: remove in favor of Connection_Manager->get_connected_user_data
1679
		if ( ! $user_id ) {
1680
			$user_id = get_current_user_id();
1681
		}
1682
1683
		$transient_key = "jetpack_connected_user_data_$user_id";
1684
1685
		if ( $cached_user_data = get_transient( $transient_key ) ) {
1686
			return $cached_user_data;
1687
		}
1688
1689
		Jetpack::load_xml_rpc_client();
1690
		$xml = new Jetpack_IXR_Client( array(
1691
			'user_id' => $user_id,
1692
		) );
1693
		$xml->query( 'wpcom.getUser' );
1694
		if ( ! $xml->isError() ) {
1695
			$user_data = $xml->getResponse();
1696
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
1697
			return $user_data;
1698
		}
1699
1700
		return false;
1701
	}
1702
1703
	/**
1704
	 * Get the wpcom email of the current|specified connected user.