Code Duplication    Length = 37-37 lines in 2 locations

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

@@ 1079-1115 (lines=37) @@
1076
			throw new WC_CLI_Exception( 'woocommerce_invalid_shipping_total', __( 'Shipping total must be a positive amount', 'woocommerce' ) );
1077
		}
1078
1079
		if ( 'create' === $action ) {
1080
1081
			// method ID is required
1082
			if ( ! isset( $shipping['method_id'] ) ) {
1083
				throw new WC_CLI_Exception( 'woocommerce_invalid_shipping_item', __( 'Shipping method ID is required', 'woocommerce' ) );
1084
			}
1085
1086
			$rate = new WC_Shipping_Rate( $shipping['method_id'], isset( $shipping['method_title'] ) ? $shipping['method_title'] : '', isset( $shipping['total'] ) ? floatval( $shipping['total'] ) : 0, array(), $shipping['method_id'] );
1087
1088
			$shipping_id = $order->add_shipping( $rate );
1089
1090
			if ( ! $shipping_id ) {
1091
				throw new WC_CLI_Exception( 'woocommerce_cannot_create_shipping', __( 'Cannot create shipping method, try again', 'woocommerce' ) );
1092
			}
1093
1094
		} else {
1095
1096
			$shipping_args = array();
1097
1098
			if ( isset( $shipping['method_id'] ) ) {
1099
				$shipping_args['method_id'] = $shipping['method_id'];
1100
			}
1101
1102
			if ( isset( $shipping['method_title'] ) ) {
1103
				$shipping_args['method_title'] = $shipping['method_title'];
1104
			}
1105
1106
			if ( isset( $shipping['total'] ) ) {
1107
				$shipping_args['cost'] = floatval( $shipping['total'] );
1108
			}
1109
1110
			$shipping_id = $order->update_shipping( $shipping['id'], $shipping_args );
1111
1112
			if ( ! $shipping_id ) {
1113
				throw new WC_CLI_Exception( 'woocommerce_cannot_update_shipping', __( 'Cannot update shipping method, try again', 'woocommerce' ) );
1114
			}
1115
		}
1116
	}
1117
1118
	/**

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

@@ 1067-1103 (lines=37) @@
1064
			throw new WC_API_Exception( 'woocommerce_invalid_shipping_total', __( 'Shipping total must be a positive amount', 'woocommerce' ), 400 );
1065
		}
1066
1067
		if ( 'create' === $action ) {
1068
1069
			// method ID is required
1070
			if ( ! isset( $shipping['method_id'] ) ) {
1071
				throw new WC_API_Exception( 'woocommerce_invalid_shipping_item', __( 'Shipping method ID is required', 'woocommerce' ), 400 );
1072
			}
1073
1074
			$rate = new WC_Shipping_Rate( $shipping['method_id'], isset( $shipping['method_title'] ) ? $shipping['method_title'] : '', isset( $shipping['total'] ) ? floatval( $shipping['total'] ) : 0, array(), $shipping['method_id'] );
1075
1076
			$shipping_id = $order->add_shipping( $rate );
1077
1078
			if ( ! $shipping_id ) {
1079
				throw new WC_API_Exception( 'woocommerce_cannot_create_shipping', __( 'Cannot create shipping method, try again', 'woocommerce' ), 500 );
1080
			}
1081
1082
		} else {
1083
1084
			$shipping_args = array();
1085
1086
			if ( isset( $shipping['method_id'] ) ) {
1087
				$shipping_args['method_id'] = $shipping['method_id'];
1088
			}
1089
1090
			if ( isset( $shipping['method_title'] ) ) {
1091
				$shipping_args['method_title'] = $shipping['method_title'];
1092
			}
1093
1094
			if ( isset( $shipping['total'] ) ) {
1095
				$shipping_args['cost'] = floatval( $shipping['total'] );
1096
			}
1097
1098
			$shipping_id = $order->update_shipping( $shipping['id'], $shipping_args );
1099
1100
			if ( ! $shipping_id ) {
1101
				throw new WC_API_Exception( 'woocommerce_cannot_update_shipping', __( 'Cannot update shipping method, try again', 'woocommerce' ), 500 );
1102
			}
1103
		}
1104
	}
1105
1106
	/**