Completed
Push — master ( a986bf...ee9494 )
by Mike
104:12 queued 59:10
created
src/Controllers/Version3/class-wc-rest-coupons-controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Coupons controller class.
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-product-categories-controller.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Product Categories controller class.
@@ -32,12 +32,12 @@  discard block
 block discarded – undo
32 32
 	 * @param WP_REST_Request $request Request instance.
33 33
 	 * @return WP_REST_Response
34 34
 	 */
35
-	public function prepare_item_for_response( $item, $request ) {
35
+	public function prepare_item_for_response($item, $request) {
36 36
 		// Get category display type.
37
-		$display_type = get_term_meta( $item->term_id, 'display_type', true );
37
+		$display_type = get_term_meta($item->term_id, 'display_type', true);
38 38
 
39 39
 		// Get category order.
40
-		$menu_order = get_term_meta( $item->term_id, 'order', true );
40
+		$menu_order = get_term_meta($item->term_id, 'order', true);
41 41
 
42 42
 		$data = array(
43 43
 			'id'          => (int) $item->term_id,
@@ -52,29 +52,29 @@  discard block
 block discarded – undo
52 52
 		);
53 53
 
54 54
 		// Get category image.
55
-		$image_id = get_term_meta( $item->term_id, 'thumbnail_id', true );
56
-		if ( $image_id ) {
57
-			$attachment = get_post( $image_id );
55
+		$image_id = get_term_meta($item->term_id, 'thumbnail_id', true);
56
+		if ($image_id) {
57
+			$attachment = get_post($image_id);
58 58
 
59 59
 			$data['image'] = array(
60 60
 				'id'                => (int) $image_id,
61
-				'date_created'      => wc_rest_prepare_date_response( $attachment->post_date ),
62
-				'date_created_gmt'  => wc_rest_prepare_date_response( $attachment->post_date_gmt ),
63
-				'date_modified'     => wc_rest_prepare_date_response( $attachment->post_modified ),
64
-				'date_modified_gmt' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ),
65
-				'src'               => wp_get_attachment_url( $image_id ),
66
-				'name'              => get_the_title( $attachment ),
67
-				'alt'               => get_post_meta( $image_id, '_wp_attachment_image_alt', true ),
61
+				'date_created'      => wc_rest_prepare_date_response($attachment->post_date),
62
+				'date_created_gmt'  => wc_rest_prepare_date_response($attachment->post_date_gmt),
63
+				'date_modified'     => wc_rest_prepare_date_response($attachment->post_modified),
64
+				'date_modified_gmt' => wc_rest_prepare_date_response($attachment->post_modified_gmt),
65
+				'src'               => wp_get_attachment_url($image_id),
66
+				'name'              => get_the_title($attachment),
67
+				'alt'               => get_post_meta($image_id, '_wp_attachment_image_alt', true),
68 68
 			);
69 69
 		}
70 70
 
71
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
72
-		$data    = $this->add_additional_fields_to_object( $data, $request );
73
-		$data    = $this->filter_response_by_context( $data, $context );
71
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
72
+		$data    = $this->add_additional_fields_to_object($data, $request);
73
+		$data    = $this->filter_response_by_context($data, $context);
74 74
 
75
-		$response = rest_ensure_response( $data );
75
+		$response = rest_ensure_response($data);
76 76
 
77
-		$response->add_links( $this->prepare_links( $item, $request ) );
77
+		$response->add_links($this->prepare_links($item, $request));
78 78
 
79 79
 		/**
80 80
 		 * Filter a term item returned from the API.
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 		 * @param object            $item      The original term object.
86 86
 		 * @param WP_REST_Request   $request   Request used to generate the response.
87 87
 		 */
88
-		return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request );
88
+		return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
89 89
 	}
90 90
 
