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/class.core-rest-api-endpoints.php 2 locations

@@ 2195-2197 (lines=3) @@
2192
	 * @return bool|WP_Error
2193
	 */
2194
	public static function validate_services( $value, $request, $param ) {
2195
		if ( ! is_array( $value ) || ! isset( $value['visible'] ) || ! isset( $value['hidden'] ) ) {
2196
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array with visible and hidden items.', 'jetpack' ), $param ) );
2197
		}
2198
2199
		// Allow to clear everything.
2200
		if ( empty( $value['visible'] ) && empty( $value['hidden'] ) ) {
@@ 2235-2237 (lines=3) @@
2232
	 * @return bool|WP_Error
2233
	 */
2234
	public static function validate_custom_service( $value, $request, $param ) {
2235
		if ( ! is_array( $value ) || ! isset( $value['sharing_name'] ) || ! isset( $value['sharing_url'] ) || ! isset( $value['sharing_icon'] ) ) {
2236
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array with sharing name, url and icon.', 'jetpack' ), $param ) );
2237
		}
2238
2239
		// Allow to clear everything.
2240
		if ( empty( $value['sharing_name'] ) && empty( $value['sharing_url'] ) && empty( $value['sharing_icon'] ) ) {

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

@@ 217-226 (lines=10) @@
214
	 */
215
	public static function activate_modules( $request ) {
216
217
		if (
218
			! isset( $request['modules'] )
219
			|| ! is_array( $request['modules'] )
220
		) {
221
			return new WP_Error(
222
				'not_found',
223
				esc_html__( 'The requested Jetpack module was not found.', 'jetpack' ),
224
				array( 'status' => 404 )
225
			);
226
		}
227
228
		$activated = array();
229
		$failed = array();