Code Duplication    Length = 13-13 lines in 2 locations

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

@@ 336-348 (lines=13) @@
333
			$args['slug'] = $request['slug'];
334
		}
335
336
		if ( isset( $request['parent'] ) ) {
337
			if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
338
				return new WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) );
339
			}
340
341
			$parent = get_term( (int) $request['parent'], $taxonomy );
342
343
			if ( ! $parent ) {
344
				return new WP_Error( 'woocommerce_rest_term_invalid', __( "Parent resource doesn't exist.", 'woocommerce' ), array( 'status' => 404 ) );
345
			}
346
347
			$args['parent'] = $parent->term_id;
348
		}
349
350
		$term = wp_insert_term( $name, $taxonomy, $args );
351
		if ( is_wp_error( $term ) ) {
@@ 438-450 (lines=13) @@
435
			$prepared_args['slug'] = $request['slug'];
436
		}
437
438
		if ( isset( $request['parent'] ) ) {
439
			if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
440
				return new WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) );
441
			}
442
443
			$parent = get_term( (int) $request['parent'], $taxonomy );
444
445
			if ( ! $parent ) {
446
				return new WP_Error( 'woocommerce_rest_term_invalid', __( "Parent resource doesn't exist.", 'woocommerce' ), array( 'status' => 400 ) );
447
			}
448
449
			$prepared_args['parent'] = $parent->term_id;
450
		}
451
452
		// Only update the term if we haz something to update.
453
		if ( ! empty( $prepared_args ) ) {