91 91
 	/**
@@ -100,114 +100,114 @@  discard block
 block discarded – undo
100 100
 			'type'       => 'object',
101 101
 			'properties' => array(
102 102
 				'id'          => array(
103
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
103
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
104 104
 					'type'        => 'integer',
105
-					'context'     => array( 'view', 'edit' ),
105
+					'context'     => array('view', 'edit'),
106 106
 					'readonly'    => true,
107 107
 				),
108 108
 				'name'        => array(
109
-					'description' => __( 'Category name.', 'woocommerce' ),
109
+					'description' => __('Category name.', 'woocommerce'),
110 110
 					'type'        => 'string',
111
-					'context'     => array( 'view', 'edit' ),
111
+					'context'     => array('view', 'edit'),
112 112
 					'arg_options' => array(
113 113
 						'sanitize_callback' => 'sanitize_text_field',
114 114
 					),
115 115
 				),
116 116
 				'slug'        => array(
117
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
117
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
118 118
 					'type'        => 'string',
119
-					'context'     => array( 'view', 'edit' ),
119
+					'context'     => array('view', 'edit'),
120 120
 					'arg_options' => array(
121 121
 						'sanitize_callback' => 'sanitize_title',
122 122
 					),
123 123
 				),
124 124
 				'parent'      => array(
125
-					'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ),
125
+					'description' => __('The ID for the parent of the resource.', 'woocommerce'),
126 126
 					'type'        => 'integer',
127
-					'context'     => array( 'view', 'edit' ),
127
+					'context'     => array('view', 'edit'),
128 128
 				),
129 129
 				'description' => array(
130
-					'description' => __( 'HTML description of the resource.', 'woocommerce' ),
130
+					'description' => __('HTML description of the resource.', 'woocommerce'),
131 131
 					'type'        => 'string',
132
-					'context'     => array( 'view', 'edit' ),
132
+					'context'     => array('view', 'edit'),
133 133
 					'arg_options' => array(
134 134
 						'sanitize_callback' => 'wp_filter_post_kses',
135 135
 					),
136 136
 				),
137 137
 				'display'     => array(
138
-					'description' => __( 'Category archive display type.', 'woocommerce' ),
138
+					'description' => __('Category archive display type.', 'woocommerce'),
139 139
 					'type'        => 'string',
140 140
 					'default'     => 'default',
141
-					'enum'        => array( 'default', 'products', 'subcategories', 'both' ),
142
-					'context'     => array( 'view', 'edit' ),
141
+					'enum'        => array('default', 'products', 'subcategories', 'both'),
142
+					'context'     => array('view', 'edit'),
143 143
 				),
144 144
 				'image'       => array(
145
-					'description' => __( 'Image data.', 'woocommerce' ),
145
+					'description' => __('Image data.', 'woocommerce'),
146 146
 					'type'        => 'object',
147
-					'context'     => array( 'view', 'edit' ),
147
+					'context'     => array('view', 'edit'),
148 148
 					'properties'  => array(
149 149
 						'id'                => array(
150
-							'description' => __( 'Image ID.', 'woocommerce' ),
150
+							'description' => __('Image ID.', 'woocommerce'),
151 151
 							'type'        => 'integer',
152
-							'context'     => array( 'view', 'edit' ),
152
+							'context'     => array('view', 'edit'),
153 153
 						),
154 154
 						'date_created'      => array(
155
-							'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
155
+							'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'),
156 156
 							'type'        => 'date-time',
157
-							'context'     => array( 'view', 'edit' ),
157
+							'context'     => array('view', 'edit'),
158 158
 							'readonly'    => true,
159 159
 						),
160 160
 						'date_created_gmt'  => array(
161
-							'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
161
+							'description' => __('The date the image was created, as GMT.', 'woocommerce'),
162 162
 							'type'        => 'date-time',
163
-							'context'     => array( 'view', 'edit' ),
163
+							'context'     => array('view', 'edit'),
164 164
 							'readonly'    => true,
165 165
 						),
166 166
 						'date_modified'     => array(
167
-							'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
167
+							'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'),
168 168
 							'type'        => 'date-time',
169
-							'context'     => array( 'view', 'edit' ),
169
+							'context'     => array('view', 'edit'),
170 170
 							'readonly'    => true,
171 171
 						),
172 172
 						'date_modified_gmt' => array(
173
-							'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
173
+							'description' => __('The date the image was last modified, as GMT.', 'woocommerce'),
174 174
 							'type'        => 'date-time',
175
-							'context'     => array( 'view', 'edit' ),
175
+							'context'     => array('view', 'edit'),
176 176
 							'readonly'    => true,
177 177
 						),
178 178
 						'src'               => array(
179
-							'description' => __( 'Image URL.', 'woocommerce' ),
179
+							'description' => __('Image URL.', 'woocommerce'),
180 180
 							'type'        => 'string',
181 181
 							'format'      => 'uri',
182
-							'context'     => array( 'view', 'edit' ),
182
+							'context'     => array('view', 'edit'),
183 183
 						),
184 184
 						'name'              => array(
185
-							'description' => __( 'Image name.', 'woocommerce' ),
185
+							'description' => __('Image name.', 'woocommerce'),
186 186
 							'type'        => 'string',
187
-							'context'     => array( 'view', 'edit' ),
187
+							'context'     => array('view', 'edit'),
188 188
 						),
189 189
 						'alt'               => array(
190
-							'description' => __( 'Image alternative text.', 'woocommerce' ),
190
+							'description' => __('Image alternative text.', 'woocommerce'),
191 191
 							'type'        => 'string',
192
-							'context'     => array( 'view', 'edit' ),
192
+							'context'     => array('view', 'edit'),
193 193
 						),
194 194
 					),
195 195
 				),
196 196
 				'menu_order'  => array(
197
-					'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ),
197
+					'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'),
198 198
 					'type'        => 'integer',
199
-					'context'     => array( 'view', 'edit' ),
199
+					'context'     => array('view', 'edit'),
200 200
 				),
201 201
 				'count'       => array(
202
-					'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
202
+					'description' => __('Number of published products for the resource.', 'woocommerce'),
203 203
 					'type'        => 'integer',
204
-					'context'     => array( 'view', 'edit' ),
204
+					'context'     => array('view', 'edit'),
205 205
 					'readonly'    => true,
206 206
 				),
207 207
 			),
208 208
 		);
209 209
 
210
-		return $this->add_additional_fields_schema( $schema );
210
+		return $this->add_additional_fields_schema($schema);
211 211
 	}
212 212
 
213 213
 	/**
@@ -219,50 +219,50 @@  discard block
 block discarded – undo
219 219
 	 *
220 220
 	 * @since 3.5.5
221 221
 	 */
