Code Duplication    Length = 3-3 lines in 6 locations

src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php 2 locations

@@ 451-453 (lines=3) @@
448
			);
449
		}
450
451
		if ( empty( $request['post'] ) ) {
452
			return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) );
453
		}
454
455
		$post = get_post( (int) $request['post'] );
456
		if ( ! $post ) {
@@ 489-491 (lines=3) @@
486
	 * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
487
	 */
488
	public function create_item( $request ) {
489
		if ( ! empty( $request['id'] ) ) {
490
			return new WP_Error( 'rest_comment_exists', __( 'Cannot create existing comment.' ), array( 'status' => 400 ) );
491
		}
492
493
		// Do not allow comments to be created with a non-default type.
494
		if ( ! empty( $request['type'] ) && 'comment' !== $request['type'] ) {

src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2 locations

@@ 494-496 (lines=3) @@
491
	 * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
492
	 */
493
	public function create_item_permissions_check( $request ) {
494
		if ( ! empty( $request['id'] ) ) {
495
			return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) );
496
		}
497
498
		$post_type = get_post_type_object( $this->post_type );
499
@@ 529-531 (lines=3) @@
526
	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
527
	 */
528
	public function create_item( $request ) {
529
		if ( ! empty( $request['id'] ) ) {
530
			return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) );
531
		}
532
533
		$prepared_post = $this->prepare_item_for_database( $request );
534

src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php 2 locations

@@ 459-461 (lines=3) @@
456
	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
457
	 */
458
	public function create_item( $request ) {
459
		if ( ! empty( $request['id'] ) ) {
460
			return new WP_Error( 'rest_user_exists', __( 'Cannot create existing user.' ), array( 'status' => 400 ) );
461
		}
462
463
		$schema = $this->get_item_schema();
464
@@ 1069-1071 (lines=3) @@
1066
			// The new role must be editable by the logged-in user.
1067
			$editable_roles = get_editable_roles();
1068
1069
			if ( empty( $editable_roles[ $role ] ) ) {
1070
				return new WP_Error( 'rest_user_invalid_role', __( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => 403 ) );
1071
			}
1072
		}
1073
1074
		return true;