Code Duplication    Length = 25-27 lines in 2 locations

packages/connection/src/Manager.php 1 location

@@ 77-103 (lines=27) @@
74
	 * @param Integer $user_id the user identifier.
75
	 * @return Object the user object.
76
	 */
77
	public function get_connected_user_data( $user_id = null ) {
78
		if ( ! $user_id ) {
79
			$user_id = get_current_user_id();
80
		}
81
82
		$transient_key    = "jetpack_connected_user_data_$user_id";
83
		$cached_user_data = get_transient( $transient_key );
84
85
		if ( $cached_user_data ) {
86
			return $cached_user_data;
87
		}
88
89
		\Jetpack::load_xml_rpc_client();
90
		$xml = new \Jetpack_IXR_Client(
91
			array(
92
				'user_id' => $user_id,
93
			)
94
		);
95
		$xml->query( 'wpcom.getUser' );
96
		if ( ! $xml->isError() ) {
97
			$user_data = $xml->getResponse();
98
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
99
			return $user_data;
100
		}
101
102
		return false;
103
	}
104
105
	/**
106
	 * Is the user the connection owner.

class.jetpack.php 1 location

@@ 1766-1790 (lines=25) @@
1763
	/**
1764
	 * Get the wpcom user data of the current|specified connected user.
1765
	 */
1766
	public static function get_connected_user_data( $user_id = null ) {
1767
		// TODO: remove in favor of Connection_Manager->get_connected_user_data
1768
		if ( ! $user_id ) {
1769
			$user_id = get_current_user_id();
1770
		}
1771
1772
		$transient_key = "jetpack_connected_user_data_$user_id";
1773
1774
		if ( $cached_user_data = get_transient( $transient_key ) ) {
1775
			return $cached_user_data;
1776
		}
1777
1778
		Jetpack::load_xml_rpc_client();
1779
		$xml = new Jetpack_IXR_Client( array(
1780
			'user_id' => $user_id,
1781
		) );
1782
		$xml->query( 'wpcom.getUser' );
1783
		if ( ! $xml->isError() ) {
1784
			$user_data = $xml->getResponse();
1785
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
1786
			return $user_data;
1787
		}
1788
1789
		return false;
1790
	}
1791
1792
	/**
1793
	 * Get the wpcom email of the current|specified connected user.