Code Duplication    Length = 3-10 lines in 4 locations

_inc/lib/core-api/class.jetpack-core-api-site-endpoints.php 1 location

@@ 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 );

_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php 1 location

@@ 225-234 (lines=10) @@
222
	 */
223
	public static function activate_modules( $request ) {
224
225
		if (
226
			! isset( $request['modules'] )
227
			|| ! is_array( $request['modules'] )
228
		) {
229
			return new WP_Error(
230
				'not_found',
231
				esc_html__( 'The requested Jetpack module was not found.', 'jetpack' ),
232
				array( 'status' => 404 )
233
			);
234
		}
235
236
		$activated = array();
237
		$failed = array();

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

@@ 2344-2346 (lines=3) @@
2341
	 * @return bool|WP_Error
2342
	 */
2343
	public static function validate_services( $value, $request, $param ) {
2344
		if ( ! is_array( $value ) || ! isset( $value['visible'] ) || ! isset( $value['hidden'] ) ) {
2345
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array with visible and hidden items.', 'jetpack' ), $param ) );
2346
		}
2347
2348
		// Allow to clear everything.
2349
		if ( empty( $value['visible'] ) && empty( $value['hidden'] ) ) {
@@ 2384-2386 (lines=3) @@
2381
	 * @return bool|WP_Error
2382
	 */
2383
	public static function validate_custom_service( $value, $request, $param ) {
2384
		if ( ! is_array( $value ) || ! isset( $value['sharing_name'] ) || ! isset( $value['sharing_url'] ) || ! isset( $value['sharing_icon'] ) ) {
2385
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array with sharing name, url and icon.', 'jetpack' ), $param ) );
2386
		}
2387
2388
		// Allow to clear everything.
2389
		if ( empty( $value['sharing_name'] ) && empty( $value['sharing_url'] ) && empty( $value['sharing_icon'] ) ) {