Code Duplication    Length = 3-3 lines in 4 locations

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

@@ 1967-1969 (lines=3) @@
1964
1965
			// If it's an associative array, use the keys to check that the value is among those admitted.
1966
			$enum = ( count( array_filter( array_keys( $args['enum'] ), 'is_string' ) ) > 0 ) ? array_keys( $args['enum'] ) : $args['enum'];
1967
			if ( ! in_array( $value, $enum ) ) {
1968
				return new WP_Error( 'invalid_param_value', sprintf(
1969
					/* Translators: first variable is the parameter passed to endpoint that holds the list item, the second is a list of admitted values. */
1970
					esc_html__( '%1$s must be one of %2$s', 'jetpack' ), $param, implode( ', ', $enum )
1971
				) );
1972
			}
@@ 2072-2074 (lines=3) @@
2069
	 */
2070
	public static function validate_sharing_show( $value, $request, $param ) {
2071
		$views = array( 'index', 'post', 'page', 'attachment', 'jetpack-portfolio' );
2072
		if ( ! is_array( $value ) ) {
2073
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array of post types.', 'jetpack' ), $param ) );
2074
		}
2075
		if ( ! array_intersect( $views, $value ) ) {
2076
			return new WP_Error( 'invalid_param', sprintf(
2077
				/* 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 */
@@ 2075-2077 (lines=3) @@
2072
		if ( ! is_array( $value ) ) {
2073
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array of post types.', 'jetpack' ), $param ) );
2074
		}
2075
		if ( ! array_intersect( $views, $value ) ) {
2076
			return new WP_Error( 'invalid_param', sprintf(
2077
				/* 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 */
2078
				esc_html__( '%1$s must be %2$s.', 'jetpack' ), $param, join( ', ', $views )
2079
			) );
2080
		}
@@ 2184-2186 (lines=3) @@
2181
		$sharer = new Sharing_Service();
2182
		$services = array_keys( $sharer->get_all_services() );
2183
2184
		if ( ! empty( $value ) && ! in_array( $value, $services ) ) {
2185
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s is not a registered custom sharing service.', 'jetpack' ), $param ) );
2186
		}
2187
2188
		return true;
2189
	}