Completed
Push — master ( 411054...889b36 )
by Mike
557:22 queued 512:23
created
src/RestApi/Version4/Controllers/ProductVariations.php 1 patch
Spacing   +358 added lines, -358 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API variations controller class.
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 * Initialize product actions (parent).
35 35
 	 */
36 36
 	public function __construct() {
37
-		add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'add_product_id' ), 9, 2 );
37
+		add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'add_product_id'), 9, 2);
38 38
 		parent::__construct();
39 39
 	}
40 40
 
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
 			array(
49 49
 				'args'   => array(
50 50
 					'product_id' => array(
51
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
51
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
52 52
 						'type'        => 'integer',
53 53
 					),
54 54
 				),
55 55
 				array(
56 56
 					'methods'             => \WP_REST_Server::READABLE,
57
-					'callback'            => array( $this, 'get_items' ),
58
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
57
+					'callback'            => array($this, 'get_items'),
58
+					'permission_callback' => array($this, 'get_items_permissions_check'),
59 59
 					'args'                => $this->get_collection_params(),
60 60
 				),
61 61
 				array(
62 62
 					'methods'             => \WP_REST_Server::CREATABLE,
63
-					'callback'            => array( $this, 'create_item' ),
64
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
65
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
63
+					'callback'            => array($this, 'create_item'),
64
+					'permission_callback' => array($this, 'create_item_permissions_check'),
65
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
66 66
 				),
67
-				'schema' => array( $this, 'get_public_item_schema' ),
67
+				'schema' => array($this, 'get_public_item_schema'),
68 68
 			),
69 69
 			true
70 70
 		);
@@ -74,18 +74,18 @@  discard block
 block discarded – undo
74 74
 			array(
75 75
 				'args'   => array(
76 76
 					'product_id' => array(
77
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
77
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
78 78
 						'type'        => 'integer',
79 79
 					),
80 80
 					'id'         => array(
81
-						'description' => __( 'Unique identifier for the variation.', 'woocommerce' ),
81
+						'description' => __('Unique identifier for the variation.', 'woocommerce'),
82 82
 						'type'        => 'integer',
83 83
 					),
84 84
 				),
85 85
 				array(
86 86
 					'methods'             => \WP_REST_Server::READABLE,
87
-					'callback'            => array( $this, 'get_item' ),
88
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
87
+					'callback'            => array($this, 'get_item'),
88
+					'permission_callback' => array($this, 'get_item_permissions_check'),
89 89
 					'args'                => array(
90 90
 						'context' => $this->get_context_param(
91 91
 							array(
@@ -96,23 +96,23 @@  discard block
 block discarded – undo
96 96
 				),
97 97
 				array(
98 98
 					'methods'             => \WP_REST_Server::EDITABLE,
99
-					'callback'            => array( $this, 'update_item' ),
100
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
101
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
99
+					'callback'            => array($this, 'update_item'),
100
+					'permission_callback' => array($this, 'update_item_permissions_check'),
101
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
102 102
 				),
103 103
 				array(
104 104
 					'methods'             => \WP_REST_Server::DELETABLE,
105
-					'callback'            => array( $this, 'delete_item' ),
106
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
105
+					'callback'            => array($this, 'delete_item'),
106
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
107 107
 					'args'                => array(
108 108
 						'force' => array(
109 109
 							'default'     => false,
110 110
 							'type'        => 'boolean',
111
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
111
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
112 112
 						),
113 113
 					),
114 114
 				),
115
-				'schema' => array( $this, 'get_public_item_schema' ),
115
+				'schema' => array($this, 'get_public_item_schema'),
116 116
 			),
117 117
 			true
118 118
 		);
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
 			array(
122 122
 				'args'   => array(
123 123
 					'product_id' => array(
124
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
124
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
125 125
 						'type'        => 'integer',
126 126
 					),
127 127
 				),
128 128
 				array(
129 129
 					'methods'             => \WP_REST_Server::EDITABLE,
130
-					'callback'            => array( $this, 'batch_items' ),
131
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
132
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
130
+					'callback'            => array($this, 'batch_items'),
131
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
132
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
133 133
 				),
134
-				'schema' => array( $this, 'get_public_batch_schema' ),
134
+				'schema' => array($this, 'get_public_batch_schema'),
135 135
 			),
136 136
 			true
137 137
 		);
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	 * @param  int $id Object ID.
145 145
 	 * @return WC_Data
146 146
 	 */
147
-	protected function get_object( $id ) {
148
-		return wc_get_product( $id );
147
+	protected function get_object($id) {
148
+		return wc_get_product($id);
149 149
 	}
150 150
 
151 151
 	/**
@@ -154,16 +154,16 @@  discard block
 block discarded – undo
154 154
 	 * @param  \WP_REST_Request $request Full details about the request.
155 155
 	 * @return \WP_Error|boolean
156 156
 	 */
157
-	public function update_item_permissions_check( $request ) {
158
-		$object = $this->get_object( (int) $request['id'] );
157
+	public function update_item_permissions_check($request) {
158
+		$object = $this->get_object((int) $request['id']);
159 159
 
160
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
161
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
160
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'edit', $object->get_id())) {
161
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
162 162
 		}
163 163
 
164 164
 		// Check if variation belongs to the correct parent product.
165
-		if ( $object && 0 !== $object->get_parent_id() && absint( $request['product_id'] ) !== $object->get_parent_id() ) {
166
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Parent product does not match current variation.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
165
+		if ($object && 0 !== $object->get_parent_id() && absint($request['product_id']) !== $object->get_parent_id()) {
166
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Parent product does not match current variation.', 'woocommerce'), array('status' => rest_authorization_required_code()));
167 167
 		}
168 168
 
169 169
 		return true;
@@ -176,33 +176,33 @@  discard block
 block discarded – undo
176 176
 	 * @param  \WP_REST_Request $request Request object.
177 177
 	 * @return \WP_REST_Response
178 178
 	 */
179
-	public function prepare_object_for_response( $object, $request ) {
180
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
179
+	public function prepare_object_for_response($object, $request) {
180
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
181 181
 		$data    = array(
182 182
 			'id'                    => $object->get_id(),
183
-			'name'                  => $object->get_name( $context ),
183
+			'name'                  => $object->get_name($context),
184 184
 			'type'                  => $object->get_type(),
185
-			'parent_id'             => $object->get_parent_id( $context ),
186
-			'date_created'          => wc_rest_prepare_date_response( $object->get_date_created(), false ),
187
-			'date_created_gmt'      => wc_rest_prepare_date_response( $object->get_date_created() ),
188
-			'date_modified'         => wc_rest_prepare_date_response( $object->get_date_modified(), false ),
189
-			'date_modified_gmt'     => wc_rest_prepare_date_response( $object->get_date_modified() ),
190
-			'description'           => wc_format_content( $object->get_description() ),
185
+			'parent_id'             => $object->get_parent_id($context),
186
+			'date_created'          => wc_rest_prepare_date_response($object->get_date_created(), false),
187
+			'date_created_gmt'      => wc_rest_prepare_date_response($object->get_date_created()),
188
+			'date_modified'         => wc_rest_prepare_date_response($object->get_date_modified(), false),
189
+			'date_modified_gmt'     => wc_rest_prepare_date_response($object->get_date_modified()),
190
+			'description'           => wc_format_content($object->get_description()),
191 191
 			'permalink'             => $object->get_permalink(),
192 192
 			'sku'                   => $object->get_sku(),
193 193
 			'price'                 => $object->get_price(),
194 194
 			'regular_price'         => $object->get_regular_price(),
195 195
 			'sale_price'            => $object->get_sale_price(),
196
-			'date_on_sale_from'     => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ),
197
-			'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ),
198
-			'date_on_sale_to'       => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ),
199
-			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ),
196
+			'date_on_sale_from'     => wc_rest_prepare_date_response($object->get_date_on_sale_from(), false),
197
+			'date_on_sale_from_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_from()),
198
+			'date_on_sale_to'       => wc_rest_prepare_date_response($object->get_date_on_sale_to(), false),
199
+			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response($object->get_date_on_sale_to()),
200 200
 			'on_sale'               => $object->is_on_sale(),
201 201
 			'status'                => $object->get_status(),
202 202
 			'purchasable'           => $object->is_purchasable(),
203 203
 			'virtual'               => $object->is_virtual(),
204 204
 			'downloadable'          => $object->is_downloadable(),
205
-			'downloads'             => $this->get_downloads( $object ),
205
+			'downloads'             => $this->get_downloads($object),
206 206
 			'download_limit'        => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1,
207 207
 			'download_expiry'       => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1,
208 208
 			'tax_status'            => $object->get_tax_status(),
@@ -221,17 +221,17 @@  discard block
 block discarded – undo
221 221
 			),
222 222
 			'shipping_class'        => $object->get_shipping_class(),
223 223
 			'shipping_class_id'     => $object->get_shipping_class_id(),
224
-			'image'                 => $this->get_image( $object ),
225
-			'attributes'            => $this->get_attributes( $object ),
224
+			'image'                 => $this->get_image($object),
225
+			'attributes'            => $this->get_attributes($object),
226 226
 			'menu_order'            => $object->get_menu_order(),
227 227
 			'meta_data'             => $object->get_meta_data(),
228 228
 		);
229 229
 
230
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
231
-		$data     = $this->add_additional_fields_to_object( $data, $request );
232
-		$data     = $this->filter_response_by_context( $data, $context );
233
-		$response = rest_ensure_response( $data );
234
-		$response->add_links( $this->prepare_links( $object, $request ) );
230
+		$context  = ! empty($request['context']) ? $request['context'] : 'view';
231
+		$data     = $this->add_additional_fields_to_object($data, $request);
232
+		$data     = $this->filter_response_by_context($data, $context);
233
+		$response = rest_ensure_response($data);
234
+		$response->add_links($this->prepare_links($object, $request));
235 235
 
236 236
 		/**
237 237
 		 * Filter the data for a response.
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 		 * @param WC_Data          $object   Object data.
244 244
 		 * @param \WP_REST_Request  $request  Request object.
245 245
 		 */
246
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
246
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
247 247
 	}
248 248
 
249 249
 	/**
@@ -252,32 +252,32 @@  discard block
 block discarded – undo
252 252
 	 * @param WC_Product_Variation $variation Variation data.
253 253
 	 * @return array
254 254
 	 */
