Code Duplication    Length = 8-9 lines in 4 locations

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

@@ 187-195 (lines=9) @@
184
		$post->post_type = $this->post_type;
185
		$post_id         = wp_insert_post( $post, true );
186
187
		if ( is_wp_error( $post_id ) ) {
188
189
			if ( in_array( $post_id->get_error_code(), array( 'db_insert_error' ) ) ) {
190
				$post_id->add_data( array( 'status' => 500 ) );
191
			} else {
192
				$post_id->add_data( array( 'status' => 400 ) );
193
			}
194
			return $post_id;
195
		}
196
		$post->ID = $post_id;
197
		$post     = get_post( $post_id );
198
@@ 268-275 (lines=8) @@
265
		}
266
		// Convert the post object to an array, otherwise wp_update_post will expect non-escaped input.
267
		$post_id = wp_update_post( (array) $post, true );
268
		if ( is_wp_error( $post_id ) ) {
269
			if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) {
270
				$post_id->add_data( array( 'status' => 500 ) );
271
			} else {
272
				$post_id->add_data( array( 'status' => 400 ) );
273
			}
274
			return $post_id;
275
		}
276
277
		$post = get_post( $post_id );
278
		$this->update_additional_fields_for_object( $post, $request );

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

@@ 152-160 (lines=9) @@
149
		$post->post_type = $this->post_type;
150
		$post_id = wp_insert_post( $post, true );
151
152
		if ( is_wp_error( $post_id ) ) {
153
154
			if ( in_array( $post_id->get_error_code(), array( 'db_insert_error' ) ) ) {
155
				$post_id->add_data( array( 'status' => 500 ) );
156
			} else {
157
				$post_id->add_data( array( 'status' => 400 ) );
158
			}
159
			return $post_id;
160
		}
161
		$post->ID = $post_id;
162
163
		$webhook = new WC_Webhook( $post_id );
@@ 257-264 (lines=8) @@
254
255
		// Convert the post object to an array, otherwise wp_update_post will expect non-escaped input.
256
		$post_id = wp_update_post( (array) $post, true );
257
		if ( is_wp_error( $post_id ) ) {
258
			if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) {
259
				$post_id->add_data( array( 'status' => 500 ) );
260
			} else {
261
				$post_id->add_data( array( 'status' => 400 ) );
262
			}
263
			return $post_id;
264
		}
265
266
		$post = get_post( $post_id );
267
		$this->update_additional_fields_for_object( $post, $request );