222
-	protected function update_term_meta_fields( $term, $request ) {
222
+	protected function update_term_meta_fields($term, $request) {
223 223
 		$id = (int) $term->term_id;
224 224
 
225
-		if ( isset( $request['display'] ) ) {
226
-			update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] );
225
+		if (isset($request['display'])) {
226
+			update_term_meta($id, 'display_type', 'default' === $request['display'] ? '' : $request['display']);
227 227
 		}
228 228
 
229
-		if ( isset( $request['menu_order'] ) ) {
230
-			update_term_meta( $id, 'order', $request['menu_order'] );
229
+		if (isset($request['menu_order'])) {
230
+			update_term_meta($id, 'order', $request['menu_order']);
231 231
 		}
232 232
 
233
-		if ( isset( $request['image'] ) ) {
234
-			if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) {
235
-				$upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) );
233
+		if (isset($request['image'])) {
234
+			if (empty($request['image']['id']) && ! empty($request['image']['src'])) {
235
+				$upload = wc_rest_upload_image_from_url(esc_url_raw($request['image']['src']));
236 236
 
237
-				if ( is_wp_error( $upload ) ) {
237
+				if (is_wp_error($upload)) {
238 238
 					return $upload;
239 239
 				}
240 240
 
241
-				$image_id = wc_rest_set_uploaded_image_as_attachment( $upload );
241
+				$image_id = wc_rest_set_uploaded_image_as_attachment($upload);
242 242
 			} else {
243
-				$image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0;
243
+				$image_id = isset($request['image']['id']) ? absint($request['image']['id']) : 0;
244 244
 			}
245 245
 
246 246
 			// Check if image_id is a valid image attachment before updating the term meta.
247
-			if ( $image_id && wp_attachment_is_image( $image_id ) ) {
248
-				update_term_meta( $id, 'thumbnail_id', $image_id );
247
+			if ($image_id && wp_attachment_is_image($image_id)) {
248
+				update_term_meta($id, 'thumbnail_id', $image_id);
249 249
 
250 250
 				// Set the image alt.
251
-				if ( ! empty( $request['image']['alt'] ) ) {
252
-					update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) );
251
+				if ( ! empty($request['image']['alt'])) {
252
+					update_post_meta($image_id, '_wp_attachment_image_alt', wc_clean($request['image']['alt']));
253 253
 				}
254 254
 
255 255
 				// Set the image title.
256
-				if ( ! empty( $request['image']['name'] ) ) {
256
+				if ( ! empty($request['image']['name'])) {
257 257
 					wp_update_post(
258 258
 						array(
259 259
 							'ID'         => $image_id,
260
-							'post_title' => wc_clean( $request['image']['name'] ),
260
+							'post_title' => wc_clean($request['image']['name']),
261 261
 						)
262 262
 					);
263 263
 				}
264 264
 			} else {
265
-				delete_term_meta( $id, 'thumbnail_id' );
265
+				delete_term_meta($id, 'thumbnail_id');
266 266
 			}
267 267
 		}
268 268
 
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-orders-controller.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since    2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Orders controller class.
@@ -33,27 +33,27 @@  discard block
 block discarded – undo
33 33
 	 * @param WC_Order        $order   Order data.
34 34
 	 * @return bool
35 35
 	 */
36
-	protected function calculate_coupons( $request, $order ) {
37
-		if ( ! isset( $request['coupon_lines'] ) || ! is_array( $request['coupon_lines'] ) ) {
36
+	protected function calculate_coupons($request, $order) {
37
+		if ( ! isset($request['coupon_lines']) || ! is_array($request['coupon_lines'])) {
38 38
 			return false;
39 39
 		}
40 40
 
41 41
 		// Remove all coupons first to ensure calculation is correct.
42
-		foreach ( $order->get_items( 'coupon' ) as $coupon ) {
43
-			$order->remove_coupon( $coupon->get_code() );
42
+		foreach ($order->get_items('coupon') as $coupon) {
43
+			$order->remove_coupon($coupon->get_code());
44 44
 		}
45 45
 
46
-		foreach ( $request['coupon_lines'] as $item ) {
47
-			if ( is_array( $item ) ) {
48
-				if ( empty( $item['id'] ) ) {
49
-					if ( empty( $item['code'] ) ) {
50
-						throw new WC_REST_Exception( 'woocommerce_rest_invalid_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 );
46
+		foreach ($request['coupon_lines'] as $item) {
47
+			if (is_array($item)) {
48
+				if (empty($item['id'])) {
49
+					if (empty($item['code'])) {
50
+						throw new WC_REST_Exception('woocommerce_rest_invalid_coupon', __('Coupon code is required.', 'woocommerce'), 400);
51 51
 					}
52 52
 
53
-					$results = $order->apply_coupon( wc_clean( $item['code'] ) );
53
+					$results = $order->apply_coupon(wc_clean($item['code']));
54 54
 
55
-					if ( is_wp_error( $results ) ) {
56
-						throw new WC_REST_Exception( 'woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400 );
55
+					if (is_wp_error($results)) {
56
+						throw new WC_REST_Exception('woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400);
57 57
 					}
58 58
 				}
59 59
 			}
@@ -70,51 +70,51 @@  discard block
 block discarded – undo
70 70
 	 * @param  bool            $creating If is creating a new object.
71 71
 	 * @return WP_Error|WC_Data
72 72
 	 */
73
-	protected function prepare_object_for_database( $request, $creating = false ) {
74
-		$id        = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
75
-		$order     = new WC_Order( $id );
73
+	protected function prepare_object_for_database($request, $creating = false) {
74
+		$id        = isset($request['id']) ? absint($request['id']) : 0;
75
+		$order     = new WC_Order($id);
76 76
 		$schema    = $this->get_item_schema();
77
-		$data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
77
+		$data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props')));
78 78
 
79 79
 		// Handle all writable props.
80
-		foreach ( $data_keys as $key ) {
81
-			$value = $request[ $key ];
80
+		foreach ($data_keys as $key) {
81
+			$value = $request[$key];
82 82
 
83
-			if ( ! is_null( $value ) ) {
84
-				switch ( $key ) {
83
+			if ( ! is_null($value)) {
84
+				switch ($key) {
85 85
 					case 'coupon_lines':
86 86
 					case 'status':
87 87
 						// Change should be done later so transitions have new data.
88 88
 						break;
89 89
 					case 'billing':
90 90
 					case 'shipping':
91
-						$this->update_address( $order, $value, $key );
91
+						$this->update_address($order, $value, $key);
92 92
 						break;
93 93
 					case 'line_items':
94 94
 					case 'shipping_lines':
95 95
 					case 'fee_lines':
96
-						if ( is_array( $value ) ) {
97
-							foreach ( $value as $item ) {
98
-								if ( is_array( $item ) ) {
99
-									if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
100
-										$order->remove_item( $item['id'] );
96
+						if (is_array($value)) {
97
+							foreach ($value as $item) {
98
+								if (is_array($item)) {
99
+									if ($this->item_is_null($item) || (isset($item['quantity']) && 0 === $item['quantity'])) {
100
+										$order->remove_item($item['id']);
101 101
 									} else {
102
-										$this->set_item( $order, $key, $item );
102
+										$this->set_item($order, $key, $item);
103 103
 									}
104 104
 								}
105 105
 							}
106 106
 						}
107 107
 						break;
108 108
 					case 'meta_data':
109
-						if ( is_array( $value ) ) {
110
-							foreach ( $value as $meta ) {
111
-								$order->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
109
+						if (is_array($value)) {
110
+							foreach ($value as $meta) {
111
+								$order->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
112 112
 							}
113 113
 						}
114 114
 						break;
115 115
 					default:
116
-						if ( is_callable( array( $order, "set_{$key}" ) ) ) {
117
-							$order->{"set_{$key}"}( $value );
116
+						if (is_callable(array($order, "set_{$key}"))) {
117
+							$order->{"set_{$key}"}($value);
118 118
 						}
119 119
 						break;
120 120
 				}
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		 * @param WP_REST_Request $request  Request object.
132 132
 		 * @param bool            $creating If is creating a new object.
133 133
 		 */
134
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating );
134
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating);
135 135
 	}
136 136
 
137 137
 	/**
@@ -143,62 +143,62 @@  discard block
 block discarded – undo
143 143
 	 * @param  bool            $creating If is creating a new object.
144 144
 	 * @return WC_Data|WP_Error
145 145
 	 */
146
-	protected function save_object( $request, $creating = false ) {
146
+	protected function save_object($request, $creating = false) {
147 147
 		try {
148
-			$object = $this->prepare_object_for_database( $request, $creating );
148
+			$object = $this->prepare_object_for_database($request, $creating);
149 149
 
150
-			if ( is_wp_error( $object ) ) {
150
+			if (is_wp_error($object)) {
151 151
 				return $object;
152 152
 			}
153 153
 
154 154
 			// Make sure gateways are loaded so hooks from gateways fire on save/create.
155 155
 			WC()->payment_gateways();
156 156
 
157
-			if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] ) {
157
+			if ( ! is_null($request['customer_id']) && 0 !== $request['customer_id']) {
158 158
 				// Make sure customer exists.
159
-				if ( false === get_user_by( 'id', $request['customer_id'] ) ) {
160
-					throw new WC_REST_Exception( 'woocommerce_rest_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce' ), 400 );
159
+				if (false === get_user_by('id', $request['customer_id'])) {
160
+					throw new WC_REST_Exception('woocommerce_rest_invalid_customer_id', __('Customer ID is invalid.', 'woocommerce'), 400);
161 161
 				}
162 162
 
163 163
 				// Make sure customer is part of blog.
164
-				if ( is_multisite() && ! is_user_member_of_blog( $request['customer_id'] ) ) {
165
-					add_user_to_blog( get_current_blog_id(), $request['customer_id'], 'customer' );
164
+				if (is_multisite() && ! is_user_member_of_blog($request['customer_id'])) {
165
+					add_user_to_blog(get_current_blog_id(), $request['customer_id'], 'customer');
166 166
 				}
167 167
 			}
168 168
 
169
-			if ( $creating ) {
170
-				$object->set_created_via( 'rest-api' );
171
-				$object->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
169
+			if ($creating) {
170
+				$object->set_created_via('rest-api');
171
+				$object->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax'));
172 172
 				$object->calculate_totals();
173 173
 			} else {
174 174
 				// If items have changed, recalculate order totals.
175
-				if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) {
176
-					$object->calculate_totals( true );
175
+				if (isset($request['billing']) || isset($request['shipping']) || isset($request['line_items']) || isset($request['shipping_lines']) || isset($request['fee_lines']) || isset($request['coupon_lines'])) {
176
+					$object->calculate_totals(true);
177 177
 				}
178 178
 			}
179 179
 
180 180
 			// Set coupons.
181
-			$this->calculate_coupons( $request, $object );
181
+			$this->calculate_coupons($request, $object);
182 182
 
183 183
 			// Set status.
184
-			if ( ! empty( $request['status'] ) ) {
185
-				$object->set_status( $request['status'] );
184
+			if ( ! empty($request['status'])) {
185
+				$object->set_status($request['status']);
186 186
 			}
187 187
 
188 188
 			$object->save();
189 189
 
190 190
 			// Actions for after the order is saved.
191
-			if ( true === $request['set_paid'] ) {
192
-				if ( $creating || $object->needs_payment() ) {
193
-					$object->payment_complete( $request['transaction_id'] );
191
+			if (true === $request['set_paid']) {
192
+				if ($creating || $object->needs_payment()) {
193
+					$object->payment_complete($request['transaction_id']);
194 194
 				}
195 195
 			}
196 196
 
197
-			return $this->get_object( $object->get_id() );
198
-		} catch ( WC_Data_Exception $e ) {
199
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
200
-		} catch ( WC_REST_Exception $e ) {
201
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
197
+			return $this->get_object($object->get_id());
198
+		} catch (WC_Data_Exception $e) {
199
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
200
+		} catch (WC_REST_Exception $e) {
201
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
202 202
 		}
203 203
 	}
204 204
 
@@ -209,17 +209,17 @@  discard block
 block discarded – undo
209 209
 	 * @param  WP_REST_Request $request Full details about the request.
210 210
 	 * @return array
211 211
 	 */
212
-	protected function prepare_objects_query( $request ) {
212
+	protected function prepare_objects_query($request) {
213 213
 		// This is needed to get around an array to string notice in WC_REST_Orders_V2_Controller::prepare_objects_query.
214 214
 		$statuses = $request['status'];
215
-		unset( $request['status'] );
216
-		$args = parent::prepare_objects_query( $request );
215
+		unset($request['status']);
216
+		$args = parent::prepare_objects_query($request);
217 217
 
218 218
 		$args['post_status'] = array();
219
-		foreach ( $statuses as $status ) {
220
-			if ( in_array( $status, $this->get_order_statuses(), true ) ) {
219
+		foreach ($statuses as $status) {
220
+			if (in_array($status, $this->get_order_statuses(), true)) {
221 221
 				$args['post_status'][] = 'wc-' . $status;
222
-			} elseif ( 'any' === $status ) {
222
+			} elseif ('any' === $status) {
223 223
 				// Set status to "any" and short-circuit out.
224 224
 				$args['post_status'] = 'any';
225 225
 				break;
@@ -257,11 +257,11 @@  discard block
 block discarded – undo
257 257
 
258 258
 		$params['status'] = array(
259 259
 			'default'           => 'any',
260
-			'description'       => __( 'Limit result set to orders which have specific statuses.', 'woocommerce' ),
260
+			'description'       => __('Limit result set to orders which have specific statuses.', 'woocommerce'),
261 261
 			'type'              => 'array',
262 262
 			'items'             => array(
263 263
 				'type' => 'string',
264
-				'enum' => array_merge( array( 'any', 'trash' ), $this->get_order_statuses() ),
264
+				'enum' => array_merge(array('any', 'trash'), $this->get_order_statuses()),
265 265
 			),
266 266
 			'validate_callback' => 'rest_validate_request_arg',
267 267
 		);
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-report-sales-controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Report Sales controller class.
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-reports-controller.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Reports controller class.
@@ -36,35 +36,35 @@  discard block
 block discarded – undo
36 36
 
37 37
 		$reports[] = array(
38 38
 			'slug'        => 'orders/totals',
39
-			'description' => __( 'Orders totals.', 'woocommerce' ),
39
+			'description' => __('Orders totals.', 'woocommerce'),
40 40
 		);
41 41
 		$reports[] = array(
42 42
 			'slug'        => 'products/totals',
43
-			'description' => __( 'Products totals.', 'woocommerce' ),
43
+			'description' => __('Products totals.', 'woocommerce'),
44 44
 		);
45 45
 		$reports[] = array(
46 46
 			'slug'        => 'customers/totals',
47
-			'description' => __( 'Customers totals.', 'woocommerce' ),
47
+			'description' => __('Customers totals.', 'woocommerce'),
48 48
 		);
49 49
 		$reports[] = array(
50 50
 			'slug'        => 'coupons/totals',
51
-			'description' => __( 'Coupons totals.', 'woocommerce' ),
51
+			'description' => __('Coupons totals.', 'woocommerce'),
52 52
 		);
53 53
 		$reports[] = array(
54 54
 			'slug'        => 'reviews/totals',
55
-			'description' => __( 'Reviews totals.', 'woocommerce' ),
55
+			'description' => __('Reviews totals.', 'woocommerce'),
56 56
 		);
57 57
 		$reports[] = array(
58 58
 			'slug'        => 'categories/totals',
59
-			'description' => __( 'Categories totals.', 'woocommerce' ),
59
+			'description' => __('Categories totals.', 'woocommerce'),
60 60
 		);
61 61
 		$reports[] = array(
62 62
 			'slug'        => 'tags/totals',
63
-			'description' => __( 'Tags totals.', 'woocommerce' ),
63
+			'description' => __('Tags totals.', 'woocommerce'),
64 64
 		);
65 65
 		$reports[] = array(
66 66
 			'slug'        => 'attributes/totals',
67
-			'description' => __( 'Attributes totals.', 'woocommerce' ),
67
+			'description' => __('Attributes totals.', 'woocommerce'),
68 68
 		);
69 69
 
70 70
 		return $reports;
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-data-currencies-controller.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   3.5.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Data Currencies controller class.
@@ -39,36 +39,36 @@  discard block
 block discarded – undo
39 39
 			$this->namespace, '/' . $this->rest_base, array(
40 40
 				array(
41 41
 					'methods'             => WP_REST_Server::READABLE,
42
-					'callback'            => array( $this, 'get_items' ),
43
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
42
+					'callback'            => array($this, 'get_items'),
43
+					'permission_callback' => array($this, 'get_items_permissions_check'),
44 44
 				),
45
-				'schema' => array( $this, 'get_public_item_schema' ),
45
+				'schema' => array($this, 'get_public_item_schema'),
46 46
 			)
47 47
 		);
48 48
 		register_rest_route(
49 49
 			$this->namespace, '/' . $this->rest_base . '/current', array(
50 50
 				array(
51 51
 					'methods'             => WP_REST_Server::READABLE,
52
-					'callback'            => array( $this, 'get_current_item' ),
53
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
52
+					'callback'            => array($this, 'get_current_item'),
53
+					'permission_callback' => array($this, 'get_item_permissions_check'),
54 54
 				),
55
-				'schema' => array( $this, 'get_public_item_schema' ),
55
+				'schema' => array($this, 'get_public_item_schema'),
56 56
 			)
57 57
 		);
58 58
 		register_rest_route(
59 59
 			$this->namespace, '/' . $this->rest_base . '/(?P<currency>[\w-]{3})', array(
60 60
 				array(
61 61
 					'methods'             => WP_REST_Server::READABLE,
62
-					'callback'            => array( $this, 'get_item' ),
63
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
62
+					'callback'            => array($this, 'get_item'),
63
+					'permission_callback' => array($this, 'get_item_permissions_check'),
64 64
 					'args'                => array(
65 65
 						'location' => array(
66
-							'description' => __( 'ISO4217 currency code.', 'woocommerce' ),
66
+							'description' => __('ISO4217 currency code.', 'woocommerce'),
67 67
 							'type'        => 'string',
68 68
 						),
69 69
 					),
70 70
 				),
71
-				'schema' => array( $this, 'get_public_item_schema' ),
71
+				'schema' => array($this, 'get_public_item_schema'),
72 72
 			)
73 73
 		);
74 74
 	}
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
 	 * @param  WP_REST_Request $request Request data.
81 81
 	 * @return array|mixed Response data, ready for insertion into collection data.
82 82
 	 */
83
-	public function get_currency( $code = false, $request ) {
83
+	public function get_currency($code = false, $request) {
84 84
 		$currencies = get_woocommerce_currencies();
85 85
 		$data       = array();
86 86
 
87
-		if ( ! array_key_exists( $code, $currencies ) ) {
87
+		if ( ! array_key_exists($code, $currencies)) {
88 88
 			return false;
89 89
 		}
90 90
 
91 91
 		$currency = array(
92 92
 			'code'   => $code,
93
-			'name'   => $currencies[ $code ],
94
-			'symbol' => get_woocommerce_currency_symbol( $code ),
93
+			'name'   => $currencies[$code],
94
+			'symbol' => get_woocommerce_currency_symbol($code),
95 95
 		);
96 96
 
97 97
 		return $currency;
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 	 * @param  WP_REST_Request $request Request data.
104 104
 	 * @return WP_Error|WP_REST_Response
105 105
 	 */
106
-	public function get_items( $request ) {
106
+	public function get_items($request) {
107 107
 		$currencies = get_woocommerce_currencies();
108
-		foreach ( array_keys( $currencies ) as $code ) {
109
-			$currency = $this->get_currency( $code, $request );
110
-			$response = $this->prepare_item_for_response( $currency, $request );
111
-			$data[]   = $this->prepare_response_for_collection( $response );
108
+		foreach (array_keys($currencies) as $code) {
109
+			$currency = $this->get_currency($code, $request);
110
+			$response = $this->prepare_item_for_response($currency, $request);
111
+			$data[]   = $this->prepare_response_for_collection($response);
112 112
 		}
113 113
 
114
-		return rest_ensure_response( $data );
114
+		return rest_ensure_response($data);
115 115
 	}
116 116
 
117 117
 	/**
@@ -120,12 +120,12 @@  discard block
 block discarded – undo
120 120
 	 * @param  WP_REST_Request $request Request data.
121 121
 	 * @return WP_Error|WP_REST_Response
122 122
 	 */
123
-	public function get_item( $request ) {
124
-		$data = $this->get_currency( strtoupper( $request['currency'] ), $request );
125
-		if ( empty( $data ) ) {
126
-			return new WP_Error( 'woocommerce_rest_data_invalid_currency', __( 'There are no currencies matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
123
+	public function get_item($request) {
124
+		$data = $this->get_currency(strtoupper($request['currency']), $request);
125
+		if (empty($data)) {
126
+			return new WP_Error('woocommerce_rest_data_invalid_currency', __('There are no currencies matching these parameters.', 'woocommerce'), array('status' => 404));
127 127
 		}
128
-		return $this->prepare_item_for_response( $data, $request );
128
+		return $this->prepare_item_for_response($data, $request);
129 129
 	}
130 130
 
131 131
 	/**
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 	 * @param  WP_REST_Request $request Request data.
135 135
 	 * @return WP_Error|WP_REST_Response
136 136
 	 */
137
-	public function get_current_item( $request ) {
138
-		$currency = get_option( 'woocommerce_currency' );
139
-		return $this->prepare_item_for_response( $this->get_currency( $currency, $request ), $request );
137
+	public function get_current_item($request) {
138
+		$currency = get_option('woocommerce_currency');
139
+		return $this->prepare_item_for_response($this->get_currency($currency, $request), $request);
140 140
 	}
141 141
 
142 142
 	/**
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
 	 * @param WP_REST_Request $request Request object.
147 147
 	 * @return WP_REST_Response $response Response data.
148 148
 	 */
149
-	public function prepare_item_for_response( $item, $request ) {
150
-		$data     = $this->add_additional_fields_to_object( $item, $request );
151
-		$data     = $this->filter_response_by_context( $data, 'view' );
152
-		$response = rest_ensure_response( $data );
149
+	public function prepare_item_for_response($item, $request) {
150
+		$data     = $this->add_additional_fields_to_object($item, $request);
151
+		$data     = $this->filter_response_by_context($data, 'view');
152
+		$response = rest_ensure_response($data);
153 153
 
154
-		$response->add_links( $this->prepare_links( $item ) );
154
+		$response->add_links($this->prepare_links($item));
155 155
 
156 156
 		/**
157 157
 		 * Filter currency returned from the API.
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		 * @param array            $item     Currency data.
161 161
 		 * @param WP_REST_Request  $request  Request used to generate the response.
162 162
 		 */
163
-		return apply_filters( 'woocommerce_rest_prepare_data_currency', $response, $item, $request );
163
+		return apply_filters('woocommerce_rest_prepare_data_currency', $response, $item, $request);
164 164
 	}
165 165
 
166 166
 	/**
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 	 * @param object $item Data object.
170 170
 	 * @return array Links for the given currency.
171 171
 	 */
172
-	protected function prepare_links( $item ) {
173
-		$code  = strtoupper( $item['code'] );
172
+	protected function prepare_links($item) {
173
+		$code  = strtoupper($item['code']);
174 174
 		$links = array(
175 175
 			'self'       => array(
176
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $code ) ),
176
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $code)),
177 177
 			),
178 178
 			'collection' => array(
179
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
179
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
180 180
 			),
181 181
 		);
182 182
 
@@ -197,25 +197,25 @@  discard block
 block discarded – undo
197 197
 			'properties' => array(
198 198
 				'code'   => array(
199 199
 					'type'        => 'string',
200
-					'description' => __( 'ISO4217 currency code.', 'woocommerce' ),
201
-					'context'     => array( 'view' ),
200
+					'description' => __('ISO4217 currency code.', 'woocommerce'),
201
+					'context'     => array('view'),
202 202
 					'readonly'    => true,
203 203
 				),
204 204
 				'name'   => array(
205 205
 					'type'        => 'string',
206
-					'description' => __( 'Full name of currency.', 'woocommerce' ),
207
-					'context'     => array( 'view' ),
206
+					'description' => __('Full name of currency.', 'woocommerce'),
207
+					'context'     => array('view'),
208 208
 					'readonly'    => true,
209 209
 				),
210 210
 				'symbol' => array(
211 211
 					'type'        => 'string',
212
-					'description' => __( 'Currency symbol.', 'woocommerce' ),
213
-					'context'     => array( 'view' ),
212
+					'description' => __('Currency symbol.', 'woocommerce'),
213
+					'context'     => array('view'),
214 214
 					'readonly'    => true,
215 215
 				),
216 216
 			),
217 217
 		);
218 218
 
219
-		return $this->add_additional_fields_schema( $schema );
219
+		return $this->add_additional_fields_schema($schema);
220 220
 	}
221 221
 }
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-customer-downloads-controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Customers controller class.
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-shipping-zones-controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @since   3.0.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Shipping Zones class.
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-network-orders-controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @since   3.4.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Network Orders controller class.
Please login to merge, or discard this patch.