Code Duplication    Length = 3-6 lines in 6 locations

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

@@ 717-720 (lines=4) @@
714
	 * @return bool|WP_Error
715
	 */
716
	public static function validate_setup_wizard_questionnaire( $value, $request, $param ) {
717
		if ( ! is_array( $value ) ) {
718
			/* translators: Name of a parameter that must be an object */
719
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an object.', 'jetpack' ), $param ) );
720
		}
721
722
		foreach ( $value as $answer_key => $answer ) {
723
			if ( is_string( $answer ) ) {
@@ 2804-2806 (lines=3) @@
2801
	 * @return bool|WP_Error
2802
	 */
2803
	public static function validate_posint( $value, $request, $param ) {
2804
		if ( ! is_numeric( $value ) || $value <= 0 ) {
2805
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be a positive integer.', 'jetpack' ), $param ) );
2806
		}
2807
		return true;
2808
	}
2809
@@ 2853-2855 (lines=3) @@
2850
	 * @return bool|WP_Error
2851
	 */
2852
	public static function validate_module_list( $value, $request, $param ) {
2853
		if ( ! is_array( $value ) ) {
2854
			return new WP_Error( 'invalid_param_value', sprintf( esc_html__( '%s must be an array', 'jetpack' ), $param ) );
2855
		}
2856
2857
		$modules = Jetpack::get_available_modules();
2858
@@ 2936-2939 (lines=4) @@
2933
	 */
2934
	public static function validate_sharing_show( $value, $request, $param ) {
2935
		$views = array( 'index', 'post', 'page', 'attachment', 'jetpack-portfolio' );
2936
		if ( ! is_array( $value ) ) {
2937
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array of post types.', 'jetpack' ), $param ) );
2938
		}
2939
		if ( ! array_intersect( $views, $value ) ) {
2940
			return new WP_Error( 'invalid_param', sprintf(
2941
				/* 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 */
2942
				esc_html__( '%1$s must be %2$s.', 'jetpack' ), $param, join( ', ', $views )
@@ 2939-2944 (lines=6) @@
2936
		if ( ! is_array( $value ) ) {
2937
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an array of post types.', 'jetpack' ), $param ) );
2938
		}
2939
		if ( ! array_intersect( $views, $value ) ) {
2940
			return new WP_Error( 'invalid_param', sprintf(
2941
				/* 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 */
2942
				esc_html__( '%1$s must be %2$s.', 'jetpack' ), $param, join( ', ', $views )
2943
			) );
2944
		}
2945
		return true;
2946
	}
2947
@@ 3085-3087 (lines=3) @@
3082
	 * @return bool|WP_Error
3083
	 */
3084
	public static function validate_string( $value, $request, $param ) {
3085
		if ( ! is_string( $value ) ) {
3086
			return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be a string.', 'jetpack' ), $param ) );
3087
		}
3088
		return true;
3089
	}
3090