Code Duplication    Length = 3-3 lines in 4 locations

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

@@ 2056-2058 (lines=3) @@
2053
2054
			// If it's an associative array, use the keys to check that the value is among those admitted.
2055
			$enum = ( count( array_filter( array_keys( $args['enum'] ), 'is_string' ) ) > 0 ) ? array_keys( $args['enum'] ) : $args['enum'];
2056
			if ( ! in_array( $value, $enum ) ) {
2057
				return new WP_Error( 'invalid_param_value', sprintf(
2058
					/* Translators: first variable is the parameter passed to endpoint that holds the list item, the second is a list of admitted values. */
2059
					esc_html__( '%1$s must be one of %2$s', 'jetpack' ), $param, implode( ', ', $enum )
2060
				) );
2061
			}
@@ 2161-2163 (lines=3) @@
2158
	 */
2159
	public static function validate_sharing_show( $value, $request, $param ) {
2160
		$views = array( 'index', 'post', 'page', 'attachment', 'jetpack-portfolio' );
2161
		if ( ! is_array( $value ) ) {
2162
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array of post types.', 'jetpack' ), $param ) );
2163
		}
2164
		if ( ! array_intersect( $views, $value ) ) {
2165
			return new WP_Error( 'invalid_param', sprintf(
2166
				/* Translators: first variable is the name of a parameter passed to endpoint holding the post type where Sharing will be displayed, the second is a list of post types where Sharing can be displayed */
@@ 2164-2166 (lines=3) @@
2161
		if ( ! is_array( $value ) ) {
2162
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array of post types.', 'jetpack' ), $param ) );
2163
		}
2164
		if ( ! array_intersect( $views, $value ) ) {
2165
			return new WP_Error( 'invalid_param', sprintf(
2166
				/* Translators: first variable is the name of a parameter passed to endpoint holding the post type where Sharing will be displayed, the second is a list of post types where Sharing can be displayed */
2167
				esc_html__( '%1$s must be %2$s.', 'jetpack' ), $param, join( ', ', $views )
2168
			) );
2169
		}
@@ 2273-2275 (lines=3) @@
2270
		$sharer = new Sharing_Service();
2271
		$services = array_keys( $sharer->get_all_services() );
2272
2273
		if ( ! empty( $value ) && ! in_array( $value, $services ) ) {
2274
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s is not a registered custom sharing service.', 'jetpack' ), $param ) );
2275
		}
2276
2277
		return true;
2278
	}