Code Duplication    Length = 3-7 lines in 4 locations

_inc/lib/core-api/class.jetpack-core-api-site-endpoints.php 2 locations

@@ 22-28 (lines=7) @@
19
		$response = Jetpack_Client::wpcom_json_api_request_as_blog( $request, '1.1' );
20
21
		// Bail if there was an error or malformed response
22
		if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) {
23
			return new WP_Error(
24
				'failed_to_fetch_data',
25
				esc_html__( 'Unable to fetch the requested data.', 'jetpack' ),
26
				array( 'status' => 500 )
27
			);
28
		}
29
30
		// Decode the results
31
		$results = json_decode( $response['body'], true );
@@ 84-90 (lines=7) @@
81
		$response = Jetpack_Client::wpcom_json_api_request_as_blog( $request, '1.1', $request_args );
82
83
		// Bail if there was an error or malformed response
84
		if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) {
85
			return new WP_Error(
86
				'failed_to_fetch_data',
87
				esc_html__( 'Unable to fetch the requested data.', 'jetpack' ),
88
				array( 'status' => 400 )
89
			);
90
		}
91
92
		// Decode the results
93
		$results = json_decode( wp_remote_retrieve_body( $response ), true );

_inc/lib/class.core-rest-api-endpoints.php 2 locations

@@ 2487-2489 (lines=3) @@
2484
	 * @return bool|WP_Error
2485
	 */
2486
	public static function validate_services( $value, $request, $param ) {
2487
		if ( ! is_array( $value ) || ! isset( $value['visible'] ) || ! isset( $value['hidden'] ) ) {
2488
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array with visible and hidden items.', 'jetpack' ), $param ) );
2489
		}
2490
2491
		// Allow to clear everything.
2492
		if ( empty( $value['visible'] ) && empty( $value['hidden'] ) ) {
@@ 2527-2529 (lines=3) @@
2524
	 * @return bool|WP_Error
2525
	 */
2526
	public static function validate_custom_service( $value, $request, $param ) {
2527
		if ( ! is_array( $value ) || ! isset( $value['sharing_name'] ) || ! isset( $value['sharing_url'] ) || ! isset( $value['sharing_icon'] ) ) {
2528
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array with sharing name, url and icon.', 'jetpack' ), $param ) );
2529
		}
2530
2531
		// Allow to clear everything.
2532
		if ( empty( $value['sharing_name'] ) && empty( $value['sharing_url'] ) && empty( $value['sharing_icon'] ) ) {