Code Duplication    Length = 8-9 lines in 4 locations

includes/abstracts/abstract-wc-rest-posts-controller.php 2 locations

@@ 164-172 (lines=9) @@
161
		$post->post_type = $this->post_type;
162
		$post_id         = wp_insert_post( $post, true );
163
164
		if ( is_wp_error( $post_id ) ) {
165
166
			if ( in_array( $post_id->get_error_code(), array( 'db_insert_error' ) ) ) {
167
				$post_id->add_data( array( 'status' => 500 ) );
168
			} else {
169
				$post_id->add_data( array( 'status' => 400 ) );
170
			}
171
			return $post_id;
172
		}
173
		$post->ID = $post_id;
174
		$schema   = $this->get_item_schema();
175
		$post     = get_post( $post_id );
@@ 246-253 (lines=8) @@
243
		}
244
		// Convert the post object to an array, otherwise wp_update_post will expect non-escaped input.
245
		$post_id = wp_update_post( (array) $post, true );
246
		if ( is_wp_error( $post_id ) ) {
247
			if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) {
248
				$post_id->add_data( array( 'status' => 500 ) );
249
			} else {
250
				$post_id->add_data( array( 'status' => 400 ) );
251
			}
252
			return $post_id;
253
		}
254
255
		$schema = $this->get_item_schema();
256

includes/api/class-wc-rest-webhooks-controller.php 2 locations

@@ 142-150 (lines=9) @@
139
		$post->post_type = $this->post_type;
140
		$post_id = wp_insert_post( $post, true );
141
142
		if ( is_wp_error( $post_id ) ) {
143
144
			if ( in_array( $post_id->get_error_code(), array( 'db_insert_error' ) ) ) {
145
				$post_id->add_data( array( 'status' => 500 ) );
146
			} else {
147
				$post_id->add_data( array( 'status' => 400 ) );
148
			}
149
			return $post_id;
150
		}
151
		$post->ID = $post_id;
152
153
		$webhook = new WC_Webhook( $post_id );
@@ 247-254 (lines=8) @@
244
245
		// Convert the post object to an array, otherwise wp_update_post will expect non-escaped input.
246
		$post_id = wp_update_post( (array) $post, true );
247
		if ( is_wp_error( $post_id ) ) {
248
			if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) {
249
				$post_id->add_data( array( 'status' => 500 ) );
250
			} else {
251
				$post_id->add_data( array( 'status' => 400 ) );
252
			}
253
			return $post_id;
254
		}
255
256
		$post = get_post( $post_id );
257
		$this->update_additional_fields_for_object( $post, $request );