Code Duplication    Length = 7-7 lines in 2 locations

includes/api/class-wc-api-coupons.php 1 location

@@ 376-382 (lines=7) @@
373
				}
374
			}
375
376
			if ( isset( $data['type'] ) ) {
377
				// Validate coupon types
378
				if ( ! in_array( wc_clean( $data['type'] ), array_keys( wc_get_coupon_types() ) ) ) {
379
					throw new WC_API_Exception( 'woocommerce_api_invalid_coupon_type', sprintf( __( 'Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce' ), implode( ', ', array_keys( wc_get_coupon_types() ) ) ), 400 );
380
				}
381
				update_post_meta( $id, 'discount_type', $data['type'] );
382
			}
383
384
			if ( isset( $data['amount'] ) ) {
385
				update_post_meta( $id, 'coupon_amount', wc_format_decimal( $data['amount'] ) );

includes/cli/class-wc-cli-coupon.php 1 location

@@ 466-472 (lines=7) @@
463
				throw new WC_CLI_Exception( 'woocommerce_cli_cannot_update_coupon', __( 'Failed to update coupon', 'woocommerce' ) );
464
			}
465
466
			if ( isset( $data['type'] ) ) {
467
				// Validate coupon types.
468
				if ( ! in_array( wc_clean( $data['type'] ), array_keys( wc_get_coupon_types() ) ) ) {
469
					throw new WC_CLI_Exception( 'woocommerce_cli_invalid_coupon_type', sprintf( __( 'Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce' ), implode( ', ', array_keys( wc_get_coupon_types() ) ) ) );
470
				}
471
				update_post_meta( $id, 'discount_type', $data['type'] );
472
			}
473
474
			if ( isset( $data['amount'] ) ) {
475
				update_post_meta( $id, 'coupon_amount', wc_format_decimal( $data['amount'] ) );