Completed
Push — master ( cd04f7...8ebd9d )
by Mike
04:37
created
src/Controllers/Version4/PaymentGateways.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 			$payment_gateway->id = $payment_gateway_id;
124 124
 			$gateway             = $this->prepare_item_for_response( $payment_gateway, $request );
125 125
 			$gateway             = $this->prepare_response_for_collection( $gateway );
126
-			$response[]          = $gateway;
126
+			$response[ ]          = $gateway;
127 127
 		}
128 128
 		return rest_ensure_response( $response );
129 129
 	}
@@ -163,14 +163,14 @@  discard block
 block discarded – undo
163 163
 		$settings = $gateway->settings;
164 164
 
165 165
 		// Update settings.
166
-		if ( isset( $request['settings'] ) ) {
166
+		if ( isset( $request[ 'settings' ] ) ) {
167 167
 			$errors_found = false;
168 168
 			foreach ( $gateway->form_fields as $key => $field ) {
169
-				if ( isset( $request['settings'][ $key ] ) ) {
170
-					if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) {
171
-						$value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field );
169
+				if ( isset( $request[ 'settings' ][ $key ] ) ) {
170
+					if ( is_callable( array( $this, 'validate_setting_' . $field[ 'type' ] . '_field' ) ) ) {
171
+						$value = $this->{'validate_setting_' . $field[ 'type' ] . '_field'}( $request[ 'settings' ][ $key ], $field );
172 172
 					} else {
173
-						$value = $this->validate_setting_text_field( $request['settings'][ $key ], $field );
173
+						$value = $this->validate_setting_text_field( $request[ 'settings' ][ $key ], $field );
174 174
 					}
175 175
 					if ( is_wp_error( $value ) ) {
176 176
 						$errors_found = true;
@@ -186,21 +186,21 @@  discard block
 block discarded – undo
186 186
 		}
187 187
 
188 188
 		// Update if this method is enabled or not.
189
-		if ( isset( $request['enabled'] ) ) {
190
-			$settings['enabled'] = wc_bool_to_string( $request['enabled'] );
191
-			$gateway->enabled    = $settings['enabled'];
189
+		if ( isset( $request[ 'enabled' ] ) ) {
190
+			$settings[ 'enabled' ] = wc_bool_to_string( $request[ 'enabled' ] );
191
+			$gateway->enabled    = $settings[ 'enabled' ];
192 192
 		}
193 193
 
194 194
 		// Update title.
195
-		if ( isset( $request['title'] ) ) {
196
-			$settings['title'] = $request['title'];
197
-			$gateway->title    = $settings['title'];
195
+		if ( isset( $request[ 'title' ] ) ) {
196
+			$settings[ 'title' ] = $request[ 'title' ];
197
+			$gateway->title    = $settings[ 'title' ];
198 198
 		}
199 199
 
200 200
 		// Update description.
201
-		if ( isset( $request['description'] ) ) {
202
-			$settings['description'] = $request['description'];
203
-			$gateway->description    = $settings['description'];
201
+		if ( isset( $request[ 'description' ] ) ) {
202
+			$settings[ 'description' ] = $request[ 'description' ];
203
+			$gateway->description    = $settings[ 'description' ];
204 204
 		}
205 205
 
206 206
 		// Update options.
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 		update_option( $gateway->get_option_key(), apply_filters( 'woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway ) );
209 209
 
210 210
 		// Update order.
211
-		if ( isset( $request['order'] ) ) {
211
+		if ( isset( $request[ 'order' ] ) ) {
212 212
 			$order                 = (array) get_option( 'woocommerce_gateway_order' );
213
-			$order[ $gateway->id ] = $request['order'];
213
+			$order[ $gateway->id ] = $request[ 'order' ];
214 214
 			update_option( 'woocommerce_gateway_order', $order );
215
-			$gateway->order = absint( $request['order'] );
215
+			$gateway->order = absint( $request[ 'order' ] );
216 216
 		}
217 217
 
218 218
 		$gateway = $this->prepare_item_for_response( $gateway, $request );
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		$gateway          = null;
230 230
 		$payment_gateways = WC()->payment_gateways->payment_gateways();
231 231
 		foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) {
232
-			if ( $request['id'] !== $payment_gateway_id ) {
232
+			if ( $request[ 'id' ] !== $payment_gateway_id ) {
233 233
 				continue;
234 234
 			}
235 235
 			$payment_gateway->id = $payment_gateway_id;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 			'settings'           => $this->get_settings( $gateway ),
260 260
 		);
261 261
 
262
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
262
+		$context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view';
263 263
 		$data    = $this->add_additional_fields_to_object( $item, $request );
264 264
 		$data    = $this->filter_response_by_context( $data, $context );
265 265
 
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 		$gateway->init_form_fields();
289 289
 		foreach ( $gateway->form_fields as $id => $field ) {
290 290
 			// Make sure we at least have a title and type.
291
-			if ( empty( $field['title'] ) || empty( $field['type'] ) ) {
291
+			if ( empty( $field[ 'title' ] ) || empty( $field[ 'type' ] ) ) {
292 292
 				continue;
293 293
 			}
294 294
 
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
 
300 300
 			$data = array(
301 301
 				'id'          => $id,
302
-				'label'       => empty( $field['label'] ) ? $field['title'] : $field['label'],
303
-				'description' => empty( $field['description'] ) ? '' : $field['description'],
304
-				'type'        => $field['type'],
302
+				'label'       => empty( $field[ 'label' ] ) ? $field[ 'title' ] : $field[ 'label' ],
303
+				'description' => empty( $field[ 'description' ] ) ? '' : $field[ 'description' ],
304
+				'type'        => $field[ 'type' ],
305 305
 				'value'       => empty( $gateway->settings[ $id ] ) ? '' : $gateway->settings[ $id ],
306
-				'default'     => empty( $field['default'] ) ? '' : $field['default'],
307
-				'tip'         => empty( $field['description'] ) ? '' : $field['description'],
308
-				'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'],
306
+				'default'     => empty( $field[ 'default' ] ) ? '' : $field[ 'default' ],
307
+				'tip'         => empty( $field[ 'description' ] ) ? '' : $field[ 'description' ],
308
+				'placeholder' => empty( $field[ 'placeholder' ] ) ? '' : $field[ 'placeholder' ],
309 309
 			);
310
-			if ( ! empty( $field['options'] ) ) {
311
-				$data['options'] = $field['options'];
310
+			if ( ! empty( $field[ 'options' ] ) ) {
311
+				$data[ 'options' ] = $field[ 'options' ];
312 312
 			}
313 313
 			$settings[ $id ] = $data;
314 314
 		}
Please login to merge, or discard this patch.
src/Controllers/Version4/ProductVariations.php 1 patch
Spacing   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
 	 * @return \WP_Error|boolean
156 156
 	 */
157 157
 	public function update_item_permissions_check( $request ) {
158
-		$object = $this->get_object( (int) $request['id'] );
158
+		$object = $this->get_object( (int) $request[ 'id' ] );
159 159
 
160 160
 		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
161 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() ) {
165
+		if ( $object && 0 !== $object->get_parent_id() && absint( $request[ 'product_id' ] ) !== $object->get_parent_id() ) {
166 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
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 * @return \WP_REST_Response
178 178
 	 */
179 179
 	public function prepare_object_for_response( $object, $request ) {
180
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
180
+		$context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view';
181 181
 		$data    = array(
182 182
 			'id'                    => $object->get_id(),
183 183
 			'name'                  => $object->get_name( $context ),
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 			'meta_data'             => $object->get_meta_data(),
228 228
 		);
229 229
 
230
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
230
+		$context  = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view';
231 231
 		$data     = $this->add_additional_fields_to_object( $data, $request );
232 232
 		$data     = $this->filter_response_by_context( $data, $context );
233 233
 		$response = rest_ensure_response( $data );
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
 	 * @return WC_Product_Variation
293 293
 	 */
294 294
 	protected function set_variation_image( $variation, $image ) {
295
-		$attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
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 300
 			if ( is_wp_error( $upload ) ) {
301 301
 				if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array( $image ) ) ) {
@@ -314,16 +314,16 @@  discard block
 block discarded – undo
314 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,
326
-					'post_title' => $image['name'],
326
+					'post_title' => $image[ 'name' ],
327 327
 				)
328 328
 			);
329 329
 		}
@@ -342,17 +342,17 @@  discard block
 block discarded – undo
342 342
 		$args = parent::prepare_objects_query( $request );
343 343
 
344 344
 		// Set post_status.
345
-		$args['post_status'] = $request['status'];
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 351
 			if ( 1 < count( $skus ) ) {
352
-				$skus[] = $request['sku'];
352
+				$skus[ ] = $request[ 'sku' ];
353 353
 			}
354 354
 
355
-			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
355
+			$args[ 'meta_query' ] = $this->add_meta_query( // WPCS: slow query ok.
356 356
 				$args,
357 357
 				array(
358 358
 					'key'     => '_sku',
@@ -363,35 +363,35 @@  discard block
 block discarded – undo
363 363
 		}
364 364
 
365 365
 		// Filter by tax class.
366
-		if ( ! empty( $request['tax_class'] ) ) {
367
-			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
366
+		if ( ! empty( $request[ 'tax_class' ] ) ) {
367
+			$args[ 'meta_query' ] = $this->add_meta_query( // WPCS: slow query ok.
368 368
 				$args,
369 369
 				array(
370 370
 					'key'   => '_tax_class',
371
-					'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '',
371
+					'value' => 'standard' !== $request[ 'tax_class' ] ? $request[ 'tax_class' ] : '',
372 372
 				)
373 373
 			);
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'] ) ) {
383
-			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
382
+		if ( ! empty( $request[ 'stock_status' ] ) ) {
383
+			$args[ 'meta_query' ] = $this->add_meta_query( // WPCS: slow query ok.
384 384
 				$args,
385 385
 				array(
386 386
 					'key'   => '_stock_status',
387
-					'value' => $request['stock_status'],
387
+					'value' => $request[ 'stock_status' ],
388 388
 				)
389 389
 			);
390 390
 		}
391 391
 
392 392
 		// Filter by on sale products.
393
-		if ( is_bool( $request['on_sale'] ) ) {
394
-			$on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in';
393
+		if ( is_bool( $request[ 'on_sale' ] ) ) {
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.
@@ -401,17 +401,17 @@  discard block
 block discarded – undo
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
-			$args['post_type'] = $this->post_type;
407
+			$args[ 'post_type' ] = $this->post_type;
408 408
 		}
409 409
 
410
-		$args['post_parent'] = $request['product_id'];
410
+		$args[ 'post_parent' ] = $request[ 'product_id' ];
411 411
 
412
-		if ( ! empty( $request['search'] ) ) {
413
-			$args['search'] = $request['search'];
414
-			unset( $args['s'] );
412
+		if ( ! empty( $request[ 'search' ] ) ) {
413
+			$args[ 'search' ] = $request[ 'search' ];
414
+			unset( $args[ 's' ] );
415 415
 		}
416 416
 
417 417
 		return $args;
@@ -425,58 +425,58 @@  discard block
 block discarded – undo
425 425
 	 * @return \WP_Error|WC_Data
426 426
 	 */
427 427
 	protected function prepare_object_for_database( $request, $creating = false ) {
428
-		if ( isset( $request['id'] ) ) {
429
-			$variation = wc_get_product( absint( $request['id'] ) );
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 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 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
 
@@ -484,24 +484,24 @@  discard block
 block discarded – undo
484 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 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'] ) ) {
500
+			if ( isset( $request[ 'stock_quantity' ] ) ) {
501
+				$variation->set_stock_quantity( $request[ 'stock_quantity' ] );
502
+			} elseif ( isset( $request[ 'inventory_delta' ] ) ) {
503 503
 				$stock_quantity  = wc_stock_amount( $variation->get_stock_quantity() );
504
-				$stock_quantity += wc_stock_amount( $request['inventory_delta'] );
504
+				$stock_quantity += wc_stock_amount( $request[ 'inventory_delta' ] );
505 505
 				$variation->set_stock_quantity( $stock_quantity );
506 506
 			}
507 507
 		} else {
@@ -510,43 +510,43 @@  discard block
 block discarded – undo
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 551
 			$parent     = wc_get_product( $variation->get_parent_id() );
552 552
 
@@ -561,16 +561,16 @@  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'] );
569
+				if ( ! empty( $attribute[ 'id' ] ) ) {
570
+					$attribute_id   = absint( $attribute[ 'id' ] );
571 571
 					$attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id );
572
-				} elseif ( ! empty( $attribute['name'] ) ) {
573
-					$attribute_name = sanitize_title( $attribute['name'] );
572
+				} elseif ( ! empty( $attribute[ 'name' ] ) ) {
573
+					$attribute_name = sanitize_title( $attribute[ 'name' ] );
574 574
 				}
575 575
 
576 576
 				if ( ! $attribute_id && ! $attribute_name ) {
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 				}
583 583
 
584 584
 				$attribute_key   = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() );
585
-				$attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : '';
585
+				$attribute_value = isset( $attribute[ 'option' ] ) ? wc_clean( stripslashes( $attribute[ 'option' ] ) ) : '';
586 586
 
587 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.
@@ -602,14 +602,14 @@  discard block
 block discarded – undo
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
 
@@ -644,8 +644,8 @@  discard block
 block discarded – undo
644 644
 	 * @return bool|\WP_Error\WP_REST_Response
645 645
 	 */
646 646
 	public function delete_item( $request ) {
647
-		$force  = (bool) $request['force'];
648
-		$object = $this->get_object( (int) $request['id'] );
647
+		$force  = (bool) $request[ 'force' ];
648
+		$object = $this->get_object( (int) $request[ 'id' ] );
649 649
 		$result = false;
650 650
 
651 651
 		if ( ! $object || 0 === $object->get_id() ) {
@@ -753,14 +753,14 @@  discard block
 block discarded – undo
753 753
 	public function batch_items( $request ) {
754 754
 		$items       = array_filter( $request->get_params() );
755 755
 		$params      = $request->get_url_params();
756
-		$product_id  = $params['product_id'];
756
+		$product_id  = $params[ 'product_id' ];
757 757
 		$body_params = array();
758 758
 
759 759
 		foreach ( array( 'update', 'create', 'delete' ) as $batch_type ) {
760 760
 			if ( ! empty( $items[ $batch_type ] ) ) {
761 761
 				$injected_items = array();
762 762
 				foreach ( $items[ $batch_type ] as $item ) {
763
-					$injected_items[] = is_array( $item ) ? array_merge(
763
+					$injected_items[ ] = is_array( $item ) ? array_merge(
764 764
 						array(
765 765
 							'product_id' => $product_id,
766 766
 						), $item
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
 	 * @return array                   Links for the given post.
785 785
 	 */
786 786
 	protected function prepare_links( $object, $request ) {
787
-		$product_id = (int) $request['product_id'];
787
+		$product_id = (int) $request[ 'product_id' ];
788 788
 		$base       = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base );
789 789
 		$links      = array(
790 790
 			'self'       => array(
@@ -1182,17 +1182,17 @@  discard block
 block discarded – undo
1182 1182
 		$params = parent::get_collection_params();
1183 1183
 
1184 1184
 		unset(
1185
-			$params['in_stock'],
1186
-			$params['type'],
1187
-			$params['featured'],
1188
-			$params['category'],
1189
-			$params['tag'],
1190
-			$params['shipping_class'],
1191
-			$params['attribute'],
1192
-			$params['attribute_term']
1185
+			$params[ 'in_stock' ],
1186
+			$params[ 'type' ],
1187
+			$params[ 'featured' ],
1188
+			$params[ 'category' ],
1189
+			$params[ 'tag' ],
1190
+			$params[ 'shipping_class' ],
1191
+			$params[ 'attribute' ],
1192
+			$params[ 'attribute_term' ]
1193 1193
 		);
1194 1194
 
1195
-		$params['stock_status'] = array(
1195
+		$params[ 'stock_status' ] = array(
1196 1196
 			'description'       => __( 'Limit result set to products with specified stock status.', 'woocommerce' ),
1197 1197
 			'type'              => 'string',
1198 1198
 			'enum'              => array_keys( wc_get_product_stock_status_options() ),
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 			'validate_callback' => 'rest_validate_request_arg',
1201 1201
 		);
1202 1202
 
1203
-		$params['search'] = array(
1203
+		$params[ 'search' ] = array(
1204 1204
 			'description'       => __( 'Search by similar product name or sku.', 'woocommerce' ),
1205 1205
 			'type'              => 'string',
1206 1206
 			'validate_callback' => 'rest_validate_request_arg',
Please login to merge, or discard this patch.
src/Controllers/Version4/Data/Currencies.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		foreach ( array_keys( $currencies ) as $code ) {
109 109
 			$currency = $this->get_currency( $code, $request );
110 110
 			$response = $this->prepare_item_for_response( $currency, $request );
111
-			$data[]   = $this->prepare_response_for_collection( $response );
111
+			$data[ ]   = $this->prepare_response_for_collection( $response );
112 112
 		}
113 113
 
114 114
 		return rest_ensure_response( $data );
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @return \WP_Error\WP_REST_Response
122 122
 	 */
123 123
 	public function get_item( $request ) {
124
-		$data = $this->get_currency( strtoupper( $request['currency'] ), $request );
124
+		$data = $this->get_currency( strtoupper( $request[ 'currency' ] ), $request );
125 125
 		if ( empty( $data ) ) {
126 126
 			return new \WP_Error( 'woocommerce_rest_data_invalid_currency', __( 'There are no currencies matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
127 127
 		}
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return array Links for the given currency.
171 171
 	 */
172 172
 	protected function prepare_links( $item ) {
173
-		$code  = strtoupper( $item['code'] );
173
+		$code  = strtoupper( $item[ 'code' ] );
174 174
 		$links = array(
175 175
 			'self'       => array(
176 176
 				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $code ) ),
Please login to merge, or discard this patch.
src/Controllers/Version4/Data/DownloadIPs.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 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
62 62
 					WHERE user_ip_address LIKE %s
63 63
 					LIMIT 10",
64
-					$request['match'] . '%'
64
+					$request[ 'match' ] . '%'
65 65
 				)
66 66
 			);
67 67
 		} else {
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		if ( ! empty( $downloads ) ) {
74 74
 			foreach ( $downloads as $download ) {
75 75
 				$response = $this->prepare_item_for_response( $download, $request );
76
-				$data[]   = $this->prepare_response_for_collection( $response );
76
+				$data[ ]   = $this->prepare_response_for_collection( $response );
77 77
 			}
78 78
 		}
79 79
 
@@ -127,8 +127,8 @@  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' ) );
131
-		$params['match']   = array(
130
+		$params[ 'context' ] = $this->get_context_param( array( 'default' => 'view' ) );
131
+		$params[ 'match' ]   = array(
132 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',
Please login to merge, or discard this patch.
src/Controllers/Version4/Data/Countries.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
 		$local_states = array();
88 88
 		if ( isset( $states[ $country_code ] ) ) {
89 89
 			foreach ( $states[ $country_code ] as $state_code => $state_name ) {
90
-				$local_states[] = array(
90
+				$local_states[ ] = array(
91 91
 					'code' => $state_code,
92 92
 					'name' => $state_name,
93 93
 				);
94 94
 			}
95 95
 		}
96
-		$country['states'] = $local_states;
96
+		$country[ 'states' ] = $local_states;
97 97
 		return $country;
98 98
 	}
99 99
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		foreach ( array_keys( $countries ) as $country_code ) {
112 112
 			$country  = $this->get_country( $country_code, $request );
113 113
 			$response = $this->prepare_item_for_response( $country, $request );
114
-			$data[]   = $this->prepare_response_for_collection( $response );
114
+			$data[ ]   = $this->prepare_response_for_collection( $response );
115 115
 		}
116 116
 
117 117
 		return rest_ensure_response( $data );
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 * @return \WP_Error\WP_REST_Response
126 126
 	 */
127 127
 	public function get_item( $request ) {
128
-		$data = $this->get_country( strtoupper( $request['location'] ), $request );
128
+		$data = $this->get_country( strtoupper( $request[ 'location' ] ), $request );
129 129
 		if ( empty( $data ) ) {
130 130
 			return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
131 131
 		}
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 * @return array Links for the given country.
167 167
 	 */
168 168
 	protected function prepare_links( $item ) {
169
-		$country_code = strtolower( $item['code'] );
169
+		$country_code = strtolower( $item[ 'code' ] );
170 170
 		$links        = array(
171 171
 			'self'       => array(
172 172
 				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $country_code ) ),
Please login to merge, or discard this patch.
src/Controllers/Version4/Data/Continents.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 
87 87
 		$continent = array(
88 88
 			'code' => $continent_code,
89
-			'name' => $continent_list['name'],
89
+			'name' => $continent_list[ 'name' ],
90 90
 		);
91 91
 
92 92
 		$local_countries = array();
93
-		foreach ( $continent_list['countries'] as $country_code ) {
93
+		foreach ( $continent_list[ 'countries' ] as $country_code ) {
94 94
 			if ( isset( $countries[ $country_code ] ) ) {
95 95
 				$country = array(
96 96
 					'code' => $country_code,
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 				$local_states = array();
120 120
 				if ( isset( $states[ $country_code ] ) ) {
121 121
 					foreach ( $states[ $country_code ] as $state_code => $state_name ) {
122
-						$local_states[] = array(
122
+						$local_states[ ] = array(
123 123
 							'code' => $state_code,
124 124
 							'name' => $state_name,
125 125
 						);
126 126
 					}
127 127
 				}
128
-				$country['states'] = $local_states;
128
+				$country[ 'states' ] = $local_states;
129 129
 
130 130
 				// Allow only desired keys (e.g. filter out tax rates).
131 131
 				$allowed = array(
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 				);
143 143
 				$country = array_intersect_key( $country, array_flip( $allowed ) );
144 144
 
145
-				$local_countries[] = $country;
145
+				$local_countries[ ] = $country;
146 146
 			}
147 147
 		}
148 148
 
149
-		$continent['countries'] = $local_countries;
149
+		$continent[ 'countries' ] = $local_countries;
150 150
 		return $continent;
151 151
 	}
152 152
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 		foreach ( array_keys( $continents ) as $continent_code ) {
165 165
 			$continent = $this->get_continent( $continent_code, $request );
166 166
 			$response  = $this->prepare_item_for_response( $continent, $request );
167
-			$data[]    = $this->prepare_response_for_collection( $response );
167
+			$data[ ]    = $this->prepare_response_for_collection( $response );
168 168
 		}
169 169
 
170 170
 		return rest_ensure_response( $data );
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @return \WP_Error|\WP_REST_Response
179 179
 	 */
180 180
 	public function get_item( $request ) {
181
-		$data = $this->get_continent( strtoupper( $request['location'] ), $request );
181
+		$data = $this->get_continent( strtoupper( $request[ 'location' ] ), $request );
182 182
 		if ( empty( $data ) ) {
183 183
 			return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
184 184
 		}
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 * @return array Links for the given continent.
220 220
 	 */
221 221
 	protected function prepare_links( $item ) {
222
-		$continent_code = strtolower( $item['code'] );
222
+		$continent_code = strtolower( $item[ 'code' ] );
223 223
 		$links          = array(
224 224
 			'self'       => array(
225 225
 				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code ) ),
Please login to merge, or discard this patch.
src/Controllers/Version4/NetworkOrders.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -46,31 +46,31 @@  discard block
 block discarded – undo
46 46
 	public function get_public_item_schema() {
47 47
 		$schema = parent::get_public_item_schema();
48 48
 
49
-		$schema['properties']['blog']              = array(
49
+		$schema[ 'properties' ][ 'blog' ] = array(
50 50
 			'description' => __( 'Blog id of the record on the multisite.', 'woocommerce' ),
51 51
 			'type'        => 'integer',
52 52
 			'context'     => array( 'view' ),
53 53
 			'readonly'    => true,
54 54
 		);
55
-		$schema['properties']['edit_url']          = array(
55
+		$schema[ 'properties' ][ 'edit_url' ] = array(
56 56
 			'description' => __( 'URL to edit the order', 'woocommerce' ),
57 57
 			'type'        => 'string',
58 58
 			'context'     => array( 'view' ),
59 59
 			'readonly'    => true,
60 60
 		);
61
-		$schema['properties']['customer'][]        = array(
61
+		$schema[ 'properties' ][ 'customer' ][ ] = array(
62 62
 			'description' => __( 'Name of the customer for the order', 'woocommerce' ),
63 63
 			'type'        => 'string',
64 64
 			'context'     => array( 'view' ),
65 65
 			'readonly'    => true,
66 66
 		);
67
-		$schema['properties']['status_name'][]     = array(
67
+		$schema[ 'properties' ][ 'status_name' ][ ] = array(
68 68
 			'description' => __( 'Order Status', 'woocommerce' ),
69 69
 			'type'        => 'string',
70 70
 			'context'     => array( 'view' ),
71 71
 			'readonly'    => true,
72 72
 		);
73
-		$schema['properties']['formatted_total'][] = array(
73
+		$schema[ 'properties' ][ 'formatted_total' ][ ] = array(
74 74
 			'description' => __( 'Order total formatted for locale', 'woocommerce' ),
75 75
 			'type'        => 'string',
76 76
 			'context'     => array( 'view' ),
@@ -133,14 +133,14 @@  discard block
 block discarded – undo
133 133
 		remove_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) );
134 134
 
135 135
 		foreach ( $items->data as &$current_order ) {
136
-			$order = wc_get_order( $current_order['id'] );
136
+			$order = wc_get_order( $current_order[ 'id' ] );
137 137
 
138
-			$current_order['blog']     = get_blog_details( get_current_blog_id() );
139
-			$current_order['edit_url'] = get_admin_url( $blog_id, 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' );
138
+			$current_order[ 'blog' ]     = get_blog_details( get_current_blog_id() );
139
+			$current_order[ 'edit_url' ] = get_admin_url( $blog_id, 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' );
140 140
 			/* translators: 1: first name 2: last name */
141
-			$current_order['customer']        = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) );
142
-			$current_order['status_name']     = wc_get_order_status_name( $order->get_status() );
143
-			$current_order['formatted_total'] = $order->get_formatted_order_total();
141
+			$current_order[ 'customer' ]        = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) );
142
+			$current_order[ 'status_name' ]     = wc_get_order_status_name( $order->get_status() );
143
+			$current_order[ 'formatted_total' ] = $order->get_formatted_order_total();
144 144
 		}
145 145
 
146 146
 		restore_current_blog();
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 * @return array
157 157
 	 */
158 158
 	public function network_orders_filter_args( $args ) {
159
-		$args['post_status'] = array(
159
+		$args[ 'post_status' ] = array(
160 160
 			'wc-on-hold',
161 161
 			'wc-processing',
162 162
 		);
Please login to merge, or discard this patch.
src/Controllers/Version4/AbstractObjectsController.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @return \WP_Error|boolean
61 61
 	 */
62 62
 	public function get_item_permissions_check( $request ) {
63
-		$object = $this->get_object( (int) $request['id'] );
63
+		$object = $this->get_object( (int) $request[ 'id' ] );
64 64
 
65 65
 		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) {
66 66
 			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @return \WP_Error|boolean
91 91
 	 */
92 92
 	public function update_item_permissions_check( $request ) {
93
-		$object = $this->get_object( (int) $request['id'] );
93
+		$object = $this->get_object( (int) $request[ 'id' ] );
94 94
 
95 95
 		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
96 96
 			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return bool|\WP_Error
107 107
 	 */
108 108
 	public function delete_item_permissions_check( $request ) {
109
-		$object = $this->get_object( (int) $request['id'] );
109
+		$object = $this->get_object( (int) $request[ 'id' ] );
110 110
 
111 111
 		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
112 112
 			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	 * @return \WP_Error|\WP_REST_Response
174 174
 	 */
175 175
 	public function get_item( $request ) {
176
-		$object = $this->get_object( (int) $request['id'] );
176
+		$object = $this->get_object( (int) $request[ 'id' ] );
177 177
 
178 178
 		if ( ! $object || 0 === $object->get_id() ) {
179 179
 			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 * @return \WP_Error|\WP_REST_Response
219 219
 	 */
220 220
 	public function create_item( $request ) {
221
-		if ( ! empty( $request['id'] ) ) {
221
+		if ( ! empty( $request[ 'id' ] ) ) {
222 222
 			/* translators: %s: post type */
223 223
 			return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
224 224
 		}
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	 * @return \WP_Error|\WP_REST_Response
265 265
 	 */
266 266
 	public function update_item( $request ) {
267
-		$object = $this->get_object( (int) $request['id'] );
267
+		$object = $this->get_object( (int) $request[ 'id' ] );
268 268
 
269 269
 		if ( ! $object || 0 === $object->get_id() ) {
270 270
 			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
@@ -307,42 +307,42 @@  discard block
 block discarded – undo
307 307
 	 */
308 308
 	protected function prepare_objects_query( $request ) {
309 309
 		$args                        = array();
310
-		$args['offset']              = $request['offset'];
311
-		$args['order']               = $request['order'];
312
-		$args['orderby']             = $request['orderby'];
313
-		$args['paged']               = $request['page'];
314
-		$args['post__in']            = $request['include'];
315
-		$args['post__not_in']        = $request['exclude'];
316
-		$args['posts_per_page']      = $request['per_page'];
317
-		$args['name']                = $request['slug'];
318
-		$args['post_parent__in']     = $request['parent'];
319
-		$args['post_parent__not_in'] = $request['parent_exclude'];
320
-		$args['s']                   = $request['search'];
321
-		$args['fields']              = 'ids';
322
-
323
-		if ( 'date' === $args['orderby'] ) {
324
-			$args['orderby'] = 'date ID';
310
+		$args[ 'offset' ]              = $request[ 'offset' ];
311
+		$args[ 'order' ]               = $request[ 'order' ];
312
+		$args[ 'orderby' ]             = $request[ 'orderby' ];
313
+		$args[ 'paged' ]               = $request[ 'page' ];
314
+		$args[ 'post__in' ]            = $request[ 'include' ];
315
+		$args[ 'post__not_in' ]        = $request[ 'exclude' ];
316
+		$args[ 'posts_per_page' ]      = $request[ 'per_page' ];
317
+		$args[ 'name' ]                = $request[ 'slug' ];
318
+		$args[ 'post_parent__in' ]     = $request[ 'parent' ];
319
+		$args[ 'post_parent__not_in' ] = $request[ 'parent_exclude' ];
320
+		$args[ 's' ]                   = $request[ 'search' ];
321
+		$args[ 'fields' ]              = 'ids';
322
+
323
+		if ( 'date' === $args[ 'orderby' ] ) {
324
+			$args[ 'orderby' ] = 'date ID';
325 325
 		}
326 326
 
327
-		$args['date_query'] = array();
327
+		$args[ 'date_query' ] = array();
328 328
 
329 329
 		// Set before into date query. Date query must be specified as an array of an array.
330
-		if ( isset( $request['before'] ) ) {
331
-			$args['date_query'][0]['before'] = $request['before'];
330
+		if ( isset( $request[ 'before' ] ) ) {
331
+			$args[ 'date_query' ][ 0 ][ 'before' ] = $request[ 'before' ];
332 332
 		}
333 333
 
334 334
 		// Set after into date query. Date query must be specified as an array of an array.
335
-		if ( isset( $request['after'] ) ) {
336
-			$args['date_query'][0]['after'] = $request['after'];
335
+		if ( isset( $request[ 'after' ] ) ) {
336
+			$args[ 'date_query' ][ 0 ][ 'after' ] = $request[ 'after' ];
337 337
 		}
338 338
 
339 339
 		// Set date query colummn. Defaults to post_date.
340
-		if ( isset( $request['date_column'] ) && ! empty( $args['date_query'][0] ) ) {
341
-			$args['date_query'][0]['column'] = 'post_' . $request['date_column'];
340
+		if ( isset( $request[ 'date_column' ] ) && ! empty( $args[ 'date_query' ][ 0 ] ) ) {
341
+			$args[ 'date_query' ][ 0 ][ 'column' ] = 'post_' . $request[ 'date_column' ];
342 342
 		}
343 343
 
344 344
 		// Force the post_type argument, since it's not a user input variable.
345
-		$args['post_type'] = $this->post_type;
345
+		$args[ 'post_type' ] = $this->post_type;
346 346
 
347 347
 		/**
348 348
 		 * Filter the query arguments for a request.
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 		$total_posts = $query->found_posts;
373 373
 		if ( $total_posts < 1 ) {
374 374
 			// Out-of-bounds, run the query again without LIMIT for total count.
375
-			unset( $query_args['paged'] );
375
+			unset( $query_args[ 'paged' ] );
376 376
 			$count_query = new \WP_Query();
377 377
 			$count_query->query( $query_args );
378 378
 			$total_posts = $count_query->found_posts;
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 		return array(
382 382
 			'objects' => array_map( array( $this, 'get_object' ), $result ),
383 383
 			'total'   => (int) $total_posts,
384
-			'pages'   => (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ),
384
+			'pages'   => (int) ceil( $total_posts / (int) $query->query_vars[ 'posts_per_page' ] ),
385 385
 		);
386 386
 	}
387 387
 
@@ -396,20 +396,20 @@  discard block
 block discarded – undo
396 396
 		$query_results = $this->get_objects( $query_args );
397 397
 
398 398
 		$objects = array();
399
-		foreach ( $query_results['objects'] as $object ) {
399
+		foreach ( $query_results[ 'objects' ] as $object ) {
400 400
 			if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) {
401 401
 				continue;
402 402
 			}
403 403
 
404 404
 			$data      = $this->prepare_object_for_response( $object, $request );
405
-			$objects[] = $this->prepare_response_for_collection( $data );
405
+			$objects[ ] = $this->prepare_response_for_collection( $data );
406 406
 		}
407 407
 
408
-		$page      = (int) $query_args['paged'];
409
-		$max_pages = $query_results['pages'];
408
+		$page      = (int) $query_args[ 'paged' ];
409
+		$max_pages = $query_results[ 'pages' ];
410 410
 
411 411
 		$response = rest_ensure_response( $objects );
412
-		$response->header( 'X-WP-Total', $query_results['total'] );
412
+		$response->header( 'X-WP-Total', $query_results[ 'total' ] );
413 413
 		$response->header( 'X-WP-TotalPages', (int) $max_pages );
414 414
 
415 415
 		$base          = $this->rest_base;
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
 			preg_match( '/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE );
420 420
 			foreach ( $attrib_names as $attrib_name_match ) {
421 421
 				$beginning_offset = strlen( $attrib_prefix );
422
-				$attrib_name_end  = strpos( $attrib_name_match[0], '>', $attrib_name_match[1] );
423
-				$attrib_name      = substr( $attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset );
422
+				$attrib_name_end  = strpos( $attrib_name_match[ 0 ], '>', $attrib_name_match[ 1 ] );
423
+				$attrib_name      = substr( $attrib_name_match[ 0 ], $beginning_offset, $attrib_name_end - $beginning_offset );
424 424
 				if ( isset( $request[ $attrib_name ] ) ) {
425 425
 					$base = str_replace( "(?P<$attrib_name>[\d]+)", $request[ $attrib_name ], $base );
426 426
 				}
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
 	 * @return \WP_REST_Response|\WP_Error
453 453
 	 */
454 454
 	public function delete_item( $request ) {
455
-		$force  = (bool) $request['force'];
456
-		$object = $this->get_object( (int) $request['id'] );
455
+		$force  = (bool) $request[ 'force' ];
456
+		$object = $this->get_object( (int) $request[ 'id' ] );
457 457
 		$result = false;
458 458
 
459 459
 		if ( ! $object || 0 === $object->get_id() ) {
@@ -563,10 +563,10 @@  discard block
 block discarded – undo
563 563
 	 */
564 564
 	public function get_collection_params() {
565 565
 		$params                       = array();
566
-		$params['context']            = $this->get_context_param();
567
-		$params['context']['default'] = 'view';
566
+		$params[ 'context' ]            = $this->get_context_param();
567
+		$params[ 'context' ][ 'default' ] = 'view';
568 568
 
569
-		$params['page'] = array(
569
+		$params[ 'page' ] = array(
570 570
 			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
571 571
 			'type'              => 'integer',
572 572
 			'default'           => 1,
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
 			'minimum'           => 1,
576 576
 		);
577 577
 
578
-		$params['per_page'] = array(
578
+		$params[ 'per_page' ] = array(
579 579
 			'description'       => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
580 580
 			'type'              => 'integer',
581 581
 			'default'           => 10,
@@ -585,28 +585,28 @@  discard block
 block discarded – undo
585 585
 			'validate_callback' => 'rest_validate_request_arg',
586 586
 		);
587 587
 
588
-		$params['search'] = array(
588
+		$params[ 'search' ] = array(
589 589
 			'description'       => __( 'Limit results to those matching a string.', 'woocommerce' ),
590 590
 			'type'              => 'string',
591 591
 			'sanitize_callback' => 'sanitize_text_field',
592 592
 			'validate_callback' => 'rest_validate_request_arg',
593 593
 		);
594 594
 
595
-		$params['after'] = array(
595
+		$params[ 'after' ] = array(
596 596
 			'description'       => __( 'Limit response to resources created after a given ISO8601 compliant date.', 'woocommerce' ),
597 597
 			'type'              => 'string',
598 598
 			'format'            => 'date-time',
599 599
 			'validate_callback' => 'rest_validate_request_arg',
600 600
 		);
601 601
 
602
-		$params['before'] = array(
602
+		$params[ 'before' ] = array(
603 603
 			'description'       => __( 'Limit response to resources created before a given ISO8601 compliant date.', 'woocommerce' ),
604 604
 			'type'              => 'string',
605 605
 			'format'            => 'date-time',
606 606
 			'validate_callback' => 'rest_validate_request_arg',
607 607
 		);
608 608
 
609
-		$params['date_column'] = array(
609
+		$params[ 'date_column' ] = array(
610 610
 			'description'       => __( 'When limiting response using after/before, which date column to compare against.', 'woocommerce' ),
611 611
 			'type'              => 'string',
612 612
 			'default'           => 'date',
@@ -619,14 +619,14 @@  discard block
 block discarded – undo
619 619
 			'validate_callback' => 'rest_validate_request_arg',
620 620
 		);
621 621
 
622
-		$params['modified_before'] = array(
622
+		$params[ 'modified_before' ] = array(
623 623
 			'description'       => __( 'Limit response to resources modified before a given ISO8601 compliant date.', 'woocommerce' ),
624 624
 			'type'              => 'string',
625 625
 			'format'            => 'date-time',
626 626
 			'validate_callback' => 'rest_validate_request_arg',
627 627
 		);
628 628
 
629
-		$params['exclude'] = array(
629
+		$params[ 'exclude' ] = array(
630 630
 			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
631 631
 			'type'              => 'array',
632 632
 			'items'             => array(
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 			'sanitize_callback' => 'wp_parse_id_list',
637 637
 		);
638 638
 
639
-		$params['include'] = array(
639
+		$params[ 'include' ] = array(
640 640
 			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
641 641
 			'type'              => 'array',
642 642
 			'items'             => array(
@@ -646,14 +646,14 @@  discard block
 block discarded – undo
646 646
 			'sanitize_callback' => 'wp_parse_id_list',
647 647
 		);
648 648
 
649
-		$params['offset'] = array(
649
+		$params[ 'offset' ] = array(
650 650
 			'description'       => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
651 651
 			'type'              => 'integer',
652 652
 			'sanitize_callback' => 'absint',
653 653
 			'validate_callback' => 'rest_validate_request_arg',
654 654
 		);
655 655
 
656
-		$params['order'] = array(
656
+		$params[ 'order' ] = array(
657 657
 			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
658 658
 			'type'              => 'string',
659 659
 			'default'           => 'desc',
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
 			'validate_callback' => 'rest_validate_request_arg',
662 662
 		);
663 663
 
664
-		$params['orderby'] = array(
664
+		$params[ 'orderby' ] = array(
665 665
 			'description'       => __( 'Sort collection by object attribute.', 'woocommerce' ),
666 666
 			'type'              => 'string',
667 667
 			'default'           => 'date',
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
 		);
678 678
 
679 679
 		if ( $this->hierarchical ) {
680
-			$params['parent'] = array(
680
+			$params[ 'parent' ] = array(
681 681
 				'description'       => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
682 682
 				'type'              => 'array',
683 683
 				'items'             => array(
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 				'default'           => array(),
688 688
 			);
689 689
 
690
-			$params['parent_exclude'] = array(
690
+			$params[ 'parent_exclude' ] = array(
691 691
 				'description'       => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
692 692
 				'type'              => 'array',
693 693
 				'items'             => array(
@@ -738,14 +738,14 @@  discard block
 block discarded – undo
738 738
 			}
739 739
 		}
740 740
 
741
-		$query_args['ignore_sticky_posts'] = true;
741
+		$query_args[ 'ignore_sticky_posts' ] = true;
742 742
 
743
-		if ( 'include' === $query_args['orderby'] ) {
744
-			$query_args['orderby'] = 'post__in';
745
-		} elseif ( 'id' === $query_args['orderby'] ) {
746
-			$query_args['orderby'] = 'ID'; // ID must be capitalized.
747
-		} elseif ( 'slug' === $query_args['orderby'] ) {
748
-			$query_args['orderby'] = 'name';
743
+		if ( 'include' === $query_args[ 'orderby' ] ) {
744
+			$query_args[ 'orderby' ] = 'post__in';
745
+		} elseif ( 'id' === $query_args[ 'orderby' ] ) {
746
+			$query_args[ 'orderby' ] = 'ID'; // ID must be capitalized.
747
+		} elseif ( 'slug' === $query_args[ 'orderby' ] ) {
748
+			$query_args[ 'orderby' ] = 'name';
749 749
 		}
750 750
 
751 751
 		return $query_args;
Please login to merge, or discard this patch.
src/Controllers/Version4/AbstractTermsContoller.php 1 patch
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 		}
249 249
 
250 250
 		// Check permissions for a single term.
251
-		$id = intval( $request['id'] );
251
+		$id = intval( $request[ 'id' ] );
252 252
 		if ( $id ) {
253 253
 			$term = get_term( $id, $taxonomy );
254 254
 
@@ -271,32 +271,32 @@  discard block
 block discarded – undo
271 271
 	public function get_items( $request ) {
272 272
 		$taxonomy      = $this->get_taxonomy( $request );
273 273
 		$prepared_args = array(
274
-			'exclude'    => $request['exclude'],
275
-			'include'    => $request['include'],
276
-			'order'      => $request['order'],
277
-			'orderby'    => $request['orderby'],
278
-			'product'    => $request['product'],
279
-			'hide_empty' => $request['hide_empty'],
280
-			'number'     => $request['per_page'],
281
-			'search'     => $request['search'],
282
-			'slug'       => $request['slug'],
274
+			'exclude'    => $request[ 'exclude' ],
275
+			'include'    => $request[ 'include' ],
276
+			'order'      => $request[ 'order' ],
277
+			'orderby'    => $request[ 'orderby' ],
278
+			'product'    => $request[ 'product' ],
279
+			'hide_empty' => $request[ 'hide_empty' ],
280
+			'number'     => $request[ 'per_page' ],
281
+			'search'     => $request[ 'search' ],
282
+			'slug'       => $request[ 'slug' ],
283 283
 		);
284 284
 
285
-		if ( ! empty( $request['offset'] ) ) {
286
-			$prepared_args['offset'] = $request['offset'];
285
+		if ( ! empty( $request[ 'offset' ] ) ) {
286
+			$prepared_args[ 'offset' ] = $request[ 'offset' ];
287 287
 		} else {
288
-			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
288
+			$prepared_args[ 'offset' ] = ( $request[ 'page' ] - 1 ) * $prepared_args[ 'number' ];
289 289
 		}
290 290
 
291 291
 		$taxonomy_obj = get_taxonomy( $taxonomy );
292 292
 
293
-		if ( $taxonomy_obj->hierarchical && isset( $request['parent'] ) ) {
294
-			if ( 0 === $request['parent'] ) {
293
+		if ( $taxonomy_obj->hierarchical && isset( $request[ 'parent' ] ) ) {
294
+			if ( 0 === $request[ 'parent' ] ) {
295 295
 				// Only query top-level terms.
296
-				$prepared_args['parent'] = 0;
296
+				$prepared_args[ 'parent' ] = 0;
297 297
 			} else {
298
-				if ( $request['parent'] ) {
299
-					$prepared_args['parent'] = $request['parent'];
298
+				if ( $request[ 'parent' ] ) {
299
+					$prepared_args[ 'parent' ] = $request[ 'parent' ];
300 300
 				}
301 301
 			}
302 302
 		}
@@ -315,20 +315,20 @@  discard block
 block discarded – undo
315 315
 		 */
316 316
 		$prepared_args = apply_filters( "woocommerce_rest_{$taxonomy}_query", $prepared_args, $request );
317 317
 
318
-		if ( ! empty( $prepared_args['product'] ) ) {
318
+		if ( ! empty( $prepared_args[ 'product' ] ) ) {
319 319
 			$query_result = $this->get_terms_for_product( $prepared_args, $request );
320 320
 			$total_terms  = $this->total_terms;
321 321
 		} else {
322 322
 			$query_result = get_terms( $taxonomy, $prepared_args );
323 323
 
324 324
 			$count_args = $prepared_args;
325
-			unset( $count_args['number'] );
326
-			unset( $count_args['offset'] );
325
+			unset( $count_args[ 'number' ] );
326
+			unset( $count_args[ 'offset' ] );
327 327
 			$total_terms = wp_count_terms( $taxonomy, $count_args );
328 328
 
329 329
 			// Ensure we don't return results when offset is out of bounds.
330 330
 			// See https://core.trac.wordpress.org/ticket/35935.
331
-			if ( $prepared_args['offset'] && $prepared_args['offset'] >= $total_terms ) {
331
+			if ( $prepared_args[ 'offset' ] && $prepared_args[ 'offset' ] >= $total_terms ) {
332 332
 				$query_result = array();
333 333
 			}
334 334
 
@@ -340,20 +340,20 @@  discard block
 block discarded – undo
340 340
 		$response = array();
341 341
 		foreach ( $query_result as $term ) {
342 342
 			$data       = $this->prepare_item_for_response( $term, $request );
343
-			$response[] = $this->prepare_response_for_collection( $data );
343
+			$response[ ] = $this->prepare_response_for_collection( $data );
344 344
 		}
345 345
 
346 346
 		$response = rest_ensure_response( $response );
347 347
 
348 348
 		// Store pagination values for headers then unset for count query.
349
-		$per_page = (int) $prepared_args['number'];
350
-		$page     = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
349
+		$per_page = (int) $prepared_args[ 'number' ];
350
+		$page     = ceil( ( ( (int) $prepared_args[ 'offset' ] ) / $per_page ) + 1 );
351 351
 
352 352
 		$response->header( 'X-WP-Total', (int) $total_terms );
353 353
 		$max_pages = ceil( $total_terms / $per_page );
354 354
 		$response->header( 'X-WP-TotalPages', (int) $max_pages );
355 355
 
356
-		$base  = str_replace( '(?P<attribute_id>[\d]+)', $request['attribute_id'], $this->rest_base );
356
+		$base = str_replace( '(?P<attribute_id>[\d]+)', $request[ 'attribute_id' ], $this->rest_base );
357 357
 		$base = add_query_arg( $request->get_query_params(), rest_url( '/' . $this->namespace . '/' . $base ) );
358 358
 		if ( $page > 1 ) {
359 359
 			$prev_page = $page - 1;
@@ -380,21 +380,21 @@  discard block
 block discarded – undo
380 380
 	 */
381 381
 	public function create_item( $request ) {
382 382
 		$taxonomy = $this->get_taxonomy( $request );
383
-		$name     = $request['name'];
383
+		$name     = $request[ 'name' ];
384 384
 		$args     = array();
385 385
 		$schema   = $this->get_item_schema();
386 386
 
387
-		if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) {
388
-			$args['description'] = $request['description'];
387
+		if ( ! empty( $schema[ 'properties' ][ 'description' ] ) && isset( $request[ 'description' ] ) ) {
388
+			$args[ 'description' ] = $request[ 'description' ];
389 389
 		}
390
-		if ( isset( $request['slug'] ) ) {
391
-			$args['slug'] = $request['slug'];
390
+		if ( isset( $request[ 'slug' ] ) ) {
391
+			$args[ 'slug' ] = $request[ 'slug' ];
392 392
 		}
393
-		if ( isset( $request['parent'] ) ) {
393
+		if ( isset( $request[ 'parent' ] ) ) {
394 394
 			if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
395 395
 				return new \WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) );
396 396
 			}
397
-			$args['parent'] = $request['parent'];
397
+			$args[ 'parent' ] = $request[ 'parent' ];
398 398
 		}
399 399
 
400 400
 		$term = wp_insert_term( $name, $taxonomy, $args );
@@ -405,13 +405,13 @@  discard block
 block discarded – undo
405 405
 			// give them the identifier they can actually use.
406 406
 			$term_id = $term->get_error_data( 'term_exists' );
407 407
 			if ( $term_id ) {
408
-				$error_data['resource_id'] = $term_id;
408
+				$error_data[ 'resource_id' ] = $term_id;
409 409
 			}
410 410
 
411 411
 			return new \WP_Error( $term->get_error_code(), $term->get_error_message(), $error_data );
412 412
 		}
413 413
 
414
-		$term = get_term( $term['term_id'], $taxonomy );
414
+		$term = get_term( $term[ 'term_id' ], $taxonomy );
415 415
 
416 416
 		$this->update_additional_fields_for_object( $term, $request );
417 417
 
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
 		$response->set_status( 201 );
439 439
 
440 440
 		$base = '/' . $this->namespace . '/' . $this->rest_base;
441
-		if ( ! empty( $request['attribute_id'] ) ) {
442
-			$base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base );
441
+		if ( ! empty( $request[ 'attribute_id' ] ) ) {
442
+			$base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request[ 'attribute_id' ], $base );
443 443
 		}
444 444
 
445 445
 		$response->header( 'Location', rest_url( $base . '/' . $term->term_id ) );
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 	 */
456 456
 	public function get_item( $request ) {
457 457
 		$taxonomy = $this->get_taxonomy( $request );
458
-		$term     = get_term( (int) $request['id'], $taxonomy );
458
+		$term     = get_term( (int) $request[ 'id' ], $taxonomy );
459 459
 
460 460
 		if ( is_wp_error( $term ) ) {
461 461
 			return $term;
@@ -474,24 +474,24 @@  discard block
 block discarded – undo
474 474
 	 */
475 475
 	public function update_item( $request ) {
476 476
 		$taxonomy      = $this->get_taxonomy( $request );
477
-		$term          = get_term( (int) $request['id'], $taxonomy );
477
+		$term          = get_term( (int) $request[ 'id' ], $taxonomy );
478 478
 		$schema        = $this->get_item_schema();
479 479
 		$prepared_args = array();
480 480
 
481
-		if ( isset( $request['name'] ) ) {
482
-			$prepared_args['name'] = $request['name'];
481
+		if ( isset( $request[ 'name' ] ) ) {
482
+			$prepared_args[ 'name' ] = $request[ 'name' ];
483 483
 		}
484
-		if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) {
485
-			$prepared_args['description'] = $request['description'];
484
+		if ( ! empty( $schema[ 'properties' ][ 'description' ] ) && isset( $request[ 'description' ] ) ) {
485
+			$prepared_args[ 'description' ] = $request[ 'description' ];
486 486
 		}
487
-		if ( isset( $request['slug'] ) ) {
488
-			$prepared_args['slug'] = $request['slug'];
487
+		if ( isset( $request[ 'slug' ] ) ) {
488
+			$prepared_args[ 'slug' ] = $request[ 'slug' ];
489 489
 		}
490
-		if ( isset( $request['parent'] ) ) {
490
+		if ( isset( $request[ 'parent' ] ) ) {
491 491
 			if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
492 492
 				return new \WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) );
493 493
 			}
494
-			$prepared_args['parent'] = $request['parent'];
494
+			$prepared_args[ 'parent' ] = $request[ 'parent' ];
495 495
 		}
496 496
 
497 497
 		// Only update the term if we haz something to update.
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 			}
503 503
 		}
504 504
 
505
-		$term = get_term( (int) $request['id'], $taxonomy );
505
+		$term = get_term( (int) $request[ 'id' ], $taxonomy );
506 506
 
507 507
 		$this->update_additional_fields_for_object( $term, $request );
508 508
 
@@ -534,19 +534,19 @@  discard block
 block discarded – undo
534 534
 	 */
535 535
 	public function delete_item( $request ) {
536 536
 		$taxonomy = $this->get_taxonomy( $request );
537
-		$force    = isset( $request['force'] ) ? (bool) $request['force'] : false;
537
+		$force    = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false;
538 538
 
539 539
 		// We don't support trashing for this type, error out.
540 540
 		if ( ! $force ) {
541 541
 			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
542 542
 		}
543 543
 
544
-		$term = get_term( (int) $request['id'], $taxonomy );
544
+		$term = get_term( (int) $request[ 'id' ], $taxonomy );
545 545
 		// Get default category id.
546 546
 		$default_category_id = absint( get_option( 'default_product_cat', 0 ) );
547 547
 
548 548
 		// Prevent deleting the default product category.
549
-		if ( $default_category_id === (int) $request['id'] ) {
549
+		if ( $default_category_id === (int) $request[ 'id' ] ) {
550 550
 			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Default product category cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
551 551
 		}
552 552
 
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	protected function prepare_links( $term, $request ) {
581 581
 		$base = '/' . $this->namespace . '/' . $this->rest_base;
582 582
 
583
-		if ( ! empty( $request['attribute_id'] ) ) {
584
-			$base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base );
583
+		if ( ! empty( $request[ 'attribute_id' ] ) ) {
584
+			$base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request[ 'attribute_id' ], $base );
585 585
 		}
586 586
 
587 587
 		$links = array(
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 		if ( $term->parent ) {
597 597
 			$parent_term = get_term( (int) $term->parent, $term->taxonomy );
598 598
 			if ( $parent_term ) {
599
-				$links['up'] = array(
599
+				$links[ 'up' ] = array(
600 600
 					'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
601 601
 				);
602 602
 			}
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 	protected function get_terms_for_product( $prepared_args, $request ) {
632 632
 		$taxonomy = $this->get_taxonomy( $request );
633 633
 
634
-		$query_result = get_the_terms( $prepared_args['product'], $taxonomy );
634
+		$query_result = get_the_terms( $prepared_args[ 'product' ], $taxonomy );
635 635
 		if ( empty( $query_result ) ) {
636 636
 			$this->total_terms = 0;
637 637
 			return array();
@@ -639,8 +639,8 @@  discard block
 block discarded – undo
639 639
 
640 640
 		// get_items() verifies that we don't have `include` set, and default.
641 641
 		// ordering is by `name`.
642
-		if ( ! in_array( $prepared_args['orderby'], array( 'name', 'none', 'include' ), true ) ) {
643
-			switch ( $prepared_args['orderby'] ) {
642
+		if ( ! in_array( $prepared_args[ 'orderby' ], array( 'name', 'none', 'include' ), true ) ) {
643
+			switch ( $prepared_args[ 'orderby' ] ) {
644 644
 				case 'id':
645 645
 					$this->sort_column = 'term_id';
646 646
 					break;
@@ -648,18 +648,18 @@  discard block
 block discarded – undo
648 648
 				case 'term_group':
649 649
 				case 'description':
650 650
 				case 'count':
651
-					$this->sort_column = $prepared_args['orderby'];
651
+					$this->sort_column = $prepared_args[ 'orderby' ];
652 652
 					break;
653 653
 			}
654 654
 			usort( $query_result, array( $this, 'compare_terms' ) );
655 655
 		}
656
-		if ( strtolower( $prepared_args['order'] ) !== 'asc' ) {
656
+		if ( strtolower( $prepared_args[ 'order' ] ) !== 'asc' ) {
657 657
 			$query_result = array_reverse( $query_result );
658 658
 		}
659 659
 
660 660
 		// Pagination.
661 661
 		$this->total_terms = count( $query_result );
662
-		$query_result      = array_slice( $query_result, $prepared_args['offset'], $prepared_args['number'] );
662
+		$query_result      = array_slice( $query_result, $prepared_args[ 'offset' ], $prepared_args[ 'number' ] );
663 663
 
664 664
 		return $query_result;
665 665
 	}
@@ -700,9 +700,9 @@  discard block
 block discarded – undo
700 700
 			$taxonomy->hierarchical = true;
701 701
 		}
702 702
 
703
-		$params['context']['default'] = 'view';
703
+		$params[ 'context' ][ 'default' ] = 'view';
704 704
 
705
-		$params['exclude'] = array(
705
+		$params[ 'exclude' ] = array(
706 706
 			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
707 707
 			'type'              => 'array',
708 708
 			'items'             => array(
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 			'default'           => array(),
712 712
 			'sanitize_callback' => 'wp_parse_id_list',
713 713
 		);
714
-		$params['include'] = array(
714
+		$params[ 'include' ] = array(
715 715
 			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
716 716
 			'type'              => 'array',
717 717
 			'items'             => array(
@@ -721,14 +721,14 @@  discard block
 block discarded – undo
721 721
 			'sanitize_callback' => 'wp_parse_id_list',
722 722
 		);
723 723
 		if ( ! $taxonomy->hierarchical ) {
724
-			$params['offset'] = array(
724
+			$params[ 'offset' ] = array(
725 725
 				'description'       => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
726 726
 				'type'              => 'integer',
727 727
 				'sanitize_callback' => 'absint',
728 728
 				'validate_callback' => 'rest_validate_request_arg',
729 729
 			);
730 730
 		}
731
-		$params['order']      = array(
731
+		$params[ 'order' ] = array(
732 732
 			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
733 733
 			'type'              => 'string',
734 734
 			'sanitize_callback' => 'sanitize_key',
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 			),
740 740
 			'validate_callback' => 'rest_validate_request_arg',
741 741
 		);
742
-		$params['orderby']    = array(
742
+		$params[ 'orderby' ] = array(
743 743
 			'description'       => __( 'Sort collection by resource attribute.', 'woocommerce' ),
744 744
 			'type'              => 'string',
745 745
 			'sanitize_callback' => 'sanitize_key',
@@ -755,27 +755,27 @@  discard block
 block discarded – undo
755 755
 			),
756 756
 			'validate_callback' => 'rest_validate_request_arg',
757 757
 		);
758
-		$params['hide_empty'] = array(
758
+		$params[ 'hide_empty' ] = array(
759 759
 			'description'       => __( 'Whether to hide resources not assigned to any products.', 'woocommerce' ),
760 760
 			'type'              => 'boolean',
761 761
 			'default'           => false,
762 762
 			'validate_callback' => 'rest_validate_request_arg',
763 763
 		);
764 764
 		if ( $taxonomy->hierarchical ) {
765
-			$params['parent'] = array(
765
+			$params[ 'parent' ] = array(
766 766
 				'description'       => __( 'Limit result set to resources assigned to a specific parent.', 'woocommerce' ),
767 767
 				'type'              => 'integer',
768 768
 				'sanitize_callback' => 'absint',
769 769
 				'validate_callback' => 'rest_validate_request_arg',
770 770
 			);
771 771
 		}
772
-		$params['product'] = array(
772
+		$params[ 'product' ] = array(
773 773
 			'description'       => __( 'Limit result set to resources assigned to a specific product.', 'woocommerce' ),
774 774
 			'type'              => 'integer',
775 775
 			'default'           => null,
776 776
 			'validate_callback' => 'rest_validate_request_arg',
777 777
 		);
778
-		$params['slug']    = array(
778
+		$params[ 'slug' ] = array(
779 779
 			'description'       => __( 'Limit result set to resources with a specific slug.', 'woocommerce' ),
780 780
 			'type'              => 'string',
781 781
 			'validate_callback' => 'rest_validate_request_arg',
@@ -797,8 +797,8 @@  discard block
 block discarded – undo
797 797
 			return $this->taxonomy;
798 798
 		}
799 799
 
800
-		if ( ! empty( $request['attribute_id'] ) ) {
801
-			$taxonomy = wc_attribute_taxonomy_name_by_id( (int) $request['attribute_id'] );
800
+		if ( ! empty( $request[ 'attribute_id' ] ) ) {
801
+			$taxonomy = wc_attribute_taxonomy_name_by_id( (int) $request[ 'attribute_id' ] );
802 802
 
803 803
 			$this->taxonomy = $taxonomy;
804 804
 		}
Please login to merge, or discard this patch.