255
-	protected function get_image( $variation ) {
256
-		if ( ! $variation->get_image_id() ) {
255
+	protected function get_image($variation) {
256
+		if ( ! $variation->get_image_id()) {
257 257
 			return;
258 258
 		}
259 259
 
260 260
 		$attachment_id   = $variation->get_image_id();
261
-		$attachment_post = get_post( $attachment_id );
262
-		if ( is_null( $attachment_post ) ) {
261
+		$attachment_post = get_post($attachment_id);
262
+		if (is_null($attachment_post)) {
263 263
 			return;
264 264
 		}
265 265
 
266
-		$attachment = wp_get_attachment_image_src( $attachment_id, 'full' );
267
-		if ( ! is_array( $attachment ) ) {
266
+		$attachment = wp_get_attachment_image_src($attachment_id, 'full');
267
+		if ( ! is_array($attachment)) {
268 268
 			return;
269 269
 		}
270 270
 
271
-		if ( ! isset( $image ) ) {
271
+		if ( ! isset($image)) {
272 272
 			return array(
273 273
 				'id'                => (int) $attachment_id,
274
-				'date_created'      => wc_rest_prepare_date_response( $attachment_post->post_date, false ),
275
-				'date_created_gmt'  => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ),
276
-				'date_modified'     => wc_rest_prepare_date_response( $attachment_post->post_modified, false ),
277
-				'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ),
278
-				'src'               => current( $attachment ),
279
-				'name'              => get_the_title( $attachment_id ),
280
-				'alt'               => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
274
+				'date_created'      => wc_rest_prepare_date_response($attachment_post->post_date, false),
275
+				'date_created_gmt'  => wc_rest_prepare_date_response(strtotime($attachment_post->post_date_gmt)),
276
+				'date_modified'     => wc_rest_prepare_date_response($attachment_post->post_modified, false),
277
+				'date_modified_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_modified_gmt)),
278
+				'src'               => current($attachment),
279
+				'name'              => get_the_title($attachment_id),
280
+				'alt'               => get_post_meta($attachment_id, '_wp_attachment_image_alt', true),
281 281
 			);
282 282
 		}
283 283
 	}
@@ -291,35 +291,35 @@  discard block
 block discarded – undo
291 291
 	 * @param  array                 $image     Image data.
292 292
 	 * @return WC_Product_Variation
293 293
 	 */
294
-	protected function set_variation_image( $variation, $image ) {
295
-		$attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
294
+	protected function set_variation_image($variation, $image) {
295
+		$attachment_id = isset($image['id']) ? absint($image['id']) : 0;
296 296
 
297
-		if ( 0 === $attachment_id && isset( $image['src'] ) ) {
298
-			$upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) );
297
+		if (0 === $attachment_id && isset($image['src'])) {
298
+			$upload = wc_rest_upload_image_from_url(esc_url_raw($image['src']));
299 299
 
300
-			if ( is_wp_error( $upload ) ) {
301
-				if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array( $image ) ) ) {
302
-					throw new \WC_REST_Exception( 'woocommerce_variation_image_upload_error', $upload->get_error_message(), 400 );
300
+			if (is_wp_error($upload)) {
301
+				if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array($image))) {
302
+					throw new \WC_REST_Exception('woocommerce_variation_image_upload_error', $upload->get_error_message(), 400);
303 303
 				}
304 304
 			}
305 305
 
306
-			$attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $variation->get_id() );
306
+			$attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $variation->get_id());
307 307
 		}
308 308
 
309
-		if ( ! wp_attachment_is_image( $attachment_id ) ) {
309
+		if ( ! wp_attachment_is_image($attachment_id)) {
310 310
 			/* translators: %s: attachment ID */
311
-			throw new \WC_REST_Exception( 'woocommerce_variation_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 );
311
+			throw new \WC_REST_Exception('woocommerce_variation_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400);
312 312
 		}
313 313
 
314
-		$variation->set_image_id( $attachment_id );
314
+		$variation->set_image_id($attachment_id);
315 315
 
316 316
 		// Set the image alt if present.
317
-		if ( ! empty( $image['alt'] ) ) {
318
-			update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) );
317
+		if ( ! empty($image['alt'])) {
318
+			update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt']));
319 319
 		}
320 320
 
321 321
 		// Set the image name if present.
322
-		if ( ! empty( $image['name'] ) ) {
322
+		if ( ! empty($image['name'])) {
323 323
 			wp_update_post(
324 324
 				array(
325 325
 					'ID'         => $attachment_id,
@@ -338,17 +338,17 @@  discard block
 block discarded – undo
338 338
 	 * @param  \WP_REST_Request $request Full details about the request.
339 339
 	 * @return array
340 340
 	 */
341
-	protected function prepare_objects_query( $request ) {
342
-		$args = parent::prepare_objects_query( $request );
341
+	protected function prepare_objects_query($request) {
342
+		$args = parent::prepare_objects_query($request);
343 343
 
344 344
 		// Set post_status.
345 345
 		$args['post_status'] = $request['status'];
346 346
 
347 347
 		// Filter by sku.
348
-		if ( ! empty( $request['sku'] ) ) {
349
-			$skus = explode( ',', $request['sku'] );
348
+		if ( ! empty($request['sku'])) {
349
+			$skus = explode(',', $request['sku']);
350 350
 			// Include the current string as a SKU too.
351
-			if ( 1 < count( $skus ) ) {
351
+			if (1 < count($skus)) {
352 352
 				$skus[] = $request['sku'];
353 353
 			}
354 354
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 		}
364 364
 
365 365
 		// Filter by tax class.
366
-		if ( ! empty( $request['tax_class'] ) ) {
366
+		if ( ! empty($request['tax_class'])) {
367 367
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
368 368
 				$args,
369 369
 				array(
@@ -374,12 +374,12 @@  discard block
 block discarded – undo
374 374
 		}
375 375
 
376 376
 		// Price filter.
377
-		if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) {
378
-			$args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) );  // WPCS: slow query ok.
377
+		if ( ! empty($request['min_price']) || ! empty($request['max_price'])) {
378
+			$args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); // WPCS: slow query ok.
379 379
 		}
380 380
 
381 381
 		// Filter product based on stock_status.
382
-		if ( ! empty( $request['stock_status'] ) ) {
382
+		if ( ! empty($request['stock_status'])) {
383 383
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
384 384
 				$args,
385 385
 				array(
@@ -390,28 +390,28 @@  discard block
 block discarded – undo
390 390
 		}
391 391
 
392 392
 		// Filter by on sale products.
393
-		if ( is_bool( $request['on_sale'] ) ) {
393
+		if (is_bool($request['on_sale'])) {
394 394
 			$on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in';
395 395
 			$on_sale_ids = wc_get_product_ids_on_sale();
396 396
 
397 397
 			// Use 0 when there's no on sale products to avoid return all products.
398
-			$on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids;
398
+			$on_sale_ids = empty($on_sale_ids) ? array(0) : $on_sale_ids;
399 399
 
400
-			$args[ $on_sale_key ] += $on_sale_ids;
400
+			$args[$on_sale_key] += $on_sale_ids;
401 401
 		}
402 402
 
403 403
 		// Force the post_type argument, since it's not a user input variable.
404
-		if ( ! empty( $request['sku'] ) ) {
405
-			$args['post_type'] = array( 'product', 'product_variation' );
404
+		if ( ! empty($request['sku'])) {
405
+			$args['post_type'] = array('product', 'product_variation');
406 406
 		} else {
407 407
 			$args['post_type'] = $this->post_type;
408 408
 		}
409 409
 
410 410
 		$args['post_parent'] = $request['product_id'];
411 411
 
412
-		if ( ! empty( $request['search'] ) ) {
412
+		if ( ! empty($request['search'])) {
413 413
 			$args['search'] = $request['search'];
414
-			unset( $args['s'] );
414
+			unset($args['s']);
415 415
 		}
416 416
 
417 417
 		return $args;
@@ -424,136 +424,136 @@  discard block
 block discarded – undo
424 424
 	 * @param  bool            $creating If is creating a new object.
425 425
 	 * @return \WP_Error|WC_Data
426 426
 	 */
427
-	protected function prepare_object_for_database( $request, $creating = false ) {
428
-		if ( isset( $request['id'] ) ) {
429
-			$variation = wc_get_product( absint( $request['id'] ) );
427
+	protected function prepare_object_for_database($request, $creating = false) {
428
+		if (isset($request['id'])) {
429
+			$variation = wc_get_product(absint($request['id']));
430 430
 		} else {
431 431
 			$variation = new \WC_Product_Variation();
432 432
 		}
433 433
 
434
-		$variation->set_parent_id( absint( $request['product_id'] ) );
434
+		$variation->set_parent_id(absint($request['product_id']));
435 435
 
436 436
 		// Status.
437
-		if ( isset( $request['status'] ) ) {
438
-			$variation->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' );
437
+		if (isset($request['status'])) {
438
+			$variation->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft');
439 439
 		}
440 440
 
441 441
 		// SKU.
442
-		if ( isset( $request['sku'] ) ) {
443
-			$variation->set_sku( wc_clean( $request['sku'] ) );
442
+		if (isset($request['sku'])) {
443
+			$variation->set_sku(wc_clean($request['sku']));
444 444
 		}
445 445
 
446 446
 		// Thumbnail.
447
-		if ( isset( $request['image'] ) ) {
448
-			if ( is_array( $request['image'] ) ) {
449
-				$variation = $this->set_variation_image( $variation, $request['image'] );
447
+		if (isset($request['image'])) {
448
+			if (is_array($request['image'])) {
449
+				$variation = $this->set_variation_image($variation, $request['image']);
450 450
 			} else {
451
-				$variation->set_image_id( '' );
451
+				$variation->set_image_id('');
452 452
 			}
453 453
 		}
454 454
 
455 455
 		// Virtual variation.
456
-		if ( isset( $request['virtual'] ) ) {
457
-			$variation->set_virtual( $request['virtual'] );
456
+		if (isset($request['virtual'])) {
457
+			$variation->set_virtual($request['virtual']);
458 458
 		}
459 459
 
460 460
 		// Downloadable variation.
461
-		if ( isset( $request['downloadable'] ) ) {
462
-			$variation->set_downloadable( $request['downloadable'] );
461
+		if (isset($request['downloadable'])) {
462
+			$variation->set_downloadable($request['downloadable']);
463 463
 		}
464 464
 
465 465
 		// Downloads.
466
-		if ( $variation->get_downloadable() ) {
466
+		if ($variation->get_downloadable()) {
467 467
 			// Downloadable files.
468
-			if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) {
469
-				$variation = $this->save_downloadable_files( $variation, $request['downloads'] );
468
+			if (isset($request['downloads']) && is_array($request['downloads'])) {
469
+				$variation = $this->save_downloadable_files($variation, $request['downloads']);
470 470
 			}
471 471
 
472 472
 			// Download limit.
473
-			if ( isset( $request['download_limit'] ) ) {
474
-				$variation->set_download_limit( $request['download_limit'] );
473
+			if (isset($request['download_limit'])) {
474
+				$variation->set_download_limit($request['download_limit']);
475 475
 			}
476 476
 
477 477
 			// Download expiry.
478
-			if ( isset( $request['download_expiry'] ) ) {
479
-				$variation->set_download_expiry( $request['download_expiry'] );
478
+			if (isset($request['download_expiry'])) {
479
+				$variation->set_download_expiry($request['download_expiry']);
480 480
 			}
481 481
 		}
482 482
 
483 483
 		// Shipping data.
484
-		$variation = $this->save_product_shipping_data( $variation, $request );
484
+		$variation = $this->save_product_shipping_data($variation, $request);
485 485
 
486 486
 		// Stock handling.
487
-		if ( isset( $request['manage_stock'] ) ) {
488
-			$variation->set_manage_stock( $request['manage_stock'] );
487
+		if (isset($request['manage_stock'])) {
488
+			$variation->set_manage_stock($request['manage_stock']);
489 489
 		}
490 490
 
491
-		if ( isset( $request['stock_status'] ) ) {
492
-			$variation->set_stock_status( $request['stock_status'] );
491
+		if (isset($request['stock_status'])) {
492
+			$variation->set_stock_status($request['stock_status']);
493 493
 		}
494 494
 
495
-		if ( isset( $request['backorders'] ) ) {
496
-			$variation->set_backorders( $request['backorders'] );
495
+		if (isset($request['backorders'])) {
496
+			$variation->set_backorders($request['backorders']);
497 497
 		}
498 498
 
499
-		if ( $variation->get_manage_stock() ) {
500
-			if ( isset( $request['stock_quantity'] ) ) {
501
-				$variation->set_stock_quantity( $request['stock_quantity'] );
502
-			} elseif ( isset( $request['inventory_delta'] ) ) {
503
-				$stock_quantity  = wc_stock_amount( $variation->get_stock_quantity() );
504
-				$stock_quantity += wc_stock_amount( $request['inventory_delta'] );
505
-				$variation->set_stock_quantity( $stock_quantity );
499
+		if ($variation->get_manage_stock()) {
500
+			if (isset($request['stock_quantity'])) {
501
+				$variation->set_stock_quantity($request['stock_quantity']);
502
+			} elseif (isset($request['inventory_delta'])) {
503
+				$stock_quantity  = wc_stock_amount($variation->get_stock_quantity());
504
+				$stock_quantity += wc_stock_amount($request['inventory_delta']);
505
+				$variation->set_stock_quantity($stock_quantity);
506 506
 			}
507 507
 		} else {
508
-			$variation->set_backorders( 'no' );
509
-			$variation->set_stock_quantity( '' );
508
+			$variation->set_backorders('no');
509
+			$variation->set_stock_quantity('');
510 510
 		}
511 511
 
512 512
 		// Regular Price.
513
-		if ( isset( $request['regular_price'] ) ) {
514
-			$variation->set_regular_price( $request['regular_price'] );
513
+		if (isset($request['regular_price'])) {
514
+			$variation->set_regular_price($request['regular_price']);
515 515
 		}
516 516
 
517 517
 		// Sale Price.
518
-		if ( isset( $request['sale_price'] ) ) {
519
-			$variation->set_sale_price( $request['sale_price'] );
518
+		if (isset($request['sale_price'])) {
519
+			$variation->set_sale_price($request['sale_price']);
520 520
 		}
521 521
 
522
-		if ( isset( $request['date_on_sale_from'] ) ) {
523
-			$variation->set_date_on_sale_from( $request['date_on_sale_from'] );
522
+		if (isset($request['date_on_sale_from'])) {
523
+			$variation->set_date_on_sale_from($request['date_on_sale_from']);
524 524
 		}
525 525
 
526
-		if ( isset( $request['date_on_sale_from_gmt'] ) ) {
527
-			$variation->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null );
526
+		if (isset($request['date_on_sale_from_gmt'])) {
527
+			$variation->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null);
528 528
 		}
529 529
 
530
-		if ( isset( $request['date_on_sale_to'] ) ) {
531
-			$variation->set_date_on_sale_to( $request['date_on_sale_to'] );
530
+		if (isset($request['date_on_sale_to'])) {
531
+			$variation->set_date_on_sale_to($request['date_on_sale_to']);
532 532
 		}
533 533
 
534
-		if ( isset( $request['date_on_sale_to_gmt'] ) ) {
535
-			$variation->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null );
534
+		if (isset($request['date_on_sale_to_gmt'])) {
535
+			$variation->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null);
536 536
 		}
537 537
 
538 538
 		// Tax class.
539
-		if ( isset( $request['tax_class'] ) ) {
540
-			$variation->set_tax_class( $request['tax_class'] );
539
+		if (isset($request['tax_class'])) {
540
+			$variation->set_tax_class($request['tax_class']);
541 541
 		}
542 542
 
543 543
 		// Description.
544
-		if ( isset( $request['description'] ) ) {
545
-			$variation->set_description( wp_kses_post( $request['description'] ) );
544
+		if (isset($request['description'])) {
545
+			$variation->set_description(wp_kses_post($request['description']));
546 546
 		}
547 547
 
548 548
 		// Update taxonomies.
549
-		if ( isset( $request['attributes'] ) ) {
549
+		if (isset($request['attributes'])) {
550 550
 			$attributes = array();
551
-			$parent     = wc_get_product( $variation->get_parent_id() );
551
+			$parent     = wc_get_product($variation->get_parent_id());
552 552
 
553
-			if ( ! $parent ) {
553
+			if ( ! $parent) {
554 554
 				return new \WP_Error(
555 555
 					// Translators: %d parent ID.
556
-					"woocommerce_rest_{$this->post_type}_invalid_parent", sprintf( __( 'Cannot set attributes due to invalid parent product.', 'woocommerce' ), $variation->get_parent_id() ), array(
556
+					"woocommerce_rest_{$this->post_type}_invalid_parent", sprintf(__('Cannot set attributes due to invalid parent product.', 'woocommerce'), $variation->get_parent_id()), array(
557 557
 						'status' => 404,
558 558
 					)
559 559
 				);
@@ -561,55 +561,55 @@  discard block
 block discarded – undo
561 561
 
562 562
 			$parent_attributes = $parent->get_attributes();
563 563
 
564
-			foreach ( $request['attributes'] as $attribute ) {
564
+			foreach ($request['attributes'] as $attribute) {
565 565
 				$attribute_id   = 0;
566 566
 				$attribute_name = '';
567 567
 
568 568
 				// Check ID for global attributes or name for product attributes.
569
-				if ( ! empty( $attribute['id'] ) ) {
570
-					$attribute_id   = absint( $attribute['id'] );
571
-					$attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id );
572
-				} elseif ( ! empty( $attribute['name'] ) ) {
573
-					$attribute_name = sanitize_title( $attribute['name'] );
569
+				if ( ! empty($attribute['id'])) {
570
+					$attribute_id   = absint($attribute['id']);
571
+					$attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
572
+				} elseif ( ! empty($attribute['name'])) {
573
+					$attribute_name = sanitize_title($attribute['name']);
574 574
 				}
575 575
 
576
-				if ( ! $attribute_id && ! $attribute_name ) {
576
+				if ( ! $attribute_id && ! $attribute_name) {
577 577
 					continue;
578 578
 				}
579 579
 
580
-				if ( ! isset( $parent_attributes[ $attribute_name ] ) || ! $parent_attributes[ $attribute_name ]->get_variation() ) {
580
+				if ( ! isset($parent_attributes[$attribute_name]) || ! $parent_attributes[$attribute_name]->get_variation()) {
581 581
 					continue;
582 582
 				}
583 583
 
584
-				$attribute_key   = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() );
585
-				$attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : '';
584
+				$attribute_key   = sanitize_title($parent_attributes[$attribute_name]->get_name());
585
+				$attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
586 586
 
587
-				if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) {
587
+				if ($parent_attributes[$attribute_name]->is_taxonomy()) {
588 588
 					// If dealing with a taxonomy, we need to get the slug from the name posted to the API.
589
-					$term = get_term_by( 'name', $attribute_value, $attribute_name );
589
+					$term = get_term_by('name', $attribute_value, $attribute_name);
590 590
 
591
-					if ( $term && ! is_wp_error( $term ) ) {
591
+					if ($term && ! is_wp_error($term)) {
592 592
 						$attribute_value = $term->slug;
593 593
 					} else {
594
-						$attribute_value = sanitize_title( $attribute_value );
594
+						$attribute_value = sanitize_title($attribute_value);
595 595
 					}
596 596
 				}
597 597
 
598
-				$attributes[ $attribute_key ] = $attribute_value;
598
+				$attributes[$attribute_key] = $attribute_value;
599 599
 			}
600 600
 
601
-			$variation->set_attributes( $attributes );
601
+			$variation->set_attributes($attributes);
602 602
 		}
603 603
 
604 604
 		// Menu order.
605
-		if ( $request['menu_order'] ) {
606
-			$variation->set_menu_order( $request['menu_order'] );
605
+		if ($request['menu_order']) {
606
+			$variation->set_menu_order($request['menu_order']);
607 607
 		}
608 608
 
609 609
 		// Meta data.
610
-		if ( is_array( $request['meta_data'] ) ) {
611
-			foreach ( $request['meta_data'] as $meta ) {
612
-				$variation->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
610
+		if (is_array($request['meta_data'])) {
611
+			foreach ($request['meta_data'] as $meta) {
612
+				$variation->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
613 613
 			}
614 614
 		}
615 615
 
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 		 * @param \WP_REST_Request $request   Request object.
624 624
 		 * @param bool            $creating  If is creating a new object.
625 625
 		 */
626
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating );
626
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating);
627 627
 	}
628 628
 
629 629
 	/**
@@ -631,9 +631,9 @@  discard block
 block discarded – undo
631 631
 	 *
632 632
 	 * @param WC_Data $object Object data.
633 633
 	 */
634
-	public function clear_transients( $object ) {
635
-		wc_delete_product_transients( $object->get_parent_id() );
636
-		wp_cache_delete( 'product-' . $object->get_parent_id(), 'products' );
634
+	public function clear_transients($object) {
635
+		wc_delete_product_transients($object->get_parent_id());
636
+		wp_cache_delete('product-' . $object->get_parent_id(), 'products');
637 637
 	}
638 638
 
639 639
 	/**
@@ -643,20 +643,20 @@  discard block
 block discarded – undo
643 643
 	 *
644 644
 	 * @return bool|\WP_Error\WP_REST_Response
645 645
 	 */
646
-	public function delete_item( $request ) {
646
+	public function delete_item($request) {
647 647
 		$force  = (bool) $request['force'];
648
-		$object = $this->get_object( (int) $request['id'] );
648
+		$object = $this->get_object((int) $request['id']);
649 649
 		$result = false;
650 650
 
651
-		if ( ! $object || 0 === $object->get_id() ) {
651
+		if ( ! $object || 0 === $object->get_id()) {
652 652
 			return new \WP_Error(
653
-				"woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array(
653
+				"woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array(
654 654
 					'status' => 404,
655 655
 				)
656 656
 			);
657 657
 		}
658 658
 
659
-		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) );
659
+		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable(array($object, 'get_status'));
660 660
 
661 661
 		/**
662 662
 		 * Filter whether an object is trashable.
@@ -666,24 +666,24 @@  discard block
 block discarded – undo
666 666
 		 * @param boolean $supports_trash Whether the object type support trashing.
667 667
 		 * @param WC_Data $object         The object being considered for trashing support.
668 668
 		 */
669
-		$supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object );
669
+		$supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object);
670 670
 
671
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
671
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
672 672
 			return new \WP_Error(
673 673
 				/* translators: %s: post type */
674
-				"woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array(
674
+				"woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array(
675 675
 					'status' => rest_authorization_required_code(),
676 676
 				)
677 677
 			);
678 678
 		}
679 679
 
680
-		$request->set_param( 'context', 'edit' );
680
+		$request->set_param('context', 'edit');
681 681
 
682 682
 		// If we're forcing, then delete permanently.
683
-		if ( $force ) {
684
-			$previous = $this->prepare_object_for_response( $object, $request );
683
+		if ($force) {
684
+			$previous = $this->prepare_object_for_response($object, $request);
685 685
 
686
-			$object->delete( true );
686
+			$object->delete(true);
687 687
 
688 688
 			$result   = 0 === $object->get_id();
689 689
 			$response = new \WP_REST_Response();
@@ -695,21 +695,21 @@  discard block
 block discarded – undo
695 695
 			);
696 696
 		} else {
697 697
 			// If we don't support trashing for this type, error out.
698
-			if ( ! $supports_trash ) {
698
+			if ( ! $supports_trash) {
699 699
 				return new \WP_Error(
700 700
 					/* translators: %s: post type */
701
-					'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array(
701
+					'woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array(
702 702
 						'status' => 501,
703 703
 					)
704 704
 				);
705 705
 			}
706 706
 
707 707
 			// Otherwise, only trash if we haven't already.
708
-			if ( is_callable( array( $object, 'get_status' ) ) ) {
709
-				if ( 'trash' === $object->get_status() ) {
708
+			if (is_callable(array($object, 'get_status'))) {
709
+				if ('trash' === $object->get_status()) {
710 710
 					return new \WP_Error(
711 711
 						/* translators: %s: post type */
712
-						'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array(
712
+						'woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array(
713 713
 							'status' => 410,
714 714
 						)
715 715
 					);
@@ -719,13 +719,13 @@  discard block
 block discarded – undo
719 719
 				$result = 'trash' === $object->get_status();
720 720
 			}
721 721
 
722
-			$response = $this->prepare_object_for_response( $object, $request );
722
+			$response = $this->prepare_object_for_response($object, $request);
723 723
 		}
724 724
 
725
-		if ( ! $result ) {
725
+		if ( ! $result) {
726 726
 			return new \WP_Error(
727 727
 				/* translators: %s: post type */
728
-				'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array(
728
+				'woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array(
729 729
 					'status' => 500,
730 730
 				)
731 731
 			);
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 		 * @param \WP_REST_Response $response The response data.
739 739
 		 * @param \WP_REST_Request  $request  The request sent to the API.
740 740
 		 */
741
-		do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );
741
+		do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request);
742 742
 
743 743
 		return $response;
744 744
 	}
@@ -750,30 +750,30 @@  discard block
 block discarded – undo
750 750
 	 * @param \WP_REST_Request $request Full details about the request.
751 751
 	 * @return array Of \WP_Error or \WP_REST_Response.
752 752
 	 */
753
-	public function batch_items( $request ) {
754
-		$items       = array_filter( $request->get_params() );
753
+	public function batch_items($request) {
754
+		$items       = array_filter($request->get_params());
755 755
 		$params      = $request->get_url_params();
756 756
 		$product_id  = $params['product_id'];
757 757
 		$body_params = array();
758 758
 
759
-		foreach ( array( 'update', 'create', 'delete' ) as $batch_type ) {
760
-			if ( ! empty( $items[ $batch_type ] ) ) {
759
+		foreach (array('update', 'create', 'delete') as $batch_type) {
760
+			if ( ! empty($items[$batch_type])) {
761 761
 				$injected_items = array();
762
-				foreach ( $items[ $batch_type ] as $item ) {
763
-					$injected_items[] = is_array( $item ) ? array_merge(
762
+				foreach ($items[$batch_type] as $item) {
763
+					$injected_items[] = is_array($item) ? array_merge(
764 764
 						array(
765 765
 							'product_id' => $product_id,
766 766
 						), $item
767 767
 					) : $item;
768 768
 				}
769
-				$body_params[ $batch_type ] = $injected_items;
769
+				$body_params[$batch_type] = $injected_items;
770 770
 			}
771 771
 		}
772 772
 
773
-		$request = new \WP_REST_Request( $request->get_method() );
774
-		$request->set_body_params( $body_params );
773
+		$request = new \WP_REST_Request($request->get_method());
774
+		$request->set_body_params($body_params);
775 775
 
776
-		return parent::batch_items( $request );
776
+		return parent::batch_items($request);
777 777
 	}
778 778
 
779 779
 	/**
@@ -783,18 +783,18 @@  discard block
 block discarded – undo
783 783
 	 * @param \WP_REST_Request $request Request object.
784 784
 	 * @return array                   Links for the given post.
785 785
 	 */
786
-	protected function prepare_links( $object, $request ) {
786
+	protected function prepare_links($object, $request) {
787 787
 		$product_id = (int) $request['product_id'];
788
-		$base       = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base );
788
+		$base       = str_replace('(?P<product_id>[\d]+)', $product_id, $this->rest_base);
789 789
 		$links      = array(
790 790
 			'self'       => array(
791
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $object->get_id() ) ),
791
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $object->get_id())),
792 792
 			),
793 793
 			'collection' => array(
794
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
794
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)),
795 795
 			),
796 796
 			'up'         => array(
797
-				'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product_id ) ),
797
+				'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product_id)),
798 798
 			),
799 799
 		);
800 800
 		return $links;
@@ -806,371 +806,371 @@  discard block
 block discarded – undo
806 806
 	 * @return array
807 807
 	 */
808 808
 	public function get_item_schema() {
809
-		$weight_unit    = get_option( 'woocommerce_weight_unit' );
810
-		$dimension_unit = get_option( 'woocommerce_dimension_unit' );
809
+		$weight_unit    = get_option('woocommerce_weight_unit');
810
+		$dimension_unit = get_option('woocommerce_dimension_unit');
811 811
 		$schema         = array(
812 812
 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
813 813
 			'title'      => $this->post_type,
814 814
 			'type'       => 'object',
815 815
 			'properties' => array(
816 816
 				'id'                    => array(
817
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
817
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
818 818
 					'type'        => 'integer',
819
-					'context'     => array( 'view', 'edit' ),
819
+					'context'     => array('view', 'edit'),
820 820
 					'readonly'    => true,
821 821
 				),
822 822
 				'name'                  => array(
823
-					'description' => __( 'Product parent name.', 'woocommerce' ),
823
+					'description' => __('Product parent name.', 'woocommerce'),
824 824
 					'type'        => 'string',
825
-					'context'     => array( 'view', 'edit' ),
825
+					'context'     => array('view', 'edit'),
826 826
 				),
827 827
 				'type'                  => array(
828
-					'description' => __( 'Product type.', 'woocommerce' ),
828
+					'description' => __('Product type.', 'woocommerce'),
829 829
 					'type'        => 'string',
830 830
 					'default'     => 'variation',
831
-					'enum'        => array( 'variation' ),
832
-					'context'     => array( 'view', 'edit' ),
831
+					'enum'        => array('variation'),
832
+					'context'     => array('view', 'edit'),
833 833
 				),
834 834
 				'parent_id'             => array(
835
-					'description' => __( 'Product parent ID.', 'woocommerce' ),
835
+					'description' => __('Product parent ID.', 'woocommerce'),
836 836
 					'type'        => 'integer',
837
-					'context'     => array( 'view', 'edit' ),
837
+					'context'     => array('view', 'edit'),
838 838
 				),
839 839
 				'date_created'          => array(
840
-					'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ),
840
+					'description' => __("The date the variation was created, in the site's timezone.", 'woocommerce'),
841 841
 					'type'        => 'date-time',
842
-					'context'     => array( 'view', 'edit' ),
842
+					'context'     => array('view', 'edit'),
843 843
 					'readonly'    => true,
844 844
 				),
845 845
 				'date_modified'         => array(
846
-					'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ),
846
+					'description' => __("The date the variation was last modified, in the site's timezone.", 'woocommerce'),
847 847
 					'type'        => 'date-time',
848
-					'context'     => array( 'view', 'edit' ),
848
+					'context'     => array('view', 'edit'),
849 849
 					'readonly'    => true,
850 850
 				),
851 851
 				'description'           => array(
852
-					'description' => __( 'Variation description.', 'woocommerce' ),
852
+					'description' => __('Variation description.', 'woocommerce'),
853 853
 					'type'        => 'string',
854
-					'context'     => array( 'view', 'edit' ),
854
+					'context'     => array('view', 'edit'),
855 855
 				),
856 856
 				'permalink'             => array(
857
-					'description' => __( 'Variation URL.', 'woocommerce' ),
857
+					'description' => __('Variation URL.', 'woocommerce'),
858 858
 					'type'        => 'string',
859 859
 					'format'      => 'uri',
860
-					'context'     => array( 'view', 'edit' ),
860
+					'context'     => array('view', 'edit'),
861 861
 					'readonly'    => true,
862 862
 				),
863 863
 				'sku'                   => array(
864
-					'description' => __( 'Unique identifier.', 'woocommerce' ),
864
+					'description' => __('Unique identifier.', 'woocommerce'),
865 865
 					'type'        => 'string',
866
-					'context'     => array( 'view', 'edit' ),
866
+					'context'     => array('view', 'edit'),
867 867
 				),
868 868
 				'price'                 => array(
869
-					'description' => __( 'Current variation price.', 'woocommerce' ),
869
+					'description' => __('Current variation price.', 'woocommerce'),
870 870
 					'type'        => 'string',
871
-					'context'     => array( 'view', 'edit' ),
871
+					'context'     => array('view', 'edit'),
872 872
 					'readonly'    => true,
873 873
 				),
874 874
 				'regular_price'         => array(
875
-					'description' => __( 'Variation regular price.', 'woocommerce' ),
875
+					'description' => __('Variation regular price.', 'woocommerce'),
876 876
 					'type'        => 'string',
877
-					'context'     => array( 'view', 'edit' ),
877
+					'context'     => array('view', 'edit'),
878 878
 				),
879 879
 				'sale_price'            => array(
880
-					'description' => __( 'Variation sale price.', 'woocommerce' ),
880
+					'description' => __('Variation sale price.', 'woocommerce'),
881 881
 					'type'        => 'string',
882
-					'context'     => array( 'view', 'edit' ),
882
+					'context'     => array('view', 'edit'),
883 883
 				),
884 884
 				'date_on_sale_from'     => array(
885
-					'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ),
885
+					'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'),
886 886
 					'type'        => 'date-time',
887
-					'context'     => array( 'view', 'edit' ),
887
+					'context'     => array('view', 'edit'),
888 888
 				),
889 889
 				'date_on_sale_from_gmt' => array(
890
-					'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ),
890
+					'description' => __('Start date of sale price, as GMT.', 'woocommerce'),
891 891
 					'type'        => 'date-time',
892
-					'context'     => array( 'view', 'edit' ),
892
+					'context'     => array('view', 'edit'),
893 893
 				),
894 894
 				'date_on_sale_to'       => array(
895
-					'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
895
+					'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'),
896 896
 					'type'        => 'date-time',
897
-					'context'     => array( 'view', 'edit' ),
897
+					'context'     => array('view', 'edit'),
898 898
 				),
899 899
 				'date_on_sale_to_gmt'   => array(
900
-					'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
900
+					'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'),
901 901
 					'type'        => 'date-time',
902
-					'context'     => array( 'view', 'edit' ),
902
+					'context'     => array('view', 'edit'),
903 903
 				),
904 904
 				'on_sale'               => array(
905
-					'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ),
905
+					'description' => __('Shows if the variation is on sale.', 'woocommerce'),
906 906
 					'type'        => 'boolean',
907
-					'context'     => array( 'view', 'edit' ),
907
+					'context'     => array('view', 'edit'),
908 908
 					'readonly'    => true,
909 909
 				),
910 910
 				'status'                => array(
911
-					'description' => __( 'Variation status.', 'woocommerce' ),
911
+					'description' => __('Variation status.', 'woocommerce'),
912 912
 					'type'        => 'string',
913 913
 					'default'     => 'publish',
914
-					'enum'        => array_keys( get_post_statuses() ),
915
-					'context'     => array( 'view', 'edit' ),
914
+					'enum'        => array_keys(get_post_statuses()),
915
+					'context'     => array('view', 'edit'),
916 916
 				),
917 917
 				'purchasable'           => array(
918
-					'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ),
918
+					'description' => __('Shows if the variation can be bought.', 'woocommerce'),
919 919
 					'type'        => 'boolean',
920
-					'context'     => array( 'view', 'edit' ),
920
+					'context'     => array('view', 'edit'),
921 921
 					'readonly'    => true,
922 922
 				),
923 923
 				'virtual'               => array(
924
-					'description' => __( 'If the variation is virtual.', 'woocommerce' ),
924
+					'description' => __('If the variation is virtual.', 'woocommerce'),
925 925
 					'type'        => 'boolean',
926 926
 					'default'     => false,
927
-					'context'     => array( 'view', 'edit' ),
927
+					'context'     => array('view', 'edit'),
928 928
 				),
929 929
 				'downloadable'          => array(
930
-					'description' => __( 'If the variation is downloadable.', 'woocommerce' ),
930
+					'description' => __('If the variation is downloadable.', 'woocommerce'),
931 931
 					'type'        => 'boolean',
932 932
 					'default'     => false,
933
-					'context'     => array( 'view', 'edit' ),
933
+					'context'     => array('view', 'edit'),
934 934
 				),
935 935
 				'downloads'             => array(
936
-					'description' => __( 'List of downloadable files.', 'woocommerce' ),
936
+					'description' => __('List of downloadable files.', 'woocommerce'),
937 937
 					'type'        => 'array',
938
-					'context'     => array( 'view', 'edit' ),
938
+					'context'     => array('view', 'edit'),
939 939
 					'items'       => array(
940 940
 						'type'       => 'object',
941 941
 						'properties' => array(
942 942
 							'id'   => array(
943
-								'description' => __( 'File ID.', 'woocommerce' ),
943
+								'description' => __('File ID.', 'woocommerce'),
944 944
 								'type'        => 'string',
945
-								'context'     => array( 'view', 'edit' ),
945
+								'context'     => array('view', 'edit'),
946 946
 							),
947 947
 							'name' => array(
948
-								'description' => __( 'File name.', 'woocommerce' ),
948
+								'description' => __('File name.', 'woocommerce'),
949 949
 								'type'        => 'string',
950
-								'context'     => array( 'view', 'edit' ),
950
+								'context'     => array('view', 'edit'),
951 951
 							),
952 952
 							'file' => array(
953
-								'description' => __( 'File URL.', 'woocommerce' ),
953
+								'description' => __('File URL.', 'woocommerce'),
954 954
 								'type'        => 'string',
955
-								'context'     => array( 'view', 'edit' ),
955
+								'context'     => array('view', 'edit'),
956 956
 							),
957 957
 						),
958 958
 					),
959 959
 				),
960 960
 				'download_limit'        => array(
961
-					'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ),
961
+					'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'),
962 962
 					'type'        => 'integer',
963 963
 					'default'     => -1,
964
-					'context'     => array( 'view', 'edit' ),
964
+					'context'     => array('view', 'edit'),
965 965
 				),
966 966
 				'download_expiry'       => array(
967
-					'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ),
967
+					'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'),
968 968
 					'type'        => 'integer',
969 969
 					'default'     => -1,
970
-					'context'     => array( 'view', 'edit' ),
970
+					'context'     => array('view', 'edit'),
971 971
 				),
972 972
 				'tax_status'            => array(
973
-					'description' => __( 'Tax status.', 'woocommerce' ),
973
+					'description' => __('Tax status.', 'woocommerce'),
974 974
 					'type'        => 'string',
975 975
 					'default'     => 'taxable',
976
-					'enum'        => array( 'taxable', 'shipping', 'none' ),
977
-					'context'     => array( 'view', 'edit' ),
976
+					'enum'        => array('taxable', 'shipping', 'none'),
977
+					'context'     => array('view', 'edit'),
978 978
 				),
979 979
 				'tax_class'             => array(
980
-					'description' => __( 'Tax class.', 'woocommerce' ),
980
+					'description' => __('Tax class.', 'woocommerce'),
981 981
 					'type'        => 'string',
982
-					'context'     => array( 'view', 'edit' ),
982
+					'context'     => array('view', 'edit'),
983 983
 				),
984 984
 				'manage_stock'          => array(
985
-					'description' => __( 'Stock management at variation level.', 'woocommerce' ),
985
+					'description' => __('Stock management at variation level.', 'woocommerce'),
986 986
 					'type'        => 'boolean',
987 987
 					'default'     => false,
988
-					'context'     => array( 'view', 'edit' ),
988
+					'context'     => array('view', 'edit'),
989 989
 				),
990 990
 				'stock_quantity'        => array(
991
-					'description' => __( 'Stock quantity.', 'woocommerce' ),
991
+					'description' => __('Stock quantity.', 'woocommerce'),
992 992
 					'type'        => 'integer',
993
-					'context'     => array( 'view', 'edit' ),
993
+					'context'     => array('view', 'edit'),
994 994
 				),
995 995
 				'stock_status'          => array(
996
-					'description' => __( 'Controls the stock status of the product.', 'woocommerce' ),
996
+					'description' => __('Controls the stock status of the product.', 'woocommerce'),
997 997
 					'type'        => 'string',
998 998
 					'default'     => 'instock',
999
-					'enum'        => array_keys( wc_get_product_stock_status_options() ),
1000
-					'context'     => array( 'view', 'edit' ),
999
+					'enum'        => array_keys(wc_get_product_stock_status_options()),
1000
+					'context'     => array('view', 'edit'),
1001 1001
 				),
1002 1002
 				'backorders'            => array(
1003
-					'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ),
1003
+					'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'),
1004 1004
 					'type'        => 'string',
1005 1005
 					'default'     => 'no',
1006
-					'enum'        => array( 'no', 'notify', 'yes' ),
1007
-					'context'     => array( 'view', 'edit' ),
1006
+					'enum'        => array('no', 'notify', 'yes'),
1007
+					'context'     => array('view', 'edit'),
1008 1008
 				),
1009 1009
 				'backorders_allowed'    => array(
1010
-					'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ),
1010
+					'description' => __('Shows if backorders are allowed.', 'woocommerce'),
1011 1011
 					'type'        => 'boolean',
1012
-					'context'     => array( 'view', 'edit' ),
1012
+					'context'     => array('view', 'edit'),
1013 1013
 					'readonly'    => true,
1014 1014
 				),
1015 1015
 				'backordered'           => array(
1016
-					'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ),
1016
+					'description' => __('Shows if the variation is on backordered.', 'woocommerce'),
1017 1017
 					'type'        => 'boolean',
1018
-					'context'     => array( 'view', 'edit' ),
1018
+					'context'     => array('view', 'edit'),
1019 1019
 					'readonly'    => true,
1020 1020
 				),
1021 1021
 				'weight'                => array(
1022 1022
 					/* translators: %s: weight unit */
1023
-					'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ),
1023
+					'description' => sprintf(__('Variation weight (%s).', 'woocommerce'), $weight_unit),
1024 1024
 					'type'        => 'string',
1025
-					'context'     => array( 'view', 'edit' ),
1025
+					'context'     => array('view', 'edit'),
1026 1026
 				),
1027 1027
 				'dimensions'            => array(
1028
-					'description' => __( 'Variation dimensions.', 'woocommerce' ),
1028
+					'description' => __('Variation dimensions.', 'woocommerce'),
1029 1029
 					'type'        => 'object',
1030
-					'context'     => array( 'view', 'edit' ),
1030
+					'context'     => array('view', 'edit'),
1031 1031
 					'properties'  => array(
1032 1032
 						'length' => array(
1033 1033
 							/* translators: %s: dimension unit */
1034
-							'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ),
1034
+							'description' => sprintf(__('Variation length (%s).', 'woocommerce'), $dimension_unit),
1035 1035
 							'type'        => 'string',
1036
-							'context'     => array( 'view', 'edit' ),
1036
+							'context'     => array('view', 'edit'),
1037 1037
 						),
1038 1038
 						'width'  => array(
1039 1039
 							/* translators: %s: dimension unit */
1040
-							'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ),
1040
+							'description' => sprintf(__('Variation width (%s).', 'woocommerce'), $dimension_unit),
1041 1041
 							'type'        => 'string',
1042
-							'context'     => array( 'view', 'edit' ),
1042
+							'context'     => array('view', 'edit'),
1043 1043
 						),
1044 1044
 						'height' => array(
1045 1045
 							/* translators: %s: dimension unit */
1046
-							'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ),
1046
+							'description' => sprintf(__('Variation height (%s).', 'woocommerce'), $dimension_unit),
1047 1047
 							'type'        => 'string',
1048
-							'context'     => array( 'view', 'edit' ),
1048
+							'context'     => array('view', 'edit'),
1049 1049
 						),
1050 1050
 					),
1051 1051
 				),
1052 1052
 				'shipping_class'        => array(
1053
-					'description' => __( 'Shipping class slug.', 'woocommerce' ),
1053
+					'description' => __('Shipping class slug.', 'woocommerce'),
1054 1054
 					'type'        => 'string',
1055
-					'context'     => array( 'view', 'edit' ),
1055
+					'context'     => array('view', 'edit'),
1056 1056
 				),
1057 1057
 				'shipping_class_id'     => array(
1058
-					'description' => __( 'Shipping class ID.', 'woocommerce' ),
1058
+					'description' => __('Shipping class ID.', 'woocommerce'),
1059 1059
 					'type'        => 'string',
1060
-					'context'     => array( 'view', 'edit' ),
1060
+					'context'     => array('view', 'edit'),
1061 1061
 					'readonly'    => true,
1062 1062
 				),
1063 1063
 				'image'                 => array(
1064
-					'description' => __( 'Variation image data.', 'woocommerce' ),
1064
+					'description' => __('Variation image data.', 'woocommerce'),
1065 1065
 					'type'        => 'object',
1066
-					'context'     => array( 'view', 'edit' ),
1066
+					'context'     => array('view', 'edit'),
1067 1067
 					'properties'  => array(
1068 1068
 						'id'                => array(
1069
-							'description' => __( 'Image ID.', 'woocommerce' ),
1069
+							'description' => __('Image ID.', 'woocommerce'),
1070 1070
 							'type'        => 'integer',
1071
-							'context'     => array( 'view', 'edit' ),
1071
+							'context'     => array('view', 'edit'),
1072 1072
 						),
1073 1073
 						'date_created'      => array(
1074
-							'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
1074
+							'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'),
1075 1075
 							'type'        => 'date-time',
1076
-							'context'     => array( 'view', 'edit' ),
1076
+							'context'     => array('view', 'edit'),
1077 1077
 							'readonly'    => true,
1078 1078
 						),
1079 1079
 						'date_created_gmt'  => array(
1080
-							'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
1080
+							'description' => __('The date the image was created, as GMT.', 'woocommerce'),
1081 1081
 							'type'        => 'date-time',
1082
-							'context'     => array( 'view', 'edit' ),
1082
+							'context'     => array('view', 'edit'),
1083 1083
 							'readonly'    => true,
1084 1084
 						),
1085 1085
 						'date_modified'     => array(
1086
-							'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
1086
+							'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'),
1087 1087
 							'type'        => 'date-time',
1088
-							'context'     => array( 'view', 'edit' ),
1088
+							'context'     => array('view', 'edit'),
1089 1089
 							'readonly'    => true,
1090 1090
 						),
1091 1091
 						'date_modified_gmt' => array(
1092
-							'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
1092
+							'description' => __('The date the image was last modified, as GMT.', 'woocommerce'),
1093 1093
 							'type'        => 'date-time',
1094
-							'context'     => array( 'view', 'edit' ),
1094
+							'context'     => array('view', 'edit'),
1095 1095
 							'readonly'    => true,
1096 1096
 						),
1097 1097
 						'src'               => array(
1098
-							'description' => __( 'Image URL.', 'woocommerce' ),
1098
+							'description' => __('Image URL.', 'woocommerce'),
1099 1099
 							'type'        => 'string',
1100 1100
 							'format'      => 'uri',
1101
-							'context'     => array( 'view', 'edit' ),
1101
+							'context'     => array('view', 'edit'),
1102 1102
 						),
1103 1103
 						'name'              => array(
1104
-							'description' => __( 'Image name.', 'woocommerce' ),
1104
+							'description' => __('Image name.', 'woocommerce'),
1105 1105
 							'type'        => 'string',
1106
-							'context'     => array( 'view', 'edit' ),
1106
+							'context'     => array('view', 'edit'),
1107 1107
 						),
1108 1108
 						'alt'               => array(
1109
-							'description' => __( 'Image alternative text.', 'woocommerce' ),
1109
+							'description' => __('Image alternative text.', 'woocommerce'),
1110 1110
 							'type'        => 'string',
1111
-							'context'     => array( 'view', 'edit' ),
1111
+							'context'     => array('view', 'edit'),
1112 1112
 						),
1113 1113
 					),
1114 1114
 				),
1115 1115
 				'attributes'            => array(
1116
-					'description' => __( 'List of attributes.', 'woocommerce' ),
1116
+					'description' => __('List of attributes.', 'woocommerce'),
1117 1117
 					'type'        => 'array',
1118
-					'context'     => array( 'view', 'edit' ),
1118
+					'context'     => array('view', 'edit'),
1119 1119
 					'items'       => array(
1120 1120
 						'type'       => 'object',
1121 1121
 						'properties' => array(
1122 1122
 							'id'     => array(
1123
-								'description' => __( 'Attribute ID.', 'woocommerce' ),
1123
+								'description' => __('Attribute ID.', 'woocommerce'),
1124 1124
 								'type'        => 'integer',
1125
-								'context'     => array( 'view', 'edit' ),
1125
+								'context'     => array('view', 'edit'),
1126 1126
 							),
1127 1127
 							'name'   => array(
1128
-								'description' => __( 'Attribute name.', 'woocommerce' ),
1128
+								'description' => __('Attribute name.', 'woocommerce'),
1129 1129
 								'type'        => 'string',
1130
-								'context'     => array( 'view', 'edit' ),
1130
+								'context'     => array('view', 'edit'),
1131 1131
 							),
1132 1132
 							'option' => array(
1133
-								'description' => __( 'Selected attribute term name.', 'woocommerce' ),
1133
+								'description' => __('Selected attribute term name.', 'woocommerce'),
1134 1134
 								'type'        => 'string',
1135
-								'context'     => array( 'view', 'edit' ),
1135
+								'context'     => array('view', 'edit'),
1136 1136
 							),
1137 1137
 						),
1138 1138
 					),
1139 1139
 				),
1140 1140
 				'menu_order'            => array(
1141
-					'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ),
1141
+					'description' => __('Menu order, used to custom sort products.', 'woocommerce'),
1142 1142
 					'type'        => 'integer',
1143
-					'context'     => array( 'view', 'edit' ),
1143
+					'context'     => array('view', 'edit'),
1144 1144
 				),
1145 1145
 				'meta_data'             => array(
1146
-					'description' => __( 'Meta data.', 'woocommerce' ),
1146
+					'description' => __('Meta data.', 'woocommerce'),
1147 1147
 					'type'        => 'array',
1148
-					'context'     => array( 'view', 'edit' ),
1148
+					'context'     => array('view', 'edit'),
1149 1149
 					'items'       => array(
1150 1150
 						'type'       => 'object',
1151 1151
 						'properties' => array(
1152 1152
 							'id'    => array(
1153
-								'description' => __( 'Meta ID.', 'woocommerce' ),
1153
+								'description' => __('Meta ID.', 'woocommerce'),
1154 1154
 								'type'        => 'integer',
1155
-								'context'     => array( 'view', 'edit' ),
1155
+								'context'     => array('view', 'edit'),
1156 1156
 								'readonly'    => true,
1157 1157
 							),
1158 1158
 							'key'   => array(
1159
-								'description' => __( 'Meta key.', 'woocommerce' ),
1159
+								'description' => __('Meta key.', 'woocommerce'),
1160 1160
 								'type'        => 'string',
1161
-								'context'     => array( 'view', 'edit' ),
1161
+								'context'     => array('view', 'edit'),
1162 1162
 							),
1163 1163
 							'value' => array(
1164
-								'description' => __( 'Meta value.', 'woocommerce' ),
1164
+								'description' => __('Meta value.', 'woocommerce'),
1165 1165
 								'type'        => 'mixed',
1166
-								'context'     => array( 'view', 'edit' ),
1166
+								'context'     => array('view', 'edit'),
1167 1167
 							),
1168 1168
 						),
1169 1169
 					),
1170 1170
 				),
1171 1171
 			),
1172 1172
 		);
1173
-		return $this->add_additional_fields_schema( $schema );
1173
+		return $this->add_additional_fields_schema($schema);
1174 1174
 	}
1175 1175
 
1176 1176
 	/**
@@ -1193,15 +1193,15 @@  discard block
 block discarded – undo
1193 1193
 		);
1194 1194
 
1195 1195
 		$params['stock_status'] = array(
1196
-			'description'       => __( 'Limit result set to products with specified stock status.', 'woocommerce' ),
1196
+			'description'       => __('Limit result set to products with specified stock status.', 'woocommerce'),
1197 1197
 			'type'              => 'string',
1198
-			'enum'              => array_keys( wc_get_product_stock_status_options() ),
1198
+			'enum'              => array_keys(wc_get_product_stock_status_options()),
1199 1199
 			'sanitize_callback' => 'sanitize_text_field',
1200 1200
 			'validate_callback' => 'rest_validate_request_arg',
1201 1201
 		);
1202 1202
 
1203 1203
 		$params['search'] = array(
1204
-			'description'       => __( 'Search by similar product name or sku.', 'woocommerce' ),
1204
+			'description'       => __('Search by similar product name or sku.', 'woocommerce'),
1205 1205
 			'type'              => 'string',
1206 1206
 			'validate_callback' => 'rest_validate_request_arg',
1207 1207
 		);
@@ -1215,14 +1215,14 @@  discard block
 block discarded – undo
1215 1215
 	 * @param \WP_REST_Request $request Full details about the request.
1216 1216
 	 * @return \WP_Error\WP_REST_Response
1217 1217
 	 */
1218
-	public function get_items( $request ) {
1219
-		add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 );
1220
-		add_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10, 2 );
1221
-		add_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10, 2 );
1222
-		$response = parent::get_items( $request );
1223
-		remove_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10 );
1224
-		remove_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10 );
1225
-		remove_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10 );
1218
+	public function get_items($request) {
1219
+		add_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10, 2);
1220
+		add_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10, 2);
1221
+		add_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10, 2);
1222
+		$response = parent::get_items($request);
1223
+		remove_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10);
1224
+		remove_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10);
1225
+		remove_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10);
1226 1226
 		return $response;
1227 1227
 	}
1228 1228
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/CustomerDownloads.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Customer Downloads controller class.
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
33 33
 			array(
34 34
 				'args' => array(
35 35
 					'customer_id' => array(
36
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
36
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
37 37
 						'type'        => 'integer',
38 38
 					),
39 39
 				),
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
 					'args'                => $this->get_collection_params(),
45 45
 				),
46
-				'schema' => array( $this, 'get_public_item_schema' ),
46
+				'schema' => array($this, 'get_public_item_schema'),
47 47
 			),
48 48
 			true
49 49
 		);
@@ -55,15 +55,15 @@  discard block
 block discarded – undo
55 55
 	 * @param  \WP_REST_Request $request Full details about the request.
56 56
 	 * @return \WP_Error|boolean
57 57
 	 */
58
-	public function get_items_permissions_check( $request ) {
59
-		$customer = get_user_by( 'id', (int) $request['customer_id'] );
58
+	public function get_items_permissions_check($request) {
59
+		$customer = get_user_by('id', (int) $request['customer_id']);
60 60
 
61
-		if ( ! $customer ) {
62
-			return new \WP_Error( 'woocommerce_rest_customer_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
61
+		if ( ! $customer) {
62
+			return new \WP_Error('woocommerce_rest_customer_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
63 63
 		}
64 64
 
65
-		if ( ! wc_rest_check_user_permissions( 'read', $customer->get_id() ) ) {
66
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
65
+		if ( ! wc_rest_check_user_permissions('read', $customer->get_id())) {
66
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
67 67
 		}
68 68
 
69 69
 		return true;
@@ -75,17 +75,17 @@  discard block
 block discarded – undo
75 75
 	 * @param \WP_REST_Request $request Request params.
76 76
 	 * @return array
77 77
 	 */
78
-	public function get_items( $request ) {
79
-		$downloads = wc_get_customer_available_downloads( (int) $request['customer_id'] );
78
+	public function get_items($request) {
79
+		$downloads = wc_get_customer_available_downloads((int) $request['customer_id']);
80 80
 
81 81
 		$data = array();
82
-		foreach ( $downloads as $download_data ) {
83
-			$download = $this->prepare_item_for_response( (object) $download_data, $request );
84
-			$download = $this->prepare_response_for_collection( $download );
82
+		foreach ($downloads as $download_data) {
83
+			$download = $this->prepare_item_for_response((object) $download_data, $request);
84
+			$download = $this->prepare_response_for_collection($download);
85 85
 			$data[]   = $download;
86 86
 		}
87 87
 
88
-		return rest_ensure_response( $data );
88
+		return rest_ensure_response($data);
89 89
 	}
90 90
 
91 91
 	/**
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * @param \WP_REST_Request $request Request object.
96 96
 	 * @return \WP_REST_Response $response Response data.
97 97
 	 */
98
-	public function prepare_item_for_response( $download, $request ) {
98
+	public function prepare_item_for_response($download, $request) {
99 99
 		$data = array(
100 100
 			'download_id'         => $download->download_id,
101 101
 			'download_url'        => $download->download_url,
@@ -105,19 +105,19 @@  discard block
 block discarded – undo
105 105
 			'order_id'            => $download->order_id,
106 106
 			'order_key'           => $download->order_key,
107 107
 			'downloads_remaining' => '' === $download->downloads_remaining ? 'unlimited' : $download->downloads_remaining,
108
-			'access_expires'      => $download->access_expires ? wc_rest_prepare_date_response( $download->access_expires ) : 'never',
109
-			'access_expires_gmt'  => $download->access_expires ? wc_rest_prepare_date_response( get_gmt_from_date( $download->access_expires ) ) : 'never',
108
+			'access_expires'      => $download->access_expires ? wc_rest_prepare_date_response($download->access_expires) : 'never',
109
+			'access_expires_gmt'  => $download->access_expires ? wc_rest_prepare_date_response(get_gmt_from_date($download->access_expires)) : 'never',
110 110
 			'file'                => $download->file,
111 111
 		);
112 112
 
113
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
114
-		$data    = $this->add_additional_fields_to_object( $data, $request );
115
-		$data    = $this->filter_response_by_context( $data, $context );
113
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
114
+		$data    = $this->add_additional_fields_to_object($data, $request);
115
+		$data    = $this->filter_response_by_context($data, $context);
116 116
 
117 117
 		// Wrap the data in a response object.
118
-		$response = rest_ensure_response( $data );
118
+		$response = rest_ensure_response($data);
119 119
 
120
-		$response->add_links( $this->prepare_links( $download, $request ) );
120
+		$response->add_links($this->prepare_links($download, $request));
121 121
 
122 122
 		/**
123 123
 		 * Filter customer download data returned from the REST API.
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * @param stdClass         $download  Download object used to create response.
127 127
 		 * @param \WP_REST_Request  $request   Request object.
128 128
 		 */
129
-		return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request );
129
+		return apply_filters('woocommerce_rest_prepare_customer_download', $response, $download, $request);
130 130
 	}
131 131
 
132 132
 	/**
@@ -136,17 +136,17 @@  discard block
 block discarded – undo
136 136
 	 * @param \WP_REST_Request $request Request object.
137 137
 	 * @return array Links for the given customer download.
138 138
 	 */
139
-	protected function prepare_links( $download, $request ) {
140
-		$base  = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base );
139
+	protected function prepare_links($download, $request) {
140
+		$base  = str_replace('(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base);
141 141
 		$links = array(
142 142
 			'collection' => array(
143
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
143
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)),
144 144
 			),
145 145
 			'product' => array(
146
-				'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $download->product_id ) ),
146
+				'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $download->product_id)),
147 147
 			),
148 148
 			'order' => array(
149
-				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $download->order_id ) ),
149
+				'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $download->order_id)),
150 150
 			),
151 151
 		);
152 152
 
@@ -165,81 +165,81 @@  discard block
 block discarded – undo
165 165
 			'type'       => 'object',
166 166
 			'properties' => array(
167 167
 				'download_id'         => array(
168
-					'description' => __( 'Download ID.', 'woocommerce' ),
168
+					'description' => __('Download ID.', 'woocommerce'),
169 169
 					'type'        => 'string',
170
-					'context'     => array( 'view' ),
170
+					'context'     => array('view'),
171 171
 					'readonly'    => true,
172 172
 				),
173 173
 				'download_url'        => array(
174
-					'description' => __( 'Download file URL.', 'woocommerce' ),
174
+					'description' => __('Download file URL.', 'woocommerce'),
175 175
 					'type'        => 'string',
176
-					'context'     => array( 'view' ),
176
+					'context'     => array('view'),
177 177
 					'readonly'    => true,
178 178
 				),
179 179
 				'product_id'          => array(
180
-					'description' => __( 'Downloadable product ID.', 'woocommerce' ),
180
+					'description' => __('Downloadable product ID.', 'woocommerce'),
181 181
 					'type'        => 'integer',
182
-					'context'     => array( 'view' ),
182
+					'context'     => array('view'),
183 183
 					'readonly'    => true,
184 184
 				),
185 185
 				'product_name'        => array(
186
-					'description' => __( 'Product name.', 'woocommerce' ),
186
+					'description' => __('Product name.', 'woocommerce'),
187 187
 					'type'        => 'string',
188
-					'context'     => array( 'view' ),
188
+					'context'     => array('view'),
189 189
 					'readonly'    => true,
190 190
 				),
191 191
 				'download_name'       => array(
192
-					'description' => __( 'Downloadable file name.', 'woocommerce' ),
192
+					'description' => __('Downloadable file name.', 'woocommerce'),
193 193
 					'type'        => 'string',
194
-					'context'     => array( 'view' ),
194
+					'context'     => array('view'),
195 195
 					'readonly'    => true,
196 196
 				),
197 197
 				'order_id'            => array(
198
-					'description' => __( 'Order ID.', 'woocommerce' ),
198
+					'description' => __('Order ID.', 'woocommerce'),
199 199
 					'type'        => 'integer',
200
-					'context'     => array( 'view' ),
200
+					'context'     => array('view'),
201 201
 					'readonly'    => true,
202 202
 				),
203 203
 				'order_key'           => array(
204
-					'description' => __( 'Order key.', 'woocommerce' ),
204
+					'description' => __('Order key.', 'woocommerce'),
205 205
 					'type'        => 'string',
206
-					'context'     => array( 'view' ),
206
+					'context'     => array('view'),
207 207
 					'readonly'    => true,
208 208
 				),
209 209
 				'downloads_remaining' => array(
210
-					'description' => __( 'Number of downloads remaining.', 'woocommerce' ),
210
+					'description' => __('Number of downloads remaining.', 'woocommerce'),
211 211
 					'type'        => 'string',
212
-					'context'     => array( 'view' ),
212
+					'context'     => array('view'),
213 213
 					'readonly'    => true,
214 214
 				),
215 215
 				'access_expires'      => array(
216
-					'description' => __( "The date when download access expires, in the site's timezone.", 'woocommerce' ),
216
+					'description' => __("The date when download access expires, in the site's timezone.", 'woocommerce'),
217 217
 					'type'        => 'string',
218
-					'context'     => array( 'view' ),
218
+					'context'     => array('view'),
219 219
 					'readonly'    => true,
220 220
 				),
221 221
 				'access_expires_gmt'  => array(
222
-					'description' => __( 'The date when download access expires, as GMT.', 'woocommerce' ),
222
+					'description' => __('The date when download access expires, as GMT.', 'woocommerce'),
223 223
 					'type'        => 'string',
224
-					'context'     => array( 'view' ),
224
+					'context'     => array('view'),
225 225
 					'readonly'    => true,
226 226
 				),
227 227
 				'file'                => array(
228
-					'description' => __( 'File details.', 'woocommerce' ),
228
+					'description' => __('File details.', 'woocommerce'),
229 229
 					'type'        => 'object',
230
-					'context'     => array( 'view' ),
230
+					'context'     => array('view'),
231 231
 					'readonly'    => true,
232 232
 					'properties'  => array(
233 233
 						'name' => array(
234
-							'description' => __( 'File name.', 'woocommerce' ),
234
+							'description' => __('File name.', 'woocommerce'),
235 235
 							'type'        => 'string',
236
-							'context'     => array( 'view' ),
236
+							'context'     => array('view'),
237 237
 							'readonly'    => true,
238 238
 						),
239 239
 						'file' => array(
240
-							'description' => __( 'File URL.', 'woocommerce' ),
240
+							'description' => __('File URL.', 'woocommerce'),
241 241
 							'type'        => 'string',
242
-							'context'     => array( 'view' ),
242
+							'context'     => array('view'),
243 243
 							'readonly'    => true,
244 244
 						),
245 245
 					),
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 			),
248 248
 		);
249 249
 
250
-		return $this->add_additional_fields_schema( $schema );
250
+		return $this->add_additional_fields_schema($schema);
251 251
 	}
252 252
 
253 253
 	/**
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	 */
258 258
 	public function get_collection_params() {
259 259
 		return array(
260
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
260
+			'context' => $this->get_context_param(array('default' => 'view')),
261 261
 		);
262 262
 	}
263 263
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/ProductCategories.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Product Categories controller class.
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 	 * @param \WP_REST_Request $request Request instance.
38 38
 	 * @return \WP_REST_Response
39 39
 	 */
40
-	public function prepare_item_for_response( $item, $request ) {
40
+	public function prepare_item_for_response($item, $request) {
41 41
 		// Get category display type.
42
-		$display_type = get_term_meta( $item->term_id, 'display_type', true );
42
+		$display_type = get_term_meta($item->term_id, 'display_type', true);
43 43
 
44 44
 		// Get category order.
45
-		$menu_order = get_term_meta( $item->term_id, 'order', true );
45
+		$menu_order = get_term_meta($item->term_id, 'order', true);
46 46
 
47 47
 		$data = array(
48 48
 			'id'          => (int) $item->term_id,
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 		);
58 58
 
59 59
 		// Get category image.
60
-		$image_id = get_term_meta( $item->term_id, 'thumbnail_id', true );
61
-		if ( $image_id ) {
62
-			$attachment = get_post( $image_id );
60
+		$image_id = get_term_meta($item->term_id, 'thumbnail_id', true);
61
+		if ($image_id) {
62
+			$attachment = get_post($image_id);
63 63
 
64 64
 			$data['image'] = array(
65 65
 				'id'                => (int) $image_id,
66
-				'date_created'      => wc_rest_prepare_date_response( $attachment->post_date ),
67
-				'date_created_gmt'  => wc_rest_prepare_date_response( $attachment->post_date_gmt ),
68
-				'date_modified'     => wc_rest_prepare_date_response( $attachment->post_modified ),
69
-				'date_modified_gmt' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ),
70
-				'src'               => wp_get_attachment_url( $image_id ),
71
-				'name'              => get_the_title( $attachment ),
72
-				'alt'               => get_post_meta( $image_id, '_wp_attachment_image_alt', true ),
66
+				'date_created'      => wc_rest_prepare_date_response($attachment->post_date),
67
+				'date_created_gmt'  => wc_rest_prepare_date_response($attachment->post_date_gmt),
68
+				'date_modified'     => wc_rest_prepare_date_response($attachment->post_modified),
69
+				'date_modified_gmt' => wc_rest_prepare_date_response($attachment->post_modified_gmt),
70
+				'src'               => wp_get_attachment_url($image_id),
71
+				'name'              => get_the_title($attachment),
72
+				'alt'               => get_post_meta($image_id, '_wp_attachment_image_alt', true),
73 73
 			);
74 74
 		}
75 75
 
76
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
77
-		$data    = $this->add_additional_fields_to_object( $data, $request );
78
-		$data    = $this->filter_response_by_context( $data, $context );
76
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
77
+		$data    = $this->add_additional_fields_to_object($data, $request);
78
+		$data    = $this->filter_response_by_context($data, $context);
79 79
 
80
-		$response = rest_ensure_response( $data );
80
+		$response = rest_ensure_response($data);
81 81
 
82
-		$response->add_links( $this->prepare_links( $item, $request ) );
82
+		$response->add_links($this->prepare_links($item, $request));
83 83
 
84 84
 		/**
85 85
 		 * Filter a term item returned from the API.
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		 * @param object            $item      The original term object.
91 91
 		 * @param \WP_REST_Request   $request   Request used to generate the response.
92 92
 		 */
93
-		return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request );
93
+		return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
94 94
 	}
95 95
 
96 96
 	/**
@@ -102,50 +102,50 @@  discard block
 block discarded – undo
102 102
 	 *
103 103
 	 * @since 3.5.5
104 104
 	 */
105
-	protected function update_term_meta_fields( $term, $request ) {
105
+	protected function update_term_meta_fields($term, $request) {
106 106
 		$id = (int) $term->term_id;
107 107
 
108
-		if ( isset( $request['display'] ) ) {
109
-			update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] );
108
+		if (isset($request['display'])) {
109
+			update_term_meta($id, 'display_type', 'default' === $request['display'] ? '' : $request['display']);
110 110
 		}
111 111
 
112
-		if ( isset( $request['menu_order'] ) ) {
113
-			update_term_meta( $id, 'order', $request['menu_order'] );
112
+		if (isset($request['menu_order'])) {
113
+			update_term_meta($id, 'order', $request['menu_order']);
114 114
 		}
115 115
 
116
-		if ( isset( $request['image'] ) ) {
117
-			if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) {
118
-				$upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) );
116
+		if (isset($request['image'])) {
117
+			if (empty($request['image']['id']) && ! empty($request['image']['src'])) {
118
+				$upload = wc_rest_upload_image_from_url(esc_url_raw($request['image']['src']));
119 119
 
120
-				if ( is_wp_error( $upload ) ) {
120
+				if (is_wp_error($upload)) {
121 121
 					return $upload;
122 122
 				}
123 123
 
124
-				$image_id = wc_rest_set_uploaded_image_as_attachment( $upload );
124
+				$image_id = wc_rest_set_uploaded_image_as_attachment($upload);
125 125
 			} else {
126
-				$image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0;
126
+				$image_id = isset($request['image']['id']) ? absint($request['image']['id']) : 0;
127 127
 			}
128 128
 
129 129
 			// Check if image_id is a valid image attachment before updating the term meta.
130
-			if ( $image_id && wp_attachment_is_image( $image_id ) ) {
131
-				update_term_meta( $id, 'thumbnail_id', $image_id );
130
+			if ($image_id && wp_attachment_is_image($image_id)) {
131
+				update_term_meta($id, 'thumbnail_id', $image_id);
132 132
 
133 133
 				// Set the image alt.
134
-				if ( ! empty( $request['image']['alt'] ) ) {
135
-					update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) );
134
+				if ( ! empty($request['image']['alt'])) {
135
+					update_post_meta($image_id, '_wp_attachment_image_alt', wc_clean($request['image']['alt']));
136 136
 				}
137 137
 
138 138
 				// Set the image title.
139
-				if ( ! empty( $request['image']['name'] ) ) {
139
+				if ( ! empty($request['image']['name'])) {
140 140
 					wp_update_post(
141 141
 						array(
142 142
 							'ID'         => $image_id,
143
-							'post_title' => wc_clean( $request['image']['name'] ),
143
+							'post_title' => wc_clean($request['image']['name']),
144 144
 						)
145 145
 					);
146 146
 				}
147 147
 			} else {
148
-				delete_term_meta( $id, 'thumbnail_id' );
148
+				delete_term_meta($id, 'thumbnail_id');
149 149
 			}
150 150
 		}
151 151
 
@@ -164,113 +164,113 @@  discard block
 block discarded – undo
164 164
 			'type'       => 'object',
165 165
 			'properties' => array(
166 166
 				'id'          => array(
167
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
167
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
168 168
 					'type'        => 'integer',
169
-					'context'     => array( 'view', 'edit' ),
169
+					'context'     => array('view', 'edit'),
170 170
 					'readonly'    => true,
171 171
 				),
172 172
 				'name'        => array(
173
-					'description' => __( 'Category name.', 'woocommerce' ),
173
+					'description' => __('Category name.', 'woocommerce'),
174 174
 					'type'        => 'string',
175
-					'context'     => array( 'view', 'edit' ),
175
+					'context'     => array('view', 'edit'),
176 176
 					'arg_options' => array(
177 177
 						'sanitize_callback' => 'sanitize_text_field',
178 178
 					),
179 179
 				),
180 180
 				'slug'        => array(
181
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
181
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
182 182
 					'type'        => 'string',
183
-					'context'     => array( 'view', 'edit' ),
183
+					'context'     => array('view', 'edit'),
184 184
 					'arg_options' => array(
185 185
 						'sanitize_callback' => 'sanitize_title',
186 186
 					),
187 187
 				),
188 188
 				'parent'      => array(
189
-					'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ),
189
+					'description' => __('The ID for the parent of the resource.', 'woocommerce'),
190 190
 					'type'        => 'integer',
191
-					'context'     => array( 'view', 'edit' ),
191
+					'context'     => array('view', 'edit'),
192 192
 				),
193 193
 				'description' => array(
194
-					'description' => __( 'HTML description of the resource.', 'woocommerce' ),
194
+					'description' => __('HTML description of the resource.', 'woocommerce'),
195 195
 					'type'        => 'string',
196
-					'context'     => array( 'view', 'edit' ),
196
+					'context'     => array('view', 'edit'),
197 197
 					'arg_options' => array(
198 198
 						'sanitize_callback' => 'wp_filter_post_kses',
199 199
 					),
200 200
 				),
201 201
 				'display'     => array(
202
-					'description' => __( 'Category archive display type.', 'woocommerce' ),
202
+					'description' => __('Category archive display type.', 'woocommerce'),
203 203
 					'type'        => 'string',
204 204
 					'default'     => 'default',
205
-					'enum'        => array( 'default', 'products', 'subcategories', 'both' ),
206
-					'context'     => array( 'view', 'edit' ),
205
+					'enum'        => array('default', 'products', 'subcategories', 'both'),
206
+					'context'     => array('view', 'edit'),
207 207
 				),
208 208
 				'image'       => array(
209
-					'description' => __( 'Image data.', 'woocommerce' ),
209
+					'description' => __('Image data.', 'woocommerce'),
210 210
 					'type'        => 'object',
211
-					'context'     => array( 'view', 'edit' ),
211
+					'context'     => array('view', 'edit'),
212 212
 					'properties'  => array(
213 213
 						'id'                => array(
214
-							'description' => __( 'Image ID.', 'woocommerce' ),
214
+							'description' => __('Image ID.', 'woocommerce'),
215 215
 							'type'        => 'integer',
216
-							'context'     => array( 'view', 'edit' ),
216
+							'context'     => array('view', 'edit'),
217 217
 						),
218 218
 						'date_created'      => array(
219
-							'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
219
+							'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'),
220 220
 							'type'        => 'date-time',
221
-							'context'     => array( 'view', 'edit' ),
221
+							'context'     => array('view', 'edit'),
222 222
 							'readonly'    => true,
223 223
 						),
224 224
 						'date_created_gmt'  => array(
225
-							'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
225
+							'description' => __('The date the image was created, as GMT.', 'woocommerce'),
226 226
 							'type'        => 'date-time',
227
-							'context'     => array( 'view', 'edit' ),
227
+							'context'     => array('view', 'edit'),
228 228
 							'readonly'    => true,
229 229
 						),
230 230
 						'date_modified'     => array(
231
-							'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
231
+							'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'),
232 232
 							'type'        => 'date-time',
233
-							'context'     => array( 'view', 'edit' ),
233
+							'context'     => array('view', 'edit'),
234 234
 							'readonly'    => true,
235 235
 						),
236 236
 						'date_modified_gmt' => array(
237
-							'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
237
+							'description' => __('The date the image was last modified, as GMT.', 'woocommerce'),
238 238
 							'type'        => 'date-time',
239
-							'context'     => array( 'view', 'edit' ),
239
+							'context'     => array('view', 'edit'),
240 240
 							'readonly'    => true,
241 241
 						),
242 242
 						'src'               => array(
243
-							'description' => __( 'Image URL.', 'woocommerce' ),
243
+							'description' => __('Image URL.', 'woocommerce'),
244 244
 							'type'        => 'string',
245 245
 							'format'      => 'uri',
246
-							'context'     => array( 'view', 'edit' ),
246
+							'context'     => array('view', 'edit'),
247 247
 						),
248 248
 						'name'              => array(
249
-							'description' => __( 'Image name.', 'woocommerce' ),
249
+							'description' => __('Image name.', 'woocommerce'),
250 250
 							'type'        => 'string',
251
-							'context'     => array( 'view', 'edit' ),
251
+							'context'     => array('view', 'edit'),
252 252
 						),
253 253
 						'alt'               => array(
254
-							'description' => __( 'Image alternative text.', 'woocommerce' ),
254
+							'description' => __('Image alternative text.', 'woocommerce'),
255 255
 							'type'        => 'string',
256
-							'context'     => array( 'view', 'edit' ),
256
+							'context'     => array('view', 'edit'),
257 257
 						),
258 258
 					),
259 259
 				),
260 260
 				'menu_order'  => array(
261
-					'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ),
261
+					'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'),
262 262
 					'type'        => 'integer',
263
-					'context'     => array( 'view', 'edit' ),
263
+					'context'     => array('view', 'edit'),
264 264
 				),
265 265
 				'count'       => array(
266
-					'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
266
+					'description' => __('Number of published products for the resource.', 'woocommerce'),
267 267
 					'type'        => 'integer',
268
-					'context'     => array( 'view', 'edit' ),
268
+					'context'     => array('view', 'edit'),
269 269
 					'readonly'    => true,
270 270
 				),
271 271
 			),
272 272
 		);
273 273
 
274
-		return $this->add_additional_fields_schema( $schema );
274
+		return $this->add_additional_fields_schema($schema);
275 275
 	}
276 276
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Data/DownloadIPs.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Data as DataController;
15 15
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 			array(
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::READABLE,
40
-					'callback'            => array( $this, 'get_items' ),
41
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
+					'callback'            => array($this, 'get_items'),
41
+					'permission_callback' => array($this, 'get_items_permissions_check'),
42 42
 				),
43
-				'schema' => array( $this, 'get_public_item_schema' ),
43
+				'schema' => array($this, 'get_public_item_schema'),
44 44
 			)
45 45
 		);
46 46
 	}
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
 	 * @param  \WP_REST_Request $request Request data.
53 53
 	 * @return \WP_Error\WP_REST_Response
54 54
 	 */
55
-	public function get_items( $request ) {
55
+	public function get_items($request) {
56 56
 		global $wpdb;
57 57
 
58
-		if ( isset( $request['match'] ) ) {
58
+		if (isset($request['match'])) {
59 59
 			$downloads = $wpdb->get_results(
60 60
 				$wpdb->prepare(
61 61
 					"SELECT DISTINCT( user_ip_address ) FROM {$wpdb->prefix}wc_download_log
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
 				)
66 66
 			);
67 67
 		} else {
68
-			return new \WP_Error( 'woocommerce_rest_data_download_ips_invalid_request', __( 'Invalid request. Please pass the match parameter.', 'woocommerce' ), array( 'status' => 400 ) );
68
+			return new \WP_Error('woocommerce_rest_data_download_ips_invalid_request', __('Invalid request. Please pass the match parameter.', 'woocommerce'), array('status' => 400));
69 69
 		}
70 70
 
71 71
 		$data = array();
72 72
 
73
-		if ( ! empty( $downloads ) ) {
74
-			foreach ( $downloads as $download ) {
75
-				$response = $this->prepare_item_for_response( $download, $request );
76
-				$data[]   = $this->prepare_response_for_collection( $response );
73
+		if ( ! empty($downloads)) {
74
+			foreach ($downloads as $download) {
75
+				$response = $this->prepare_item_for_response($download, $request);
76
+				$data[]   = $this->prepare_response_for_collection($response);
77 77
 			}
78 78
 		}
79 79
 
80
-		return rest_ensure_response( $data );
80
+		return rest_ensure_response($data);
81 81
 	}
82 82
 
83 83
 	/**
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
 	 * @param \WP_REST_Request $request Request object.
89 89
 	 * @return \WP_REST_Response $response Response data.
90 90
 	 */
91
-	public function prepare_item_for_response( $item, $request ) {
92
-		$data     = $this->add_additional_fields_to_object( $item, $request );
93
-		$data     = $this->filter_response_by_context( $data, 'view' );
94
-		$response = rest_ensure_response( $data );
91
+	public function prepare_item_for_response($item, $request) {
92
+		$data     = $this->add_additional_fields_to_object($item, $request);
93
+		$data     = $this->filter_response_by_context($data, 'view');
94
+		$response = rest_ensure_response($data);
95 95
 
96
-		$response->add_links( $this->prepare_links( $item ) );
96
+		$response->add_links($this->prepare_links($item));
97 97
 
98 98
 		/**
99 99
 		 * Filter the list returned from the API.
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		 * @param array            $item     The original item.
103 103
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
104 104
 		 */
105
-		return apply_filters( 'woocommerce_rest_prepare_data_download_ip', $response, $item, $request );
105
+		return apply_filters('woocommerce_rest_prepare_data_download_ip', $response, $item, $request);
106 106
 	}
107 107
 
108 108
 	/**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
 	 * @param object $item Data object.
112 112
 	 * @return array Links for the given object.
113 113
 	 */
114
-	protected function prepare_links( $item ) {
114
+	protected function prepare_links($item) {
115 115
 		$links = array(
116 116
 			'collection' => array(
117
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
117
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
118 118
 			),
119 119
 		);
120 120
 		return $links;
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 	 */
128 128
 	public function get_collection_params() {
129 129
 		$params            = array();
130
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
130
+		$params['context'] = $this->get_context_param(array('default' => 'view'));
131 131
 		$params['match']   = array(
132
-			'description'       => __( 'A partial IP address can be passed and matching results will be returned.', 'woocommerce' ),
132
+			'description'       => __('A partial IP address can be passed and matching results will be returned.', 'woocommerce'),
133 133
 			'type'              => 'string',
134 134
 			'validate_callback' => 'rest_validate_request_arg',
135 135
 		);
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 			'properties' => array(
151 151
 				'user_ip_address' => array(
152 152
 					'type'        => 'string',
153
-					'description' => __( 'IP address.', 'woocommerce' ),
154
-					'context'     => array( 'view' ),
153
+					'description' => __('IP address.', 'woocommerce'),
154
+					'context'     => array('view'),
155 155
 					'readonly'    => true,
156 156
 				),
157 157
 			),
158 158
 		);
159 159
 
160
-		return $this->add_additional_fields_schema( $schema );
160
+		return $this->add_additional_fields_schema($schema);
161 161
 	}
162 162
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Data/Currencies.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Data as DataController;
15 15
 
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 			array(
36 36
 				array(
37 37
 					'methods'             => \WP_REST_Server::READABLE,
38
-					'callback'            => array( $this, 'get_items' ),
39
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
38
+					'callback'            => array($this, 'get_items'),
39
+					'permission_callback' => array($this, 'get_items_permissions_check'),
40 40
 				),
41
-				'schema' => array( $this, 'get_public_item_schema' ),
41
+				'schema' => array($this, 'get_public_item_schema'),
42 42
 			)
43 43
 		);
44 44
 		register_rest_route(
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 			array(
48 48
 				array(
49 49
 					'methods'             => \WP_REST_Server::READABLE,
50
-					'callback'            => array( $this, 'get_current_item' ),
51
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
50
+					'callback'            => array($this, 'get_current_item'),
51
+					'permission_callback' => array($this, 'get_item_permissions_check'),
52 52
 				),
53
-				'schema' => array( $this, 'get_public_item_schema' ),
53
+				'schema' => array($this, 'get_public_item_schema'),
54 54
 			)
55 55
 		);
56 56
 		register_rest_route(
@@ -59,16 +59,16 @@  discard block
 block discarded – undo
59 59
 			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/RestApi/Version4/Controllers/Data/Continents.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Data as DataController;
15 15
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 			array(
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::READABLE,
40
-					'callback'            => array( $this, 'get_items' ),
41
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
+					'callback'            => array($this, 'get_items'),
41
+					'permission_callback' => array($this, 'get_items_permissions_check'),
42 42
 				),
43
-				'schema' => array( $this, 'get_public_item_schema' ),
43
+				'schema' => array($this, 'get_public_item_schema'),
44 44
 			)
45 45
 		);
46 46
 		register_rest_route(
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
 			array(
50 50
 				array(
51 51
 					'methods'             => \WP_REST_Server::READABLE,
52
-					'callback'            => array( $this, 'get_item' ),
53
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
52
+					'callback'            => array($this, 'get_item'),
53
+					'permission_callback' => array($this, 'get_items_permissions_check'),
54 54
 					'args'                => array(
55 55
 						'continent' => array(
56
-							'description' => __( '2 character continent code.', 'woocommerce' ),
56
+							'description' => __('2 character continent code.', 'woocommerce'),
57 57
 							'type'        => 'string',
58 58
 						),
59 59
 					),
60 60
 				),
61
-				'schema' => array( $this, 'get_public_item_schema' ),
61
+				'schema' => array($this, 'get_public_item_schema'),
62 62
 			)
63 63
 		);
64 64
 	}
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
 	 * @param  \WP_REST_Request $request        Request data.
72 72
 	 * @return array|mixed Response data, ready for insertion into collection data.
73 73
 	 */
74
-	public function get_continent( $continent_code = false, $request ) {
74
+	public function get_continent($continent_code = false, $request) {
75 75
 		$continents  = WC()->countries->get_continents();
76 76
 		$countries   = WC()->countries->get_countries();
77 77
 		$states      = WC()->countries->get_states();
78 78
 		$locale_info = include WC()->plugin_path() . '/i18n/locale-info.php';
79 79
 		$data        = array();
80 80
 
81
-		if ( ! array_key_exists( $continent_code, $continents ) ) {
81
+		if ( ! array_key_exists($continent_code, $continents)) {
82 82
 			return false;
83 83
 		}
84 84
 
85
-		$continent_list = $continents[ $continent_code ];
85
+		$continent_list = $continents[$continent_code];
86 86
 
87 87
 		$continent = array(
88 88
 			'code' => $continent_code,
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
 		);
91 91
 
92 92
 		$local_countries = array();
93
-		foreach ( $continent_list['countries'] as $country_code ) {
94
-			if ( isset( $countries[ $country_code ] ) ) {
93
+		foreach ($continent_list['countries'] as $country_code) {
94
+			if (isset($countries[$country_code])) {
95 95
 				$country = array(
96 96
 					'code' => $country_code,
97
-					'name' => $countries[ $country_code ],
97
+					'name' => $countries[$country_code],
98 98
 				);
99 99
 
100 100
 				// If we have detailed locale information include that in the response.
101
-				if ( array_key_exists( $country_code, $locale_info ) ) {
101
+				if (array_key_exists($country_code, $locale_info)) {
102 102
 					// Defensive programming against unexpected changes in locale-info.php.
103 103
 					$country_data = wp_parse_args(
104
-						$locale_info[ $country_code ],
104
+						$locale_info[$country_code],
105 105
 						array(
106 106
 							'currency_code'  => 'USD',
107 107
 							'currency_pos'   => 'left',
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 						)
114 114
 					);
115 115
 
116
-					$country = array_merge( $country, $country_data );
116
+					$country = array_merge($country, $country_data);
117 117
 				}
118 118
 
119 119
 				$local_states = array();
120
-				if ( isset( $states[ $country_code ] ) ) {
121
-					foreach ( $states[ $country_code ] as $state_code => $state_name ) {
120
+				if (isset($states[$country_code])) {
121
+					foreach ($states[$country_code] as $state_code => $state_name) {
122 122
 						$local_states[] = array(
123 123
 							'code' => $state_code,
124 124
 							'name' => $state_name,
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 					'thousand_sep',
141 141
 					'weight_unit',
142 142
 				);
143
-				$country = array_intersect_key( $country, array_flip( $allowed ) );
143
+				$country = array_intersect_key($country, array_flip($allowed));
144 144
 
145 145
 				$local_countries[] = $country;
146 146
 			}
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
 	 * @param  \WP_REST_Request $request Request data.
158 158
 	 * @return \WP_Error\WP_REST_Response
159 159
 	 */
160
-	public function get_items( $request ) {
160
+	public function get_items($request) {
161 161
 		$continents = WC()->countries->get_continents();
162 162
 		$data       = array();
163 163
 
164
-		foreach ( array_keys( $continents ) as $continent_code ) {
165
-			$continent = $this->get_continent( $continent_code, $request );
166
-			$response  = $this->prepare_item_for_response( $continent, $request );
167
-			$data[]    = $this->prepare_response_for_collection( $response );
164
+		foreach (array_keys($continents) as $continent_code) {
165
+			$continent = $this->get_continent($continent_code, $request);
166
+			$response  = $this->prepare_item_for_response($continent, $request);
167
+			$data[]    = $this->prepare_response_for_collection($response);
168 168
 		}
169 169
 
170
-		return rest_ensure_response( $data );
170
+		return rest_ensure_response($data);
171 171
 	}
172 172
 
173 173
 	/**
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
 	 * @param  \WP_REST_Request $request Request data.
178 178
 	 * @return \WP_Error\WP_REST_Response
179 179
 	 */
180
-	public function get_item( $request ) {
181
-		$data = $this->get_continent( strtoupper( $request['location'] ), $request );
182
-		if ( empty( $data ) ) {
183
-			return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
180
+	public function get_item($request) {
181
+		$data = $this->get_continent(strtoupper($request['location']), $request);
182
+		if (empty($data)) {
183
+			return new \WP_Error('woocommerce_rest_data_invalid_location', __('There are no locations matching these parameters.', 'woocommerce'), array('status' => 404));
184 184
 		}
185
-		return $this->prepare_item_for_response( $data, $request );
185
+		return $this->prepare_item_for_response($data, $request);
186 186
 	}
187 187
 
188 188
 	/**
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
 	 * @param \WP_REST_Request $request Request object.
194 194
 	 * @return \WP_REST_Response $response Response data.
195 195
 	 */
196
-	public function prepare_item_for_response( $item, $request ) {
197
-		$data     = $this->add_additional_fields_to_object( $item, $request );
198
-		$data     = $this->filter_response_by_context( $data, 'view' );
199
-		$response = rest_ensure_response( $data );
196
+	public function prepare_item_for_response($item, $request) {
197
+		$data     = $this->add_additional_fields_to_object($item, $request);
198
+		$data     = $this->filter_response_by_context($data, 'view');
199
+		$response = rest_ensure_response($data);
200 200
 
201
-		$response->add_links( $this->prepare_links( $item ) );
201
+		$response->add_links($this->prepare_links($item));
202 202
 
203 203
 		/**
204 204
 		 * Filter the location list returned from the API.
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 		 * @param array            $item     The original list of continent(s), countries, and states.
210 210
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
211 211
 		 */
212
-		return apply_filters( 'woocommerce_rest_prepare_data_continent', $response, $item, $request );
212
+		return apply_filters('woocommerce_rest_prepare_data_continent', $response, $item, $request);
213 213
 	}
214 214
 
215 215
 	/**
@@ -218,14 +218,14 @@  discard block
 block discarded – undo
218 218
 	 * @param object $item Data object.
219 219
 	 * @return array Links for the given continent.
220 220
 	 */
221
-	protected function prepare_links( $item ) {
222
-		$continent_code = strtolower( $item['code'] );
221
+	protected function prepare_links($item) {
222
+		$continent_code = strtolower($item['code']);
223 223
 		$links          = array(
224 224
 			'self'       => array(
225
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code ) ),
225
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code)),
226 226
 			),
227 227
 			'collection' => array(
228
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
228
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
229 229
 			),
230 230
 		);
231 231
 		return $links;
@@ -245,88 +245,88 @@  discard block
 block discarded – undo
245 245
 			'properties' => array(
246 246
 				'code'      => array(
247 247
 					'type'        => 'string',
248
-					'description' => __( '2 character continent code.', 'woocommerce' ),
249
-					'context'     => array( 'view' ),
248
+					'description' => __('2 character continent code.', 'woocommerce'),
249
+					'context'     => array('view'),
250 250
 					'readonly'    => true,
251 251
 				),
252 252
 				'name'      => array(
253 253
 					'type'        => 'string',
254
-					'description' => __( 'Full name of continent.', 'woocommerce' ),
255
-					'context'     => array( 'view' ),
254
+					'description' => __('Full name of continent.', 'woocommerce'),
255
+					'context'     => array('view'),
256 256
 					'readonly'    => true,
257 257
 				),
258 258
 				'countries' => array(
259 259
 					'type'        => 'array',
260
-					'description' => __( 'List of countries on this continent.', 'woocommerce' ),
261
-					'context'     => array( 'view' ),
260
+					'description' => __('List of countries on this continent.', 'woocommerce'),
261
+					'context'     => array('view'),
262 262
 					'readonly'    => true,
263 263
 					'items'       => array(
264 264
 						'type'       => 'object',
265
-						'context'    => array( 'view' ),
265
+						'context'    => array('view'),
266 266
 						'readonly'   => true,
267 267
 						'properties' => array(
268 268
 							'code'           => array(
269 269
 								'type'        => 'string',
270
-								'description' => __( 'ISO3166 alpha-2 country code.', 'woocommerce' ),
271
-								'context'     => array( 'view' ),
270
+								'description' => __('ISO3166 alpha-2 country code.', 'woocommerce'),
271
+								'context'     => array('view'),
272 272
 								'readonly'    => true,
273 273
 							),
274 274
 							'currency_code'  => array(
275 275
 								'type'        => 'string',
276
-								'description' => __( 'Default ISO4127 alpha-3 currency code for the country.', 'woocommerce' ),
277
-								'context'     => array( 'view' ),
276
+								'description' => __('Default ISO4127 alpha-3 currency code for the country.', 'woocommerce'),
277
+								'context'     => array('view'),
278 278
 								'readonly'    => true,
279 279
 							),
280 280
 							'currency_pos'   => array(
281 281
 								'type'        => 'string',
282
-								'description' => __( 'Currency symbol position for this country.', 'woocommerce' ),
283
-								'context'     => array( 'view' ),
282
+								'description' => __('Currency symbol position for this country.', 'woocommerce'),
283
+								'context'     => array('view'),
284 284
 								'readonly'    => true,
285 285
 							),
286 286
 							'decimal_sep'    => array(
287 287
 								'type'        => 'string',
288
-								'description' => __( 'Decimal separator for displayed prices for this country.', 'woocommerce' ),
289
-								'context'     => array( 'view' ),
288
+								'description' => __('Decimal separator for displayed prices for this country.', 'woocommerce'),
289
+								'context'     => array('view'),
290 290
 								'readonly'    => true,
291 291
 							),
292 292
 							'dimension_unit' => array(
293 293
 								'type'        => 'string',
294
-								'description' => __( 'The unit lengths are defined in for this country.', 'woocommerce' ),
295
-								'context'     => array( 'view' ),
294
+								'description' => __('The unit lengths are defined in for this country.', 'woocommerce'),
295
+								'context'     => array('view'),
296 296
 								'readonly'    => true,
297 297
 							),
298 298
 							'name'           => array(
299 299
 								'type'        => 'string',
300
-								'description' => __( 'Full name of country.', 'woocommerce' ),
301
-								'context'     => array( 'view' ),
300
+								'description' => __('Full name of country.', 'woocommerce'),
301
+								'context'     => array('view'),
302 302
 								'readonly'    => true,
303 303
 							),
304 304
 							'num_decimals'   => array(
305 305
 								'type'        => 'integer',
306
-								'description' => __( 'Number of decimal points shown in displayed prices for this country.', 'woocommerce' ),
307
-								'context'     => array( 'view' ),
306
+								'description' => __('Number of decimal points shown in displayed prices for this country.', 'woocommerce'),
307
+								'context'     => array('view'),
308 308
 								'readonly'    => true,
309 309
 							),
310 310
 							'states'         => array(
311 311
 								'type'        => 'array',
312
-								'description' => __( 'List of states in this country.', 'woocommerce' ),
313
-								'context'     => array( 'view' ),
312
+								'description' => __('List of states in this country.', 'woocommerce'),
313
+								'context'     => array('view'),
314 314
 								'readonly'    => true,
315 315
 								'items'       => array(
316 316
 									'type'       => 'object',
317
-									'context'    => array( 'view' ),
317
+									'context'    => array('view'),
318 318
 									'readonly'   => true,
319 319
 									'properties' => array(
320 320
 										'code' => array(
321 321
 											'type'        => 'string',
322
-											'description' => __( 'State code.', 'woocommerce' ),
323
-											'context'     => array( 'view' ),
322
+											'description' => __('State code.', 'woocommerce'),
323
+											'context'     => array('view'),
324 324
 											'readonly'    => true,
325 325
 										),
326 326
 										'name' => array(
327 327
 											'type'        => 'string',
328
-											'description' => __( 'Full name of state.', 'woocommerce' ),
329
-											'context'     => array( 'view' ),
328
+											'description' => __('Full name of state.', 'woocommerce'),
329
+											'context'     => array('view'),
330 330
 											'readonly'    => true,
331 331
 										),
332 332
 									),
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
 							),
335 335
 							'thousand_sep'   => array(
336 336
 								'type'        => 'string',
337
-								'description' => __( 'Thousands separator for displayed prices in this country.', 'woocommerce' ),
338
-								'context'     => array( 'view' ),
337
+								'description' => __('Thousands separator for displayed prices in this country.', 'woocommerce'),
338
+								'context'     => array('view'),
339 339
 								'readonly'    => true,
340 340
 							),
341 341
 							'weight_unit'    => array(
342 342
 								'type'        => 'string',
343
-								'description' => __( 'The unit weights are defined in for this country.', 'woocommerce' ),
344
-								'context'     => array( 'view' ),
343
+								'description' => __('The unit weights are defined in for this country.', 'woocommerce'),
344
+								'context'     => array('view'),
345 345
 								'readonly'    => true,
346 346
 							),
347 347
 						),
@@ -350,6 +350,6 @@  discard block
 block discarded – undo
350 350
 			),
351 351
 		);
352 352
 
353
-		return $this->add_additional_fields_schema( $schema );
353
+		return $this->add_additional_fields_schema($schema);
354 354
 	}
355 355
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Data/Countries.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Data as DataController;
15 15
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 			array(
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::READABLE,
40
-					'callback'            => array( $this, 'get_items' ),
41
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
+					'callback'            => array($this, 'get_items'),
41
+					'permission_callback' => array($this, 'get_items_permissions_check'),
42 42
 				),
43
-				'schema' => array( $this, 'get_public_item_schema' ),
43
+				'schema' => array($this, 'get_public_item_schema'),
44 44
 			)
45 45
 		);
46 46
 		register_rest_route(
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
 			array(
50 50
 				array(
51 51
 					'methods'             => \WP_REST_Server::READABLE,
52
-					'callback'            => array( $this, 'get_item' ),
53
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
52
+					'callback'            => array($this, 'get_item'),
53
+					'permission_callback' => array($this, 'get_items_permissions_check'),
54 54
 					'args'                => array(
55 55
 						'location' => array(
56
-							'description' => __( 'ISO3166 alpha-2 country code.', 'woocommerce' ),
56
+							'description' => __('ISO3166 alpha-2 country code.', 'woocommerce'),
57 57
 							'type'        => 'string',
58 58
 						),
59 59
 					),
60 60
 				),
61
-				'schema' => array( $this, 'get_public_item_schema' ),
61
+				'schema' => array($this, 'get_public_item_schema'),
62 62
 			)
63 63
 		);
64 64
 	}
@@ -70,23 +70,23 @@  discard block
 block discarded – undo
70 70
 	 * @param  \WP_REST_Request $request      Request data.
71 71
 	 * @return array|mixed Response data, ready for insertion into collection data.
72 72
 	 */
73
-	public function get_country( $country_code = false, $request ) {
73
+	public function get_country($country_code = false, $request) {
74 74
 		$countries = WC()->countries->get_countries();
75 75
 		$states    = WC()->countries->get_states();
76 76
 		$data      = array();
77 77
 
78
-		if ( ! array_key_exists( $country_code, $countries ) ) {
78
+		if ( ! array_key_exists($country_code, $countries)) {
79 79
 			return false;
80 80
 		}
81 81
 
82 82
 		$country = array(
83 83
 			'code' => $country_code,
84
-			'name' => $countries[ $country_code ],
84
+			'name' => $countries[$country_code],
85 85
 		);
86 86
 
87 87
 		$local_states = array();
88
-		if ( isset( $states[ $country_code ] ) ) {
89
-			foreach ( $states[ $country_code ] as $state_code => $state_name ) {
88
+		if (isset($states[$country_code])) {
89
+			foreach ($states[$country_code] as $state_code => $state_name) {
90 90
 				$local_states[] = array(
91 91
 					'code' => $state_code,
92 92
 					'name' => $state_name,
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
 	 * @param  \WP_REST_Request $request Request data.
105 105
 	 * @return \WP_Error\WP_REST_Response
106 106
 	 */
107
-	public function get_items( $request ) {
107
+	public function get_items($request) {
108 108
 		$countries = WC()->countries->get_countries();
109 109
 		$data      = array();
110 110
 
111
-		foreach ( array_keys( $countries ) as $country_code ) {
112
-			$country  = $this->get_country( $country_code, $request );
113
-			$response = $this->prepare_item_for_response( $country, $request );
114
-			$data[]   = $this->prepare_response_for_collection( $response );
111
+		foreach (array_keys($countries) as $country_code) {
112
+			$country  = $this->get_country($country_code, $request);
113
+			$response = $this->prepare_item_for_response($country, $request);
114
+			$data[]   = $this->prepare_response_for_collection($response);
115 115
 		}
116 116
 
117
-		return rest_ensure_response( $data );
117
+		return rest_ensure_response($data);
118 118
 	}
119 119
 
120 120
 	/**
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 	 * @param  \WP_REST_Request $request Request data.
125 125
 	 * @return \WP_Error\WP_REST_Response
126 126
 	 */
127
-	public function get_item( $request ) {
128
-		$data = $this->get_country( strtoupper( $request['location'] ), $request );
129
-		if ( empty( $data ) ) {
130
-			return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
127
+	public function get_item($request) {
128
+		$data = $this->get_country(strtoupper($request['location']), $request);
129
+		if (empty($data)) {
130
+			return new \WP_Error('woocommerce_rest_data_invalid_location', __('There are no locations matching these parameters.', 'woocommerce'), array('status' => 404));
131 131
 		}
132
-		return $this->prepare_item_for_response( $data, $request );
132
+		return $this->prepare_item_for_response($data, $request);
133 133
 	}
134 134
 
135 135
 	/**
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 * @param \WP_REST_Request $request Request object.
141 141
 	 * @return \WP_REST_Response $response Response data.
142 142
 	 */
143
-	public function prepare_item_for_response( $item, $request ) {
144
-		$data     = $this->add_additional_fields_to_object( $item, $request );
145
-		$data     = $this->filter_response_by_context( $data, 'view' );
146
-		$response = rest_ensure_response( $data );
143
+	public function prepare_item_for_response($item, $request) {
144
+		$data     = $this->add_additional_fields_to_object($item, $request);
145
+		$data     = $this->filter_response_by_context($data, 'view');
146
+		$response = rest_ensure_response($data);
147 147
 
148
-		$response->add_links( $this->prepare_links( $item ) );
148
+		$response->add_links($this->prepare_links($item));
149 149
 
150 150
 		/**
151 151
 		 * Filter the states list for a country returned from the API.
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		 * @param array            $data     The original country's states list.
157 157
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
158 158
 		 */
159
-		return apply_filters( 'woocommerce_rest_prepare_data_country', $response, $item, $request );
159
+		return apply_filters('woocommerce_rest_prepare_data_country', $response, $item, $request);
160 160
 	}
161 161
 
162 162
 	/**
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
 	 * @param object $item Data object.
166 166
 	 * @return array Links for the given country.
167 167
 	 */
168
-	protected function prepare_links( $item ) {
169
-		$country_code = strtolower( $item['code'] );
168
+	protected function prepare_links($item) {
169
+		$country_code = strtolower($item['code']);
170 170
 		$links        = array(
171 171
 			'self'       => array(
172
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $country_code ) ),
172
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $country_code)),
173 173
 			),
174 174
 			'collection' => array(
175
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
175
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
176 176
 			),
177 177
 		);
178 178
 
@@ -194,36 +194,36 @@  discard block
 block discarded – undo
194 194
 			'properties' => array(
195 195
 				'code'   => array(
196 196
 					'type'        => 'string',
197
-					'description' => __( 'ISO3166 alpha-2 country code.', 'woocommerce' ),
198
-					'context'     => array( 'view' ),
197
+					'description' => __('ISO3166 alpha-2 country code.', 'woocommerce'),
198
+					'context'     => array('view'),
199 199
 					'readonly'    => true,
200 200
 				),
201 201
 				'name'   => array(
202 202
 					'type'        => 'string',
203
-					'description' => __( 'Full name of country.', 'woocommerce' ),
204
-					'context'     => array( 'view' ),
203
+					'description' => __('Full name of country.', 'woocommerce'),
204
+					'context'     => array('view'),
205 205
 					'readonly'    => true,
206 206
 				),
207 207
 				'states' => array(
208 208
 					'type'        => 'array',
209
-					'description' => __( 'List of states in this country.', 'woocommerce' ),
210
-					'context'     => array( 'view' ),
209
+					'description' => __('List of states in this country.', 'woocommerce'),
210
+					'context'     => array('view'),
211 211
 					'readonly'    => true,
212 212
 					'items'       => array(
213 213
 						'type'       => 'object',
214
-						'context'    => array( 'view' ),
214
+						'context'    => array('view'),
215 215
 						'readonly'   => true,
216 216
 						'properties' => array(
217 217
 							'code' => array(
218 218
 								'type'        => 'string',
219
-								'description' => __( 'State code.', 'woocommerce' ),
220
-								'context'     => array( 'view' ),
219
+								'description' => __('State code.', 'woocommerce'),
220
+								'context'     => array('view'),
221 221
 								'readonly'    => true,
222 222
 							),
223 223
 							'name' => array(
224 224
 								'type'        => 'string',
225
-								'description' => __( 'Full name of state.', 'woocommerce' ),
226
-								'context'     => array( 'view' ),
225
+								'description' => __('Full name of state.', 'woocommerce'),
226
+								'context'     => array('view'),
227 227
 								'readonly'    => true,
228 228
 							),
229 229
 						),
@@ -232,6 +232,6 @@  discard block
 block discarded – undo
232 232
 			),
233 233
 		);
234 234
 
235
-		return $this->add_additional_fields_schema( $schema );
235
+		return $this->add_additional_fields_schema($schema);
236 236
 	}
237 237
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports/PerformanceIndicators.php 1 patch
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Reports;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
15 15
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 			array(
64 64
 				array(
65 65
 					'methods'             => \WP_REST_Server::READABLE,
66
-					'callback'            => array( $this, 'get_items' ),
67
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
66
+					'callback'            => array($this, 'get_items'),
67
+					'permission_callback' => array($this, 'get_items_permissions_check'),
68 68
 					'args'                => $this->get_collection_params(),
69 69
 				),
70
-				'schema' => array( $this, 'get_public_item_schema' ),
70
+				'schema' => array($this, 'get_public_item_schema'),
71 71
 			)
72 72
 		);
73 73
 
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 			array(
78 78
 				array(
79 79
 					'methods'             => \WP_REST_Server::READABLE,
80
-					'callback'            => array( $this, 'get_allowed_items' ),
81
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
80
+					'callback'            => array($this, 'get_allowed_items'),
81
+					'permission_callback' => array($this, 'get_items_permissions_check'),
82 82
 					'args'                => $this->get_collection_params(),
83 83
 				),
84
-				'schema' => array( $this, 'get_public_allowed_item_schema' ),
84
+				'schema' => array($this, 'get_public_allowed_item_schema'),
85 85
 			)
86 86
 		);
87 87
 	}
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @param array $request Request array.
93 93
 	 * @return array
94 94
 	 */
95
-	protected function prepare_reports_query( $request ) {
95
+	protected function prepare_reports_query($request) {
96 96
 		$args           = array();
97 97
 		$args['before'] = $request['before'];
98 98
 		$args['after']  = $request['after'];
@@ -107,44 +107,44 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	private function get_indicator_data() {
109 109
 		// Data already retrieved.
110
-		if ( ! empty( $this->endpoints ) && ! empty( $this->labels ) && ! empty( $this->allowed_stats ) ) {
110
+		if ( ! empty($this->endpoints) && ! empty($this->labels) && ! empty($this->allowed_stats)) {
111 111
 			return true;
112 112
 		}
113 113
 
114
-		$request       = new \WP_REST_Request( 'GET', '/wc/v4/reports' );
115
-		$response      = rest_do_request( $request );
114
+		$request       = new \WP_REST_Request('GET', '/wc/v4/reports');
115
+		$response      = rest_do_request($request);
116 116
 		$endpoints     = $response->get_data();
117 117
 		$allowed_stats = array();
118
-		if ( 200 !== $response->get_status() ) {
119
-			return new \WP_Error( 'woocommerce_reports_performance_indicators_result_failed', __( 'Sorry, fetching performance indicators failed.', 'woocommerce' ) );
118
+		if (200 !== $response->get_status()) {
119
+			return new \WP_Error('woocommerce_reports_performance_indicators_result_failed', __('Sorry, fetching performance indicators failed.', 'woocommerce'));
120 120
 		}
121 121
 
122
-		foreach ( $endpoints as $endpoint ) {
123
-			if ( '/stats' === substr( $endpoint['slug'], -6 ) ) {
124
-				$request  = new \WP_REST_Request( 'OPTIONS', $endpoint['path'] );
125
-				$response = rest_do_request( $request );
122
+		foreach ($endpoints as $endpoint) {
123
+			if ('/stats' === substr($endpoint['slug'], -6)) {
124
+				$request  = new \WP_REST_Request('OPTIONS', $endpoint['path']);
125
+				$response = rest_do_request($request);
126 126
 				$data     = $response->get_data();
127 127
 
128
-				$prefix = substr( $endpoint['slug'], 0, -6 );
128
+				$prefix = substr($endpoint['slug'], 0, -6);
129 129
 
130
-				if ( empty( $data['schema']['properties']['totals']['properties'] ) ) {
130
+				if (empty($data['schema']['properties']['totals']['properties'])) {
131 131
 					continue;
132 132
 				}
133 133
 
134
-				foreach ( $data['schema']['properties']['totals']['properties'] as $property_key => $schema_info ) {
135
-					if ( empty( $schema_info['indicator'] ) || ! $schema_info['indicator'] ) {
134
+				foreach ($data['schema']['properties']['totals']['properties'] as $property_key => $schema_info) {
135
+					if (empty($schema_info['indicator']) || ! $schema_info['indicator']) {
136 136
 						continue;
137 137
 					}
138 138
 
139 139
 					$stat            = $prefix . '/' . $property_key;
140 140
 					$allowed_stats[] = $stat;
141 141
 
142
-					$this->labels[ $stat ]  = trim( preg_replace( '/\W+/', ' ', $schema_info['description'] ) );
143
-					$this->formats[ $stat ] = isset( $schema_info['format'] ) ? $schema_info['format'] : 'number';
142
+					$this->labels[$stat]  = trim(preg_replace('/\W+/', ' ', $schema_info['description']));
143
+					$this->formats[$stat] = isset($schema_info['format']) ? $schema_info['format'] : 'number';
144 144
 				}
145 145
 
146
-				$this->endpoints[ $prefix ] = $endpoint['path'];
147
-				$this->urls[ $prefix ]      = $endpoint['_links']['report'][0]['href'];
146
+				$this->endpoints[$prefix] = $endpoint['path'];
147
+				$this->urls[$prefix]      = $endpoint['_links']['report'][0]['href'];
148 148
 			}
149 149
 		}
150 150
 
@@ -158,37 +158,37 @@  discard block
 block discarded – undo
158 158
 	 * @param  \WP_REST_Request $request Request data.
159 159
 	 * @return array|\WP_Error
160 160
 	 */
161
-	public function get_allowed_items( $request ) {
161
+	public function get_allowed_items($request) {
162 162
 		$indicator_data = $this->get_indicator_data();
163
-		if ( is_wp_error( $indicator_data ) ) {
163
+		if (is_wp_error($indicator_data)) {
164 164
 			return $indicator_data;
165 165
 		}
166 166
 
167 167
 		$data = array();
168
-		foreach ( $this->allowed_stats as $stat ) {
169
-			$pieces = $this->get_stats_parts( $stat );
168
+		foreach ($this->allowed_stats as $stat) {
169
+			$pieces = $this->get_stats_parts($stat);
170 170
 			$report = $pieces[0];
171 171
 			$chart  = $pieces[1];
172 172
 			$data[] = (object) array(
173 173
 				'stat'  => $stat,
174 174
 				'chart' => $chart,
175
-				'label' => $this->labels[ $stat ],
175
+				'label' => $this->labels[$stat],
176 176
 			);
177 177
 		}
178 178
 
179
-		usort( $data, array( $this, 'sort' ) );
179
+		usort($data, array($this, 'sort'));
180 180
 
181 181
 		$objects = array();
182
-		foreach ( $data as $item ) {
183
-			$prepared  = $this->prepare_item_for_response( $item, $request );
184
-			$objects[] = $this->prepare_response_for_collection( $prepared );
182
+		foreach ($data as $item) {
183
+			$prepared  = $this->prepare_item_for_response($item, $request);
184
+			$objects[] = $this->prepare_response_for_collection($prepared);
185 185
 		}
186 186
 
187
-		$response = rest_ensure_response( $objects );
188
-		$response->header( 'X-WP-Total', count( $data ) );
189
-		$response->header( 'X-WP-TotalPages', 1 );
187
+		$response = rest_ensure_response($objects);
188
+		$response->header('X-WP-Total', count($data));
189
+		$response->header('X-WP-TotalPages', 1);
190 190
 
191
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
191
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
192 192
 
193 193
 		return $response;
194 194
 	}
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 * @param object $b Second item.
202 202
 	 * @return order
203 203
 	 */
204
-	public function sort( $a, $b ) {
204
+	public function sort($a, $b) {
205 205
 		/**
206 206
 		 * Custom ordering for store performance indicators.
207 207
 		 *
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 			)
228 228
 		);
229 229
 
230
-		$a = array_search( $a->stat, $stat_order );
231
-		$b = array_search( $b->stat, $stat_order );
230
+		$a = array_search($a->stat, $stat_order);
231
+		$b = array_search($b->stat, $stat_order);
232 232
 
233
-		if ( false === $a && false === $b ) {
233
+		if (false === $a && false === $b) {
234 234
 			return 0;
235
-		} elseif ( false === $a ) {
235
+		} elseif (false === $a) {
236 236
 			return 1;
237
-		} elseif ( false === $b ) {
237
+		} elseif (false === $b) {
238 238
 			return -1;
239 239
 		} else {
240 240
 			return $a - $b;
@@ -247,41 +247,41 @@  discard block
 block discarded – undo
247 247
 	 * @param  \WP_REST_Request $request Request data.
248 248
 	 * @return array|\WP_Error
249 249
 	 */
250
-	public function get_items( $request ) {
250
+	public function get_items($request) {
251 251
 		$indicator_data = $this->get_indicator_data();
252
-		if ( is_wp_error( $indicator_data ) ) {
252
+		if (is_wp_error($indicator_data)) {
253 253
 			return $indicator_data;
254 254
 		}
255 255
 
256
-		$query_args = $this->prepare_reports_query( $request );
257
-		if ( empty( $query_args['stats'] ) ) {
258
-			return new \WP_Error( 'woocommerce_reports_performance_indicators_empty_query', __( 'A list of stats to query must be provided.', 'woocommerce' ), 400 );
256
+		$query_args = $this->prepare_reports_query($request);
257
+		if (empty($query_args['stats'])) {
258
+			return new \WP_Error('woocommerce_reports_performance_indicators_empty_query', __('A list of stats to query must be provided.', 'woocommerce'), 400);
259 259
 		}
260 260
 
261 261
 		$stats = array();
262
-		foreach ( $query_args['stats'] as $stat ) {
262
+		foreach ($query_args['stats'] as $stat) {
263 263
 			$is_error = false;
264 264
 
265
-			$pieces = $this->get_stats_parts( $stat );
265
+			$pieces = $this->get_stats_parts($stat);
266 266
 			$report = $pieces[0];
267 267
 			$chart  = $pieces[1];
268 268
 
269
-			if ( ! in_array( $stat, $this->allowed_stats ) ) {
269
+			if ( ! in_array($stat, $this->allowed_stats)) {
270 270
 				continue;
271 271
 			}
272 272
 
273
-			$request_url = $this->endpoints[ $report ];
274
-			$request     = new \WP_REST_Request( 'GET', $request_url );
275
-			$request->set_param( 'before', $query_args['before'] );
276
-			$request->set_param( 'after', $query_args['after'] );
273
+			$request_url = $this->endpoints[$report];
274
+			$request     = new \WP_REST_Request('GET', $request_url);
275
+			$request->set_param('before', $query_args['before']);
276
+			$request->set_param('after', $query_args['after']);
277 277
 
278
-			$response = rest_do_request( $request );
278
+			$response = rest_do_request($request);
279 279
 
280 280
 			$data   = $response->get_data();
281
-			$format = $this->formats[ $stat ];
282
-			$label  = $this->labels[ $stat ];
281
+			$format = $this->formats[$stat];
282
+			$label  = $this->labels[$stat];
283 283
 
284
-			if ( 200 !== $response->get_status() || ! isset( $data['totals'][ $chart ] ) ) {
284
+			if (200 !== $response->get_status() || ! isset($data['totals'][$chart])) {
285 285
 				$stats[] = (object) array(
286 286
 					'stat'   => $stat,
287 287
 					'chart'  => $chart,
@@ -297,23 +297,23 @@  discard block
 block discarded – undo
297 297
 				'chart'  => $chart,
298 298
 				'label'  => $label,
299 299
 				'format' => $format,
300
-				'value'  => $data['totals'][ $chart ],
300
+				'value'  => $data['totals'][$chart],
301 301
 			);
302 302
 		}
303 303
 
304
-		usort( $stats, array( $this, 'sort' ) );
304
+		usort($stats, array($this, 'sort'));
305 305
 
306 306
 		$objects = array();
307
-		foreach ( $stats as $stat ) {
308
-			$data      = $this->prepare_item_for_response( $stat, $request );
309
-			$objects[] = $this->prepare_response_for_collection( $data );
307
+		foreach ($stats as $stat) {
308
+			$data      = $this->prepare_item_for_response($stat, $request);
309
+			$objects[] = $this->prepare_response_for_collection($data);
310 310
 		}
311 311
 
312
-		$response = rest_ensure_response( $objects );
313
-		$response->header( 'X-WP-Total', count( $stats ) );
314
-		$response->header( 'X-WP-TotalPages', 1 );
312
+		$response = rest_ensure_response($objects);
313
+		$response->header('X-WP-Total', count($stats));
314
+		$response->header('X-WP-TotalPages', 1);
315 315
 
316
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
316
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
317 317
 
318 318
 		return $response;
319 319
 	}
@@ -325,15 +325,15 @@  discard block
 block discarded – undo
325 325
 	 * @param \WP_REST_Request $request Request object.
326 326
 	 * @return \WP_REST_Response
327 327
 	 */
328
-	public function prepare_item_for_response( $stat_data, $request ) {
329
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
330
-		$data    = $this->add_additional_fields_to_object( $stat_data, $request );
331
-		$data    = $this->filter_response_by_context( $data, $context );
328
+	public function prepare_item_for_response($stat_data, $request) {
329
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
330
+		$data    = $this->add_additional_fields_to_object($stat_data, $request);
331
+		$data    = $this->filter_response_by_context($data, $context);
332 332
 
333 333
 		// Wrap the data in a response object.
334
-		$response = rest_ensure_response( $data );
334
+		$response = rest_ensure_response($data);
335 335
 
336
-		$response->add_links( $this->prepare_links( $data ) );
336
+		$response->add_links($this->prepare_links($data));
337 337
 
338 338
 		/**
339 339
 		 * Filter a report returned from the API.
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 		 * @param object           $report   The original report object.
345 345
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
346 346
 		 */
347
-		return apply_filters( 'woocommerce_rest_prepare_report_performance_indicators', $response, $stat_data, $request );
347
+		return apply_filters('woocommerce_rest_prepare_report_performance_indicators', $response, $stat_data, $request);
348 348
 	}
349 349
 
350 350
 	/**
@@ -353,18 +353,18 @@  discard block
 block discarded – undo
353 353
 	 * @param WC_Admin_Reports_Query $object Object data.
354 354
 	 * @return array
355 355
 	 */
356
-	protected function prepare_links( $object ) {
357
-		$pieces   = $this->get_stats_parts( $object->stat );
356
+	protected function prepare_links($object) {
357
+		$pieces   = $this->get_stats_parts($object->stat);
358 358
 		$endpoint = $pieces[0];
359 359
 		$stat     = $pieces[1];
360
-		$url      = $this->urls[ $endpoint ];
360
+		$url      = $this->urls[$endpoint];
361 361
 
362 362
 		$links = array(
363 363
 			'api'    => array(
364
-				'href' => rest_url( $this->endpoints[ $endpoint ] ),
364
+				'href' => rest_url($this->endpoints[$endpoint]),
365 365
 			),
366 366
 			'report' => array(
367
-				'href' => ! empty( $url ) ? $url : '',
367
+				'href' => ! empty($url) ? $url : '',
368 368
 			),
369 369
 		);
370 370
 
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
 	 * @param string $full_stat A stat request string like orders/avg_order_value or fue/emails/sent.
379 379
 	 * @return array Containing the prefix (endpoint) and suffix (stat).
380 380
 	 */
381
-	private function get_stats_parts( $full_stat ) {
382
-		$endpoint = substr( $full_stat, 0, strrpos( $full_stat, '/' ) );
383
-		$stat     = substr( $full_stat, ( strrpos( $full_stat, '/' ) + 1 ) );
381
+	private function get_stats_parts($full_stat) {
382
+		$endpoint = substr($full_stat, 0, strrpos($full_stat, '/'));
383
+		$stat     = substr($full_stat, (strrpos($full_stat, '/') + 1));
384 384
 		return array(
385 385
 			$endpoint,
386 386
 			$stat,
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 	 */
395 395
 	public function get_item_schema() {
396 396
 		$indicator_data = $this->get_indicator_data();
397
-		if ( is_wp_error( $indicator_data ) ) {
397
+		if (is_wp_error($indicator_data)) {
398 398
 			$allowed_stats = array();
399 399
 		} else {
400 400
 			$allowed_stats = $this->allowed_stats;
@@ -406,41 +406,41 @@  discard block
 block discarded – undo
406 406
 			'type'       => 'object',
407 407
 			'properties' => array(
408 408
 				'stat'   => array(
409
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
409
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
410 410
 					'type'        => 'string',
411
-					'context'     => array( 'view', 'edit' ),
411
+					'context'     => array('view', 'edit'),
412 412
 					'readonly'    => true,
413 413
 					'enum'        => $allowed_stats,
414 414
 				),
415 415
 				'chart'  => array(
416
-					'description' => __( 'The specific chart this stat referrers to.', 'woocommerce' ),
416
+					'description' => __('The specific chart this stat referrers to.', 'woocommerce'),
417 417
 					'type'        => 'string',
418
-					'context'     => array( 'view', 'edit' ),
418
+					'context'     => array('view', 'edit'),
419 419
 					'readonly'    => true,
420 420
 				),
421 421
 				'label'  => array(
422
-					'description' => __( 'Human readable label for the stat.', 'woocommerce' ),
422
+					'description' => __('Human readable label for the stat.', 'woocommerce'),
423 423
 					'type'        => 'string',
424
-					'context'     => array( 'view', 'edit' ),
424
+					'context'     => array('view', 'edit'),
425 425
 					'readonly'    => true,
426 426
 				),
427 427
 				'format' => array(
428
-					'description' => __( 'Format of the stat.', 'woocommerce' ),
428
+					'description' => __('Format of the stat.', 'woocommerce'),
429 429
 					'type'        => 'number',
430
-					'context'     => array( 'view', 'edit' ),
430
+					'context'     => array('view', 'edit'),
431 431
 					'readonly'    => true,
432
-					'enum'        => array( 'number', 'currency' ),
432
+					'enum'        => array('number', 'currency'),
433 433
 				),
434 434
 				'value'  => array(
435
-					'description' => __( 'Value of the stat. Returns null if the stat does not exist or cannot be loaded.', 'woocommerce' ),
435
+					'description' => __('Value of the stat. Returns null if the stat does not exist or cannot be loaded.', 'woocommerce'),
436 436
 					'type'        => 'number',
437
-					'context'     => array( 'view', 'edit' ),
437
+					'context'     => array('view', 'edit'),
438 438
 					'readonly'    => true,
439 439
 				),
440 440
 			),
441 441
 		);
442 442
 
443
-		return $this->add_additional_fields_schema( $schema );
443
+		return $this->add_additional_fields_schema($schema);
444 444
 	}
445 445
 
446 446
 	/**
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
 	 */
451 451
 	public function get_public_allowed_item_schema() {
452 452
 		$schema = $this->get_public_item_schema();
453
-		unset( $schema['properties']['value'] );
454
-		unset( $schema['properties']['format'] );
453
+		unset($schema['properties']['value']);
454
+		unset($schema['properties']['format']);
455 455
 		return $schema;
456 456
 	}
457 457
 
@@ -462,18 +462,18 @@  discard block
 block discarded – undo
462 462
 	 */
463 463
 	public function get_collection_params() {
464 464
 		$indicator_data = $this->get_indicator_data();
465
-		if ( is_wp_error( $indicator_data ) ) {
466
-			$allowed_stats = __( 'There was an issue loading the report endpoints', 'woocommerce' );
465
+		if (is_wp_error($indicator_data)) {
466
+			$allowed_stats = __('There was an issue loading the report endpoints', 'woocommerce');
467 467
 		} else {
468
-			$allowed_stats = implode( ', ', $this->allowed_stats );
468
+			$allowed_stats = implode(', ', $this->allowed_stats);
469 469
 		}
470 470
 
471 471
 		$params            = array();
472
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
472
+		$params['context'] = $this->get_context_param(array('default' => 'view'));
473 473
 		$params['stats']   = array(
474 474
 			'description'       => sprintf(
475 475
 				/* translators: Allowed values is a list of stat endpoints. */
476
-				__( 'Limit response to specific report stats. Allowed values: %s.', 'woocommerce' ),
476
+				__('Limit response to specific report stats. Allowed values: %s.', 'woocommerce'),
477 477
 				$allowed_stats
478 478
 			),
479 479
 			'type'              => 'array',
@@ -482,14 +482,14 @@  discard block
 block discarded – undo
482 482
 				'type' => 'string',
483 483
 			),
484 484
 		);
485
-		$params['after']   = array(
486
-			'description'       => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
485
+		$params['after'] = array(
486
+			'description'       => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
487 487
 			'type'              => 'string',
488 488
 			'format'            => 'date-time',
489 489
 			'validate_callback' => 'rest_validate_request_arg',
490 490
 		);
491
-		$params['before']  = array(
492
-			'description'       => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
491
+		$params['before'] = array(
492
+			'description'       => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
493 493
 			'type'              => 'string',
494 494
 			'format'            => 'date-time',
495 495
 			'validate_callback' => 'rest_validate_request_arg',
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports/RevenueStats.php 1 patch
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Reports;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
15 15
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @param array $request Request array.
32 32
 	 * @return array
33 33
 	 */
34
-	protected function prepare_reports_query( $request ) {
34
+	protected function prepare_reports_query($request) {
35 35
 		$args              = array();
36 36
 		$args['before']    = $request['before'];
37 37
 		$args['after']     = $request['after'];
@@ -51,44 +51,44 @@  discard block
 block discarded – undo
51 51
 	 * @param \WP_REST_Request $request Request data.
52 52
 	 * @return array|\WP_Error
53 53
 	 */
54
-	public function get_items( $request ) {
55
-		$query_args      = $this->prepare_reports_query( $request );
56
-		$reports_revenue = new \WC_Admin_Reports_Revenue_Query( $query_args );
54
+	public function get_items($request) {
55
+		$query_args      = $this->prepare_reports_query($request);
56
+		$reports_revenue = new \WC_Admin_Reports_Revenue_Query($query_args);
57 57
 		try {
58 58
 			$report_data = $reports_revenue->get_data();
59
-		} catch ( WC_Admin_Reports_Parameter_Exception $e ) {
60
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
59
+		} catch (WC_Admin_Reports_Parameter_Exception $e) {
60
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
61 61
 		}
62 62
 
63 63
 		$out_data = array(
64
-			'totals'    => get_object_vars( $report_data->totals ),
64
+			'totals'    => get_object_vars($report_data->totals),
65 65
 			'intervals' => array(),
66 66
 		);
67 67
 
68
-		foreach ( $report_data->intervals as $interval_data ) {
69
-			$item                    = $this->prepare_item_for_response( $interval_data, $request );
70
-			$out_data['intervals'][] = $this->prepare_response_for_collection( $item );
68
+		foreach ($report_data->intervals as $interval_data) {
69
+			$item                    = $this->prepare_item_for_response($interval_data, $request);
70
+			$out_data['intervals'][] = $this->prepare_response_for_collection($item);
71 71
 		}
72 72
 
73
-		$response = rest_ensure_response( $out_data );
74
-		$response->header( 'X-WP-Total', (int) $report_data->total );
75
-		$response->header( 'X-WP-TotalPages', (int) $report_data->pages );
73
+		$response = rest_ensure_response($out_data);
74
+		$response->header('X-WP-Total', (int) $report_data->total);
75
+		$response->header('X-WP-TotalPages', (int) $report_data->pages);
76 76
 
77 77
 		$page      = $report_data->page_no;
78 78
 		$max_pages = $report_data->pages;
79
-		$base      = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
80
-		if ( $page > 1 ) {
79
+		$base      = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
80
+		if ($page > 1) {
81 81
 			$prev_page = $page - 1;
82
-			if ( $prev_page > $max_pages ) {
82
+			if ($prev_page > $max_pages) {
83 83
 				$prev_page = $max_pages;
84 84
 			}
85
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
86
-			$response->link_header( 'prev', $prev_link );
85
+			$prev_link = add_query_arg('page', $prev_page, $base);
86
+			$response->link_header('prev', $prev_link);
87 87
 		}
88
-		if ( $max_pages > $page ) {
88
+		if ($max_pages > $page) {
89 89
 			$next_page = $page + 1;
90
-			$next_link = add_query_arg( 'page', $next_page, $base );
91
-			$response->link_header( 'next', $next_link );
90
+			$next_link = add_query_arg('page', $next_page, $base);
91
+			$response->link_header('next', $next_link);
92 92
 		}
93 93
 
94 94
 		return $response;
@@ -101,15 +101,15 @@  discard block
 block discarded – undo
101 101
 	 * @param \WP_REST_Request $request Request object.
102 102
 	 * @return \WP_REST_Response
103 103
 	 */
104
-	public function prepare_item_for_response( $report, $request ) {
104
+	public function prepare_item_for_response($report, $request) {
105 105
 		$data = $report;
106 106
 
107
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
108
-		$data    = $this->add_additional_fields_to_object( $data, $request );
109
-		$data    = $this->filter_response_by_context( $data, $context );
107
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
108
+		$data    = $this->add_additional_fields_to_object($data, $request);
109
+		$data    = $this->filter_response_by_context($data, $context);
110 110
 
111 111
 		// Wrap the data in a response object.
112
-		$response = rest_ensure_response( $data );
112
+		$response = rest_ensure_response($data);
113 113
 
114 114
 		/**
115 115
 		 * Filter a report returned from the API.
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		 * @param object           $report   The original report object.
121 121
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
122 122
 		 */
123
-		return apply_filters( 'woocommerce_rest_prepare_report_revenue_stats', $response, $report, $request );
123
+		return apply_filters('woocommerce_rest_prepare_report_revenue_stats', $response, $report, $request);
124 124
 	}
125 125
 
126 126
 	/**
@@ -131,96 +131,96 @@  discard block
 block discarded – undo
131 131
 	public function get_item_schema() {
132 132
 		$data_values = array(
133 133
 			'gross_revenue'  => array(
134
-				'description' => __( 'Gross revenue.', 'woocommerce' ),
134
+				'description' => __('Gross revenue.', 'woocommerce'),
135 135
 				'type'        => 'number',
136
-				'context'     => array( 'view', 'edit' ),
136
+				'context'     => array('view', 'edit'),
137 137
 				'readonly'    => true,
138 138
 				'indicator'   => true,
139 139
 				'format'      => 'currency',
140 140
 			),
141 141
 			'net_revenue'    => array(
142
-				'description' => __( 'Net revenue.', 'woocommerce' ),
142
+				'description' => __('Net revenue.', 'woocommerce'),
143 143
 				'type'        => 'number',
144
-				'context'     => array( 'view', 'edit' ),
144
+				'context'     => array('view', 'edit'),
145 145
 				'readonly'    => true,
146 146
 				'indicator'   => true,
147 147
 				'format'      => 'currency',
148 148
 			),
149 149
 			'coupons'        => array(
150
-				'description' => __( 'Amount discounted by coupons.', 'woocommerce' ),
150
+				'description' => __('Amount discounted by coupons.', 'woocommerce'),
151 151
 				'type'        => 'number',
152
-				'context'     => array( 'view', 'edit' ),
152
+				'context'     => array('view', 'edit'),
153 153
 				'readonly'    => true,
154 154
 			),
155 155
 			'coupons_count'  => array(
156
-				'description' => __( 'Unique coupons count.', 'woocommerce' ),
156
+				'description' => __('Unique coupons count.', 'woocommerce'),
157 157
 				'type'        => 'number',
158
-				'context'     => array( 'view', 'edit' ),
158
+				'context'     => array('view', 'edit'),
159 159
 				'readonly'    => true,
160 160
 				'format'      => 'currency',
161 161
 			),
162 162
 			'shipping'       => array(
163
-				'description' => __( 'Total of shipping.', 'woocommerce' ),
163
+				'description' => __('Total of shipping.', 'woocommerce'),
164 164
 				'type'        => 'number',
165
-				'context'     => array( 'view', 'edit' ),
165
+				'context'     => array('view', 'edit'),
166 166
 				'readonly'    => true,
167 167
 				'indicator'   => true,
168 168
 				'format'      => 'currency',
169 169
 			),
170 170
 			'taxes'          => array(
171
-				'description' => __( 'Total of taxes.', 'woocommerce' ),
171
+				'description' => __('Total of taxes.', 'woocommerce'),
172 172
 				'type'        => 'number',
173
-				'context'     => array( 'view', 'edit' ),
173
+				'context'     => array('view', 'edit'),
174 174
 				'readonly'    => true,
175 175
 				'format'      => 'currency',
176 176
 			),
177 177
 			'refunds'        => array(
178
-				'description' => __( 'Total of refunds.', 'woocommerce' ),
178
+				'description' => __('Total of refunds.', 'woocommerce'),
179 179
 				'type'        => 'number',
180
-				'context'     => array( 'view', 'edit' ),
180
+				'context'     => array('view', 'edit'),
181 181
 				'readonly'    => true,
182 182
 				'indicator'   => true,
183 183
 				'format'      => 'currency',
184 184
 			),
185 185
 			'orders_count'   => array(
186
-				'description' => __( 'Amount of orders.', 'woocommerce' ),
186
+				'description' => __('Amount of orders.', 'woocommerce'),
187 187
 				'type'        => 'integer',
188
-				'context'     => array( 'view', 'edit' ),
188
+				'context'     => array('view', 'edit'),
189 189
 				'readonly'    => true,
190 190
 			),
191 191
 			'num_items_sold' => array(
192
-				'description' => __( 'Items sold.', 'woocommerce' ),
192
+				'description' => __('Items sold.', 'woocommerce'),
193 193
 				'type'        => 'integer',
194
-				'context'     => array( 'view', 'edit' ),
194
+				'context'     => array('view', 'edit'),
195 195
 				'readonly'    => true,
196 196
 			),
197 197
 			'products'       => array(
198
-				'description' => __( 'Products sold.', 'woocommerce' ),
198
+				'description' => __('Products sold.', 'woocommerce'),
199 199
 				'type'        => 'integer',
200
-				'context'     => array( 'view', 'edit' ),
200
+				'context'     => array('view', 'edit'),
201 201
 				'readonly'    => true,
202 202
 			),
203 203
 		);
204 204
 
205 205
 		$segments = array(
206 206
 			'segments' => array(
207
-				'description' => __( 'Reports data grouped by segment condition.', 'woocommerce' ),
207
+				'description' => __('Reports data grouped by segment condition.', 'woocommerce'),
208 208
 				'type'        => 'array',
209
-				'context'     => array( 'view', 'edit' ),
209
+				'context'     => array('view', 'edit'),
210 210
 				'readonly'    => true,
211 211
 				'items'       => array(
212 212
 					'type'       => 'object',
213 213
 					'properties' => array(
214 214
 						'segment_id' => array(
215
-							'description' => __( 'Segment identificator.', 'woocommerce' ),
215
+							'description' => __('Segment identificator.', 'woocommerce'),
216 216
 							'type'        => 'integer',
217
-							'context'     => array( 'view', 'edit' ),
217
+							'context'     => array('view', 'edit'),
218 218
 							'readonly'    => true,
219 219
 						),
220 220
 						'subtotals'  => array(
221
-							'description' => __( 'Interval subtotals.', 'woocommerce' ),
221
+							'description' => __('Interval subtotals.', 'woocommerce'),
222 222
 							'type'        => 'object',
223
-							'context'     => array( 'view', 'edit' ),
223
+							'context'     => array('view', 'edit'),
224 224
 							'readonly'    => true,
225 225
 							'properties'  => $data_values,
226 226
 						),
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
 			),
230 230
 		);
231 231
 
232
-		$totals = array_merge( $data_values, $segments );
232
+		$totals = array_merge($data_values, $segments);
233 233
 
234 234
 		// Products is not shown in intervals.
235
-		unset( $data_values['products'] );
235
+		unset($data_values['products']);
236 236
 
237
-		$intervals = array_merge( $data_values, $segments );
237
+		$intervals = array_merge($data_values, $segments);
238 238
 
239 239
 		$schema = array(
240 240
 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
@@ -242,55 +242,55 @@  discard block
 block discarded – undo
242 242
 			'type'       => 'object',
243 243
 			'properties' => array(
244 244
 				'totals'    => array(
245
-					'description' => __( 'Totals data.', 'woocommerce' ),
245
+					'description' => __('Totals data.', 'woocommerce'),
246 246
 					'type'        => 'object',
247
-					'context'     => array( 'view', 'edit' ),
247
+					'context'     => array('view', 'edit'),
248 248
 					'readonly'    => true,
249 249
 					'properties'  => $totals,
250 250
 				),
251 251
 				'intervals' => array(
252
-					'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ),
252
+					'description' => __('Reports data grouped by intervals.', 'woocommerce'),
253 253
 					'type'        => 'array',
254
-					'context'     => array( 'view', 'edit' ),
254
+					'context'     => array('view', 'edit'),
255 255
 					'readonly'    => true,
256 256
 					'items'       => array(
257 257
 						'type'       => 'object',
258 258
 						'properties' => array(
259 259
 							'interval'       => array(
260
-								'description' => __( 'Type of interval.', 'woocommerce' ),
260
+								'description' => __('Type of interval.', 'woocommerce'),
261 261
 								'type'        => 'string',
262
-								'context'     => array( 'view', 'edit' ),
262
+								'context'     => array('view', 'edit'),
263 263
 								'readonly'    => true,
264
-								'enum'        => array( 'day', 'week', 'month', 'year' ),
264
+								'enum'        => array('day', 'week', 'month', 'year'),
265 265
 							),
266 266
 							'date_start'     => array(
267
-								'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ),
267
+								'description' => __("The date the report start, in the site's timezone.", 'woocommerce'),
268 268
 								'type'        => 'date-time',
269
-								'context'     => array( 'view', 'edit' ),
269
+								'context'     => array('view', 'edit'),
270 270
 								'readonly'    => true,
271 271
 							),
272 272
 							'date_start_gmt' => array(
273
-								'description' => __( 'The date the report start, as GMT.', 'woocommerce' ),
273
+								'description' => __('The date the report start, as GMT.', 'woocommerce'),
274 274
 								'type'        => 'date-time',
275
-								'context'     => array( 'view', 'edit' ),
275
+								'context'     => array('view', 'edit'),
276 276
 								'readonly'    => true,
277 277
 							),
278 278
 							'date_end'       => array(
279
-								'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ),
279
+								'description' => __("The date the report end, in the site's timezone.", 'woocommerce'),
280 280
 								'type'        => 'date-time',
281
-								'context'     => array( 'view', 'edit' ),
281
+								'context'     => array('view', 'edit'),
282 282
 								'readonly'    => true,
283 283
 							),
284 284
 							'date_end_gmt'   => array(
285
-								'description' => __( 'The date the report end, as GMT.', 'woocommerce' ),
285
+								'description' => __('The date the report end, as GMT.', 'woocommerce'),
286 286
 								'type'        => 'date-time',
287
-								'context'     => array( 'view', 'edit' ),
287
+								'context'     => array('view', 'edit'),
288 288
 								'readonly'    => true,
289 289
 							),
290 290
 							'subtotals'      => array(
291
-								'description' => __( 'Interval subtotals.', 'woocommerce' ),
291
+								'description' => __('Interval subtotals.', 'woocommerce'),
292 292
 								'type'        => 'object',
293
-								'context'     => array( 'view', 'edit' ),
293
+								'context'     => array('view', 'edit'),
294 294
 								'readonly'    => true,
295 295
 								'properties'  => $intervals,
296 296
 							),
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 			),
301 301
 		);
302 302
 
303
-		return $this->add_additional_fields_schema( $schema );
303
+		return $this->add_additional_fields_schema($schema);
304 304
 	}
305 305
 
306 306
 	/**
@@ -310,17 +310,17 @@  discard block
 block discarded – undo
310 310
 	 */
311 311
 	public function get_collection_params() {
312 312
 		$params              = array();
313
-		$params['context']   = $this->get_context_param( array( 'default' => 'view' ) );
313
+		$params['context']   = $this->get_context_param(array('default' => 'view'));
314 314
 		$params['page']      = array(
315
-			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
315
+			'description'       => __('Current page of the collection.', 'woocommerce'),
316 316
 			'type'              => 'integer',
317 317
 			'default'           => 1,
318 318
 			'sanitize_callback' => 'absint',
319 319
 			'validate_callback' => 'rest_validate_request_arg',
320 320
 			'minimum'           => 1,
321 321
 		);
322
-		$params['per_page']  = array(
323
-			'description'       => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
322
+		$params['per_page'] = array(
323
+			'description'       => __('Maximum number of items to be returned in result set.', 'woocommerce'),
324 324
 			'type'              => 'integer',
325 325
 			'default'           => 10,
326 326
 			'minimum'           => 1,
@@ -328,27 +328,27 @@  discard block
 block discarded – undo
328 328
 			'sanitize_callback' => 'absint',
329 329
 			'validate_callback' => 'rest_validate_request_arg',
330 330
 		);
331
-		$params['after']     = array(
332
-			'description'       => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
331
+		$params['after'] = array(
332
+			'description'       => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
333 333
 			'type'              => 'string',
334 334
 			'format'            => 'date-time',
335 335
 			'validate_callback' => 'rest_validate_request_arg',
336 336
 		);
337
-		$params['before']    = array(
338
-			'description'       => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
337
+		$params['before'] = array(
338
+			'description'       => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
339 339
 			'type'              => 'string',
340 340
 			'format'            => 'date-time',
341 341
 			'validate_callback' => 'rest_validate_request_arg',
342 342
 		);
343
-		$params['order']     = array(
344
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
343
+		$params['order'] = array(
344
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
345 345
 			'type'              => 'string',
346 346
 			'default'           => 'desc',
347
-			'enum'              => array( 'asc', 'desc' ),
347
+			'enum'              => array('asc', 'desc'),
348 348
 			'validate_callback' => 'rest_validate_request_arg',
349 349
 		);
350
-		$params['orderby']   = array(
351
-			'description'       => __( 'Sort collection by object attribute.', 'woocommerce' ),
350
+		$params['orderby'] = array(
351
+			'description'       => __('Sort collection by object attribute.', 'woocommerce'),
352 352
 			'type'              => 'string',
353 353
 			'default'           => 'date',
354 354
 			'enum'              => array(
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
 			),
365 365
 			'validate_callback' => 'rest_validate_request_arg',
366 366
 		);
367
-		$params['interval']  = array(
368
-			'description'       => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
367
+		$params['interval'] = array(
368
+			'description'       => __('Time interval to use for buckets in the returned data.', 'woocommerce'),
369 369
 			'type'              => 'string',
370 370
 			'default'           => 'week',
371 371
 			'enum'              => array(
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 			'validate_callback' => 'rest_validate_request_arg',
380 380
 		);
381 381
 		$params['segmentby'] = array(
382
-			'description'       => __( 'Segment the response by additional constraint.', 'woocommerce' ),
382
+			'description'       => __('Segment the response by additional constraint.', 'woocommerce'),
383 383
 			'type'              => 'string',
384 384
 			'enum'              => array(
385 385
 				'product',
Please login to merge, or discard this patch.