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

@@ 462-468 (lines=7) @@
459
				throw new WC_CLI_Exception( 'woocommerce_cli_cannot_update_coupon', __( 'Failed to update coupon', 'woocommerce' ) );
460
			}
461
462
			if ( isset( $data['type'] ) ) {
463
				// Validate coupon types.
464
				if ( ! in_array( wc_clean( $data['type'] ), array_keys( wc_get_coupon_types() ) ) ) {
465
					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() ) ) ) );
466
				}
467
				update_post_meta( $id, 'discount_type', $data['type'] );
468
			}
469
470
			if ( isset( $data['amount'] ) ) {
471
				update_post_meta( $id, 'coupon_amount', wc_format_decimal( $data['amount'] ) );