Completed
Push — master ( ee9494...a1e9b4 )
by Mike
45:32
created
src/Controllers/Version4/ProductReviews.php 1 patch
Spacing   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Product Reviews controller class.
@@ -33,41 +33,41 @@  discard block
 block discarded – undo
33 33
 			array(
34 34
 				array(
35 35
 					'methods'             => \WP_REST_Server::READABLE,
36
-					'callback'            => array( $this, 'get_items' ),
37
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
36
+					'callback'            => array($this, 'get_items'),
37
+					'permission_callback' => array($this, 'get_items_permissions_check'),
38 38
 					'args'                => $this->get_collection_params(),
39 39
 				),
40 40
 				array(
41 41
 					'methods'             => \WP_REST_Server::CREATABLE,
42
-					'callback'            => array( $this, 'create_item' ),
43
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
42
+					'callback'            => array($this, 'create_item'),
43
+					'permission_callback' => array($this, 'create_item_permissions_check'),
44 44
 					'args'                => array_merge(
45
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
45
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
46 46
 						array(
47 47
 							'product_id'     => array(
48 48
 								'required'    => true,
49
-								'description' => __( 'Unique identifier for the product.', 'woocommerce' ),
49
+								'description' => __('Unique identifier for the product.', 'woocommerce'),
50 50
 								'type'        => 'integer',
51 51
 							),
52 52
 							'review'         => array(
53 53
 								'required'    => true,
54 54
 								'type'        => 'string',
55
-								'description' => __( 'Review content.', 'woocommerce' ),
55
+								'description' => __('Review content.', 'woocommerce'),
56 56
 							),
57 57
 							'reviewer'       => array(
58 58
 								'required'    => true,
59 59
 								'type'        => 'string',
60
-								'description' => __( 'Name of the reviewer.', 'woocommerce' ),
60
+								'description' => __('Name of the reviewer.', 'woocommerce'),
61 61
 							),
62 62
 							'reviewer_email' => array(
63 63
 								'required'    => true,
64 64
 								'type'        => 'string',
65
-								'description' => __( 'Email of the reviewer.', 'woocommerce' ),
65
+								'description' => __('Email of the reviewer.', 'woocommerce'),
66 66
 							),
67 67
 						)
68 68
 					),
69 69
 				),
70
-				'schema' => array( $this, 'get_public_item_schema' ),
70
+				'schema' => array($this, 'get_public_item_schema'),
71 71
 			),
72 72
 			true
73 73
 		);
@@ -78,37 +78,37 @@  discard block
 block discarded – undo
78 78
 			array(
79 79
 				'args'   => array(
80 80
 					'id' => array(
81
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
81
+						'description' => __('Unique identifier for the resource.', '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
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
90
+						'context' => $this->get_context_param(array('default' => 'view')),
91 91
 					),
92 92
 				),
93 93
 				array(
94 94
 					'methods'             => \WP_REST_Server::EDITABLE,
95
-					'callback'            => array( $this, 'update_item' ),
96
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
97
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
95
+					'callback'            => array($this, 'update_item'),
96
+					'permission_callback' => array($this, 'update_item_permissions_check'),
97
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
98 98
 				),
99 99
 				array(
100 100
 					'methods'             => \WP_REST_Server::DELETABLE,
101
-					'callback'            => array( $this, 'delete_item' ),
102
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
101
+					'callback'            => array($this, 'delete_item'),
102
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
103 103
 					'args'                => array(
104 104
 						'force' => array(
105 105
 							'default'     => false,
106 106
 							'type'        => 'boolean',
107
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
107
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
108 108
 						),
109 109
 					),
110 110
 				),
111
-				'schema' => array( $this, 'get_public_item_schema' ),
111
+				'schema' => array($this, 'get_public_item_schema'),
112 112
 			),
113 113
 			true
114 114
 		);
@@ -119,11 +119,11 @@  discard block
 block discarded – undo
119 119
 			array(
120 120
 				array(
121 121
 					'methods'             => \WP_REST_Server::EDITABLE,
122
-					'callback'            => array( $this, 'batch_items' ),
123
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
124
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
122
+					'callback'            => array($this, 'batch_items'),
123
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
124
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
125 125
 				),
126
-				'schema' => array( $this, 'get_public_batch_schema' ),
126
+				'schema' => array($this, 'get_public_batch_schema'),
127 127
 			),
128 128
 			true
129 129
 		);
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
 	 * @param  \WP_REST_Request $request Full details about the request.
136 136
 	 * @return \WP_Error|boolean
137 137
 	 */
138
-	public function get_items_permissions_check( $request ) {
139
-		if ( ! wc_rest_check_product_reviews_permissions( 'read' ) ) {
140
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
138
+	public function get_items_permissions_check($request) {
139
+		if ( ! wc_rest_check_product_reviews_permissions('read')) {
140
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
141 141
 		}
142 142
 
143 143
 		return true;
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
 	 * @param  \WP_REST_Request $request Full details about the request.
150 150
 	 * @return \WP_Error|boolean
151 151
 	 */
152
-	public function get_item_permissions_check( $request ) {
152
+	public function get_item_permissions_check($request) {
153 153
 		$id     = (int) $request['id'];
154
-		$review = get_comment( $id );
154
+		$review = get_comment($id);
155 155
 
156
-		if ( $review && ! wc_rest_check_product_reviews_permissions( 'read', $review->comment_ID ) ) {
157
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
156
+		if ($review && ! wc_rest_check_product_reviews_permissions('read', $review->comment_ID)) {
157
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
158 158
 		}
159 159
 
160 160
 		return true;
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
 	 * @param  \WP_REST_Request $request Full details about the request.
167 167
 	 * @return \WP_Error|boolean
168 168
 	 */
169
-	public function create_item_permissions_check( $request ) {
170
-		if ( ! wc_rest_check_product_reviews_permissions( 'create' ) ) {
171
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
169
+	public function create_item_permissions_check($request) {
170
+		if ( ! wc_rest_check_product_reviews_permissions('create')) {
171
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
172 172
 		}
173 173
 
174 174
 		return true;
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
 	 * @param  \WP_REST_Request $request Full details about the request.
181 181
 	 * @return \WP_Error|boolean
182 182
 	 */
183
-	public function update_item_permissions_check( $request ) {
183
+	public function update_item_permissions_check($request) {
184 184
 		$id     = (int) $request['id'];
185
-		$review = get_comment( $id );
185
+		$review = get_comment($id);
186 186
 
187
-		if ( $review && ! wc_rest_check_product_reviews_permissions( 'edit', $review->comment_ID ) ) {
188
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
187
+		if ($review && ! wc_rest_check_product_reviews_permissions('edit', $review->comment_ID)) {
188
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
189 189
 		}
190 190
 
191 191
 		return true;
@@ -197,12 +197,12 @@  discard block
 block discarded – undo
197 197
 	 * @param  \WP_REST_Request $request Full details about the request.
198 198
 	 * @return \WP_Error|boolean
199 199
 	 */
200
-	public function delete_item_permissions_check( $request ) {
200
+	public function delete_item_permissions_check($request) {
201 201
 		$id     = (int) $request['id'];
202
-		$review = get_comment( $id );
202
+		$review = get_comment($id);
203 203
 
204
-		if ( $review && ! wc_rest_check_product_reviews_permissions( 'delete', $review->comment_ID ) ) {
205
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
204
+		if ($review && ! wc_rest_check_product_reviews_permissions('delete', $review->comment_ID)) {
205
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
206 206
 		}
207 207
 
208 208
 		return true;
@@ -214,9 +214,9 @@  discard block
 block discarded – undo
214 214
 	 * @param  \WP_REST_Request $request Full details about the request.
215 215
 	 * @return boolean|\WP_Error
216 216
 	 */
217
-	public function batch_items_permissions_check( $request ) {
218
-		if ( ! wc_rest_check_product_reviews_permissions( 'create' ) ) {
219
-			return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
217
+	public function batch_items_permissions_check($request) {
218
+		if ( ! wc_rest_check_product_reviews_permissions('create')) {
219
+			return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
220 220
 		}
221 221
 
222 222
 		return true;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * @param \WP_REST_Request $request Full details about the request.
229 229
 	 * @return array|\WP_Error
230 230
 	 */
231
-	public function get_items( $request ) {
231
+	public function get_items($request) {
232 232
 		// Retrieve the list of registered collection query parameters.
233 233
 		$registered = $this->get_collection_params();
234 234
 
@@ -258,24 +258,24 @@  discard block
 block discarded – undo
258 258
 		 * For each known parameter which is both registered and present in the request,
259 259
 		 * set the parameter's value on the query $prepared_args.
260 260
 		 */
261
-		foreach ( $parameter_mappings as $api_param => $wp_param ) {
262
-			if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) {
263
-				$prepared_args[ $wp_param ] = $request[ $api_param ];
261
+		foreach ($parameter_mappings as $api_param => $wp_param) {
262
+			if (isset($registered[$api_param], $request[$api_param])) {
263
+				$prepared_args[$wp_param] = $request[$api_param];
264 264
 			}
265 265
 		}
266 266
 
267 267
 		// Ensure certain parameter values default to empty strings.
268
-		foreach ( array( 'author_email', 'search' ) as $param ) {
269
-			if ( ! isset( $prepared_args[ $param ] ) ) {
270
-				$prepared_args[ $param ] = '';
268
+		foreach (array('author_email', 'search') as $param) {
269
+			if ( ! isset($prepared_args[$param])) {
270
+				$prepared_args[$param] = '';
271 271
 			}
272 272
 		}
273 273
 
274
-		if ( isset( $registered['orderby'] ) ) {
275
-			$prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] );
274
+		if (isset($registered['orderby'])) {
275
+			$prepared_args['orderby'] = $this->normalize_query_param($request['orderby']);
276 276
 		}
277 277
 
278
-		if ( isset( $prepared_args['status'] ) ) {
278
+		if (isset($prepared_args['status'])) {
279 279
 			$prepared_args['status'] = 'approved' === $prepared_args['status'] ? 'approve' : $prepared_args['status'];
280 280
 		}
281 281
 
@@ -283,17 +283,17 @@  discard block
 block discarded – undo
283 283
 		$prepared_args['date_query']    = array();
284 284
 
285 285
 		// Set before into date query. Date query must be specified as an array of an array.
286
-		if ( isset( $registered['before'], $request['before'] ) ) {
286
+		if (isset($registered['before'], $request['before'])) {
287 287
 			$prepared_args['date_query'][0]['before'] = $request['before'];
288 288
 		}
289 289
 
290 290
 		// Set after into date query. Date query must be specified as an array of an array.
291
-		if ( isset( $registered['after'], $request['after'] ) ) {
291
+		if (isset($registered['after'], $request['after'])) {
292 292
 			$prepared_args['date_query'][0]['after'] = $request['after'];
293 293
 		}
294 294
 
295
-		if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) {
296
-			$prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 );
295
+		if (isset($registered['page']) && empty($request['offset'])) {
296
+			$prepared_args['offset'] = $prepared_args['number'] * (absint($request['page']) - 1);
297 297
 		}
298 298
 
299 299
 		/**
@@ -304,61 +304,61 @@  discard block
 block discarded – undo
304 304
 		 * @param array           $prepared_args Array of arguments for \WP_Comment_Query.
305 305
 		 * @param \WP_REST_Request $request       The current request.
306 306
 		 */
307
-		$prepared_args = apply_filters( 'woocommerce_rest_product_review_query', $prepared_args, $request );
307
+		$prepared_args = apply_filters('woocommerce_rest_product_review_query', $prepared_args, $request);
308 308
 
309 309
 		// Make sure that returns only reviews.
310 310
 		$prepared_args['type'] = 'review';
311 311
 
312 312
 		// Query reviews.
313 313
 		$query        = new \WP_Comment_Query();
314
-		$query_result = $query->query( $prepared_args );
314
+		$query_result = $query->query($prepared_args);
315 315
 		$reviews      = array();
316 316
 
317
-		foreach ( $query_result as $review ) {
318
-			if ( ! wc_rest_check_product_reviews_permissions( 'read', $review->comment_ID ) ) {
317
+		foreach ($query_result as $review) {
318
+			if ( ! wc_rest_check_product_reviews_permissions('read', $review->comment_ID)) {
319 319
 				continue;
320 320
 			}
321 321
 
322
-			$data      = $this->prepare_item_for_response( $review, $request );
323
-			$reviews[] = $this->prepare_response_for_collection( $data );
322
+			$data      = $this->prepare_item_for_response($review, $request);
323
+			$reviews[] = $this->prepare_response_for_collection($data);
324 324
 		}
325 325
 
326 326
 		$total_reviews = (int) $query->found_comments;
327 327
 		$max_pages     = (int) $query->max_num_pages;
328 328
 
329
-		if ( $total_reviews < 1 ) {
329
+		if ($total_reviews < 1) {
330 330
 			// Out-of-bounds, run the query again without LIMIT for total count.
331
-			unset( $prepared_args['number'], $prepared_args['offset'] );
331
+			unset($prepared_args['number'], $prepared_args['offset']);
332 332
 
333 333
 			$query                  = new \WP_Comment_Query();
334 334
 			$prepared_args['count'] = true;
335 335
 
336
-			$total_reviews = $query->query( $prepared_args );
337
-			$max_pages     = ceil( $total_reviews / $request['per_page'] );
336
+			$total_reviews = $query->query($prepared_args);
337
+			$max_pages     = ceil($total_reviews / $request['per_page']);
338 338
 		}
339 339
 
340
-		$response = rest_ensure_response( $reviews );
341
-		$response->header( 'X-WP-Total', $total_reviews );
342
-		$response->header( 'X-WP-TotalPages', $max_pages );
340
+		$response = rest_ensure_response($reviews);
341
+		$response->header('X-WP-Total', $total_reviews);
342
+		$response->header('X-WP-TotalPages', $max_pages);
343 343
 
344
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
344
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)));
345 345
 
346
-		if ( $request['page'] > 1 ) {
346
+		if ($request['page'] > 1) {
347 347
 			$prev_page = $request['page'] - 1;
348 348
 
349
-			if ( $prev_page > $max_pages ) {
349
+			if ($prev_page > $max_pages) {
350 350
 				$prev_page = $max_pages;
351 351
 			}
352 352
 
353
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
354
-			$response->link_header( 'prev', $prev_link );
353
+			$prev_link = add_query_arg('page', $prev_page, $base);
354
+			$response->link_header('prev', $prev_link);
355 355
 		}
356 356
 
357
-		if ( $max_pages > $request['page'] ) {
357
+		if ($max_pages > $request['page']) {
358 358
 			$next_page = $request['page'] + 1;
359
-			$next_link = add_query_arg( 'page', $next_page, $base );
359
+			$next_link = add_query_arg('page', $next_page, $base);
360 360
 
361
-			$response->link_header( 'next', $next_link );
361
+			$response->link_header('next', $next_link);
362 362
 		}
363 363
 
364 364
 		return $response;
@@ -370,19 +370,19 @@  discard block
 block discarded – undo
370 370
 	 * @param \WP_REST_Request $request Full details about the request.
371 371
 	 * @return \WP_Error|\WP_REST_Response
372 372
 	 */
373
-	public function create_item( $request ) {
374
-		if ( ! empty( $request['id'] ) ) {
375
-			return new \WP_Error( 'woocommerce_rest_review_exists', __( 'Cannot create existing product review.', 'woocommerce' ), array( 'status' => 400 ) );
373
+	public function create_item($request) {
374
+		if ( ! empty($request['id'])) {
375
+			return new \WP_Error('woocommerce_rest_review_exists', __('Cannot create existing product review.', 'woocommerce'), array('status' => 400));
376 376
 		}
377 377
 
378 378
 		$product_id = (int) $request['product_id'];
379 379
 
380
-		if ( 'product' !== get_post_type( $product_id ) ) {
381
-			return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) );
380
+		if ('product' !== get_post_type($product_id)) {
381
+			return new \WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404));
382 382
 		}
383 383
 
384
-		$prepared_review = $this->prepare_item_for_database( $request );
385
-		if ( is_wp_error( $prepared_review ) ) {
384
+		$prepared_review = $this->prepare_item_for_database($request);
385
+		if (is_wp_error($prepared_review)) {
386 386
 			return $prepared_review;
387 387
 		}
388 388
 
@@ -391,49 +391,49 @@  discard block
 block discarded – undo
391 391
 		/*
392 392
 		 * Do not allow a comment to be created with missing or empty comment_content. See wp_handle_comment_submission().
393 393
 		 */
394
-		if ( empty( $prepared_review['comment_content'] ) ) {
395
-			return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) );
394
+		if (empty($prepared_review['comment_content'])) {
395
+			return new \WP_Error('woocommerce_rest_review_content_invalid', __('Invalid review content.', 'woocommerce'), array('status' => 400));
396 396
 		}
397 397
 
398 398
 		// Setting remaining values before wp_insert_comment so we can use wp_allow_comment().
399
-		if ( ! isset( $prepared_review['comment_date_gmt'] ) ) {
400
-			$prepared_review['comment_date_gmt'] = current_time( 'mysql', true );
399
+		if ( ! isset($prepared_review['comment_date_gmt'])) {
400
+			$prepared_review['comment_date_gmt'] = current_time('mysql', true);
401 401
 		}
402 402
 
403
-		if ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) { // WPCS: input var ok, sanitization ok.
404
-			$prepared_review['comment_author_IP'] = wc_clean( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // WPCS: input var ok.
403
+		if ( ! empty($_SERVER['REMOTE_ADDR']) && rest_is_ip_address(wp_unslash($_SERVER['REMOTE_ADDR']))) { // WPCS: input var ok, sanitization ok.
404
+			$prepared_review['comment_author_IP'] = wc_clean(wp_unslash($_SERVER['REMOTE_ADDR'])); // WPCS: input var ok.
405 405
 		} else {
406 406
 			$prepared_review['comment_author_IP'] = '127.0.0.1';
407 407
 		}
408 408
 
409
-		if ( ! empty( $request['author_user_agent'] ) ) {
409
+		if ( ! empty($request['author_user_agent'])) {
410 410
 			$prepared_review['comment_agent'] = $request['author_user_agent'];
411
-		} elseif ( $request->get_header( 'user_agent' ) ) {
412
-			$prepared_review['comment_agent'] = $request->get_header( 'user_agent' );
411
+		} elseif ($request->get_header('user_agent')) {
412
+			$prepared_review['comment_agent'] = $request->get_header('user_agent');
413 413
 		} else {
414 414
 			$prepared_review['comment_agent'] = '';
415 415
 		}
416 416
 
417
-		$check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_review );
418
-		if ( is_wp_error( $check_comment_lengths ) ) {
419
-			$error_code = str_replace( array( 'comment_author', 'comment_content' ), array( 'reviewer', 'review_content' ), $check_comment_lengths->get_error_code() );
420
-			return new \WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce' ), array( 'status' => 400 ) );
417
+		$check_comment_lengths = wp_check_comment_data_max_lengths($prepared_review);
418
+		if (is_wp_error($check_comment_lengths)) {
419
+			$error_code = str_replace(array('comment_author', 'comment_content'), array('reviewer', 'review_content'), $check_comment_lengths->get_error_code());
420
+			return new \WP_Error('woocommerce_rest_' . $error_code, __('Product review field exceeds maximum length allowed.', 'woocommerce'), array('status' => 400));
421 421
 		}
422 422
 
423 423
 		$prepared_review['comment_parent']     = 0;
424 424
 		$prepared_review['comment_author_url'] = '';
425
-		$prepared_review['comment_approved']   = wp_allow_comment( $prepared_review, true );
425
+		$prepared_review['comment_approved']   = wp_allow_comment($prepared_review, true);
426 426
 
427
-		if ( is_wp_error( $prepared_review['comment_approved'] ) ) {
427
+		if (is_wp_error($prepared_review['comment_approved'])) {
428 428
 			$error_code    = $prepared_review['comment_approved']->get_error_code();
429 429
 			$error_message = $prepared_review['comment_approved']->get_error_message();
430 430
 
431
-			if ( 'comment_duplicate' === $error_code ) {
432
-				return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 409 ) );
431
+			if ('comment_duplicate' === $error_code) {
432
+				return new \WP_Error('woocommerce_rest_' . $error_code, $error_message, array('status' => 409));
433 433
 			}
434 434
 
435
-			if ( 'comment_flood' === $error_code ) {
436
-				return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 400 ) );
435
+			if ('comment_flood' === $error_code) {
436
+				return new \WP_Error('woocommerce_rest_' . $error_code, $error_message, array('status' => 400));
437 437
 			}
438 438
 
439 439
 			return $prepared_review['comment_approved'];
@@ -450,24 +450,24 @@  discard block
 block discarded – undo
450 450
 		 * @param array|\WP_Error  $prepared_review The prepared review data for wp_insert_comment().
451 451
 		 * @param \WP_REST_Request $request          Request used to insert the review.
452 452
 		 */
453
-		$prepared_review = apply_filters( 'woocommerce_rest_pre_insert_product_review', $prepared_review, $request );
454
-		if ( is_wp_error( $prepared_review ) ) {
453
+		$prepared_review = apply_filters('woocommerce_rest_pre_insert_product_review', $prepared_review, $request);
454
+		if (is_wp_error($prepared_review)) {
455 455
 			return $prepared_review;
456 456
 		}
457 457
 
458
-		$review_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_review ) ) );
458
+		$review_id = wp_insert_comment(wp_filter_comment(wp_slash((array) $prepared_review)));
459 459
 
460
-		if ( ! $review_id ) {
461
-			return new \WP_Error( 'woocommerce_rest_review_failed_create', __( 'Creating product review failed.', 'woocommerce' ), array( 'status' => 500 ) );
460
+		if ( ! $review_id) {
461
+			return new \WP_Error('woocommerce_rest_review_failed_create', __('Creating product review failed.', 'woocommerce'), array('status' => 500));
462 462
 		}
463 463
 
464
-		if ( isset( $request['status'] ) ) {
465
-			$this->handle_status_param( $request['status'], $review_id );
464
+		if (isset($request['status'])) {
465
+			$this->handle_status_param($request['status'], $review_id);
466 466
 		}
467 467
 
468
-		update_comment_meta( $review_id, 'rating', ! empty( $request['rating'] ) ? $request['rating'] : '0' );
468
+		update_comment_meta($review_id, 'rating', ! empty($request['rating']) ? $request['rating'] : '0');
469 469
 
470
-		$review = get_comment( $review_id );
470
+		$review = get_comment($review_id);
471 471
 
472 472
 		/**
473 473
 		 * Fires after a comment is created or updated via the REST API.
@@ -476,21 +476,21 @@  discard block
 block discarded – undo
476 476
 		 * @param \WP_REST_Request $request  Request object.
477 477
 		 * @param bool            $creating True when creating a comment, false when updating.
478 478
 		 */
479
-		do_action( 'woocommerce_rest_insert_product_review', $review, $request, true );
479
+		do_action('woocommerce_rest_insert_product_review', $review, $request, true);
480 480
 
481
-		$fields_update = $this->update_additional_fields_for_object( $review, $request );
482
-		if ( is_wp_error( $fields_update ) ) {
481
+		$fields_update = $this->update_additional_fields_for_object($review, $request);
482
+		if (is_wp_error($fields_update)) {
483 483
 			return $fields_update;
484 484
 		}
485 485
 
486
-		$context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view';
487
-		$request->set_param( 'context', $context );
486
+		$context = current_user_can('moderate_comments') ? 'edit' : 'view';
487
+		$request->set_param('context', $context);
488 488
 
489
-		$response = $this->prepare_item_for_response( $review, $request );
490
-		$response = rest_ensure_response( $response );
489
+		$response = $this->prepare_item_for_response($review, $request);
490
+		$response = rest_ensure_response($response);
491 491
 
492
-		$response->set_status( 201 );
493
-		$response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $review_id ) ) );
492
+		$response->set_status(201);
493
+		$response->header('Location', rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $review_id)));
494 494
 
495 495
 		return $response;
496 496
 	}
@@ -501,14 +501,14 @@  discard block
 block discarded – undo
501 501
 	 * @param \WP_REST_Request $request Full details about the request.
502 502
 	 * @return \WP_Error|\WP_REST_Response
503 503
 	 */
504
-	public function get_item( $request ) {
505
-		$review = $this->get_review( $request['id'] );
506
-		if ( is_wp_error( $review ) ) {
504
+	public function get_item($request) {
505
+		$review = $this->get_review($request['id']);
506
+		if (is_wp_error($review)) {
507 507
 			return $review;
508 508
 		}
509 509
 
510
-		$data     = $this->prepare_item_for_response( $review, $request );
511
-		$response = rest_ensure_response( $data );
510
+		$data     = $this->prepare_item_for_response($review, $request);
511
+		$response = rest_ensure_response($data);
512 512
 
513 513
 		return $response;
514 514
 	}
@@ -519,84 +519,84 @@  discard block
 block discarded – undo
519 519
 	 * @param \WP_REST_Request $request Full details about the request.
520 520
 	 * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure.
521 521
 	 */
522
-	public function update_item( $request ) {
523
-		$review = $this->get_review( $request['id'] );
524
-		if ( is_wp_error( $review ) ) {
522
+	public function update_item($request) {
523
+		$review = $this->get_review($request['id']);
524
+		if (is_wp_error($review)) {
525 525
 			return $review;
526 526
 		}
527 527
 
528 528
 		$id = (int) $review->comment_ID;
529 529
 
530
-		if ( isset( $request['type'] ) && 'review' !== get_comment_type( $id ) ) {
531
-			return new \WP_Error( 'woocommerce_rest_review_invalid_type', __( 'Sorry, you are not allowed to change the comment type.', 'woocommerce' ), array( 'status' => 404 ) );
530
+		if (isset($request['type']) && 'review' !== get_comment_type($id)) {
531
+			return new \WP_Error('woocommerce_rest_review_invalid_type', __('Sorry, you are not allowed to change the comment type.', 'woocommerce'), array('status' => 404));
532 532
 		}
533 533
 
534
-		$prepared_args = $this->prepare_item_for_database( $request );
535
-		if ( is_wp_error( $prepared_args ) ) {
534
+		$prepared_args = $this->prepare_item_for_database($request);
535
+		if (is_wp_error($prepared_args)) {
536 536
 			return $prepared_args;
537 537
 		}
538 538
 
539
-		if ( ! empty( $prepared_args['comment_post_ID'] ) ) {
540
-			if ( 'product' !== get_post_type( (int) $prepared_args['comment_post_ID'] ) ) {
541
-				return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) );
539
+		if ( ! empty($prepared_args['comment_post_ID'])) {
540
+			if ('product' !== get_post_type((int) $prepared_args['comment_post_ID'])) {
541
+				return new \WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404));
542 542
 			}
543 543
 		}
544 544
 
545
-		if ( empty( $prepared_args ) && isset( $request['status'] ) ) {
545
+		if (empty($prepared_args) && isset($request['status'])) {
546 546
 			// Only the comment status is being changed.
547
-			$change = $this->handle_status_param( $request['status'], $id );
547
+			$change = $this->handle_status_param($request['status'], $id);
548 548
 
549
-			if ( ! $change ) {
550
-				return new \WP_Error( 'woocommerce_rest_review_failed_edit', __( 'Updating review status failed.', 'woocommerce' ), array( 'status' => 500 ) );
549
+			if ( ! $change) {
550
+				return new \WP_Error('woocommerce_rest_review_failed_edit', __('Updating review status failed.', 'woocommerce'), array('status' => 500));
551 551
 			}
552
-		} elseif ( ! empty( $prepared_args ) ) {
553
-			if ( is_wp_error( $prepared_args ) ) {
552
+		} elseif ( ! empty($prepared_args)) {
553
+			if (is_wp_error($prepared_args)) {
554 554
 				return $prepared_args;
555 555
 			}
556 556
 
557
-			if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) {
558
-				return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) );
557
+			if (isset($prepared_args['comment_content']) && empty($prepared_args['comment_content'])) {
558
+				return new \WP_Error('woocommerce_rest_review_content_invalid', __('Invalid review content.', 'woocommerce'), array('status' => 400));
559 559
 			}
560 560
 
561 561
 			$prepared_args['comment_ID'] = $id;
562 562
 
563
-			$check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args );
564
-			if ( is_wp_error( $check_comment_lengths ) ) {
565
-				$error_code = str_replace( array( 'comment_author', 'comment_content' ), array( 'reviewer', 'review_content' ), $check_comment_lengths->get_error_code() );
566
-				return new \WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce' ), array( 'status' => 400 ) );
563
+			$check_comment_lengths = wp_check_comment_data_max_lengths($prepared_args);
564
+			if (is_wp_error($check_comment_lengths)) {
565
+				$error_code = str_replace(array('comment_author', 'comment_content'), array('reviewer', 'review_content'), $check_comment_lengths->get_error_code());
566
+				return new \WP_Error('woocommerce_rest_' . $error_code, __('Product review field exceeds maximum length allowed.', 'woocommerce'), array('status' => 400));
567 567
 			}
568 568
 
569
-			$updated = wp_update_comment( wp_slash( (array) $prepared_args ) );
569
+			$updated = wp_update_comment(wp_slash((array) $prepared_args));
570 570
 
571
-			if ( false === $updated ) {
572
-				return new \WP_Error( 'woocommerce_rest_comment_failed_edit', __( 'Updating review failed.', 'woocommerce' ), array( 'status' => 500 ) );
571
+			if (false === $updated) {
572
+				return new \WP_Error('woocommerce_rest_comment_failed_edit', __('Updating review failed.', 'woocommerce'), array('status' => 500));
573 573
 			}
574 574
 
575
-			if ( isset( $request['status'] ) ) {
576
-				$this->handle_status_param( $request['status'], $id );
575
+			if (isset($request['status'])) {
576
+				$this->handle_status_param($request['status'], $id);
577 577
 			}
578 578
 		}
579 579
 
580
-		if ( ! empty( $request['rating'] ) ) {
581
-			update_comment_meta( $id, 'rating', $request['rating'] );
580
+		if ( ! empty($request['rating'])) {
581
+			update_comment_meta($id, 'rating', $request['rating']);
582 582
 		}
583 583
 
584
-		$review = get_comment( $id );
584
+		$review = get_comment($id);
585 585
 
586 586
 		/** This action is documented in includes/api/class-wc-rest-product-reviews-controller.php */
587
-		do_action( 'woocommerce_rest_insert_product_review', $review, $request, false );
587
+		do_action('woocommerce_rest_insert_product_review', $review, $request, false);
588 588
 
589
-		$fields_update = $this->update_additional_fields_for_object( $review, $request );
589
+		$fields_update = $this->update_additional_fields_for_object($review, $request);
590 590
 
591
-		if ( is_wp_error( $fields_update ) ) {
591
+		if (is_wp_error($fields_update)) {
592 592
 			return $fields_update;
593 593
 		}
594 594
 
595
-		$request->set_param( 'context', 'edit' );
595
+		$request->set_param('context', 'edit');
596 596
 
597
-		$response = $this->prepare_item_for_response( $review, $request );
597
+		$response = $this->prepare_item_for_response($review, $request);
598 598
 
599
-		return rest_ensure_response( $response );
599
+		return rest_ensure_response($response);
600 600
 	}
601 601
 
602 602
 	/**
@@ -605,13 +605,13 @@  discard block
 block discarded – undo
605 605
 	 * @param \WP_REST_Request $request Full details about the request.
606 606
 	 * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure.
607 607
 	 */
608
-	public function delete_item( $request ) {
609
-		$review = $this->get_review( $request['id'] );
610
-		if ( is_wp_error( $review ) ) {
608
+	public function delete_item($request) {
609
+		$review = $this->get_review($request['id']);
610
+		if (is_wp_error($review)) {
611 611
 			return $review;
612 612
 		}
613 613
 
614
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
614
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
615 615
 
616 616
 		/**
617 617
 		 * Filters whether a review can be trashed.
@@ -622,13 +622,13 @@  discard block
 block discarded – undo
622 622
 		 * @param bool       $supports_trash Whether the post type support trashing.
623 623
 		 * @param WP_Comment $review         The review object being considered for trashing support.
624 624
 		 */
625
-		$supports_trash = apply_filters( 'woocommerce_rest_product_review_trashable', ( EMPTY_TRASH_DAYS > 0 ), $review );
625
+		$supports_trash = apply_filters('woocommerce_rest_product_review_trashable', (EMPTY_TRASH_DAYS > 0), $review);
626 626
 
627
-		$request->set_param( 'context', 'edit' );
627
+		$request->set_param('context', 'edit');
628 628
 
629
-		if ( $force ) {
630
-			$previous = $this->prepare_item_for_response( $review, $request );
631
-			$result   = wp_delete_comment( $review->comment_ID, true );
629
+		if ($force) {
630
+			$previous = $this->prepare_item_for_response($review, $request);
631
+			$result   = wp_delete_comment($review->comment_ID, true);
632 632
 			$response = new \WP_REST_Response();
633 633
 			$response->set_data(
634 634
 				array(
@@ -638,22 +638,22 @@  discard block
 block discarded – undo
638 638
 			);
639 639
 		} else {
640 640
 			// If this type doesn't support trashing, error out.
641
-			if ( ! $supports_trash ) {
641
+			if ( ! $supports_trash) {
642 642
 				/* translators: %s: force=true */
643
-				return new \WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( "The object does not support trashing. Set '%s' to delete.", 'woocommerce' ), 'force=true' ), array( 'status' => 501 ) );
643
+				return new \WP_Error('woocommerce_rest_trash_not_supported', sprintf(__("The object does not support trashing. Set '%s' to delete.", 'woocommerce'), 'force=true'), array('status' => 501));
644 644
 			}
645 645
 
646
-			if ( 'trash' === $review->comment_approved ) {
647
-				return new \WP_Error( 'woocommerce_rest_already_trashed', __( 'The object has already been trashed.', 'woocommerce' ), array( 'status' => 410 ) );
646
+			if ('trash' === $review->comment_approved) {
647
+				return new \WP_Error('woocommerce_rest_already_trashed', __('The object has already been trashed.', 'woocommerce'), array('status' => 410));
648 648
 			}
649 649
 
650
-			$result   = wp_trash_comment( $review->comment_ID );
651
-			$review   = get_comment( $review->comment_ID );
652
-			$response = $this->prepare_item_for_response( $review, $request );
650
+			$result   = wp_trash_comment($review->comment_ID);
651
+			$review   = get_comment($review->comment_ID);
652
+			$response = $this->prepare_item_for_response($review, $request);
653 653
 		}
654 654
 
655
-		if ( ! $result ) {
656
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The object cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
655
+		if ( ! $result) {
656
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('The object cannot be deleted.', 'woocommerce'), array('status' => 500));
657 657
 		}
658 658
 
659 659
 		/**
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 		 * @param \WP_REST_Response $response The response returned from the API.
664 664
 		 * @param \WP_REST_Request  $request  The request sent to the API.
665 665
 		 */
666
-		do_action( 'woocommerce_rest_delete_review', $review, $response, $request );
666
+		do_action('woocommerce_rest_delete_review', $review, $response, $request);
667 667
 
668 668
 		return $response;
669 669
 	}
@@ -675,52 +675,52 @@  discard block
 block discarded – undo
675 675
 	 * @param \WP_REST_Request $request Request object.
676 676
 	 * @return \WP_REST_Response $response Response data.
677 677
 	 */
678
-	public function prepare_item_for_response( $review, $request ) {
679
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
680
-		$fields  = $this->get_fields_for_response( $request );
678
+	public function prepare_item_for_response($review, $request) {
679
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
680
+		$fields  = $this->get_fields_for_response($request);
681 681
 		$data    = array();
682 682
 
683
-		if ( in_array( 'id', $fields, true ) ) {
683
+		if (in_array('id', $fields, true)) {
684 684
 			$data['id'] = (int) $review->comment_ID;
685 685
 		}
686
-		if ( in_array( 'date_created', $fields, true ) ) {
687
-			$data['date_created'] = wc_rest_prepare_date_response( $review->comment_date );
686
+		if (in_array('date_created', $fields, true)) {
687
+			$data['date_created'] = wc_rest_prepare_date_response($review->comment_date);
688 688
 		}
689
-		if ( in_array( 'date_created_gmt', $fields, true ) ) {
690
-			$data['date_created_gmt'] = wc_rest_prepare_date_response( $review->comment_date_gmt );
689
+		if (in_array('date_created_gmt', $fields, true)) {
690
+			$data['date_created_gmt'] = wc_rest_prepare_date_response($review->comment_date_gmt);
691 691
 		}
692
-		if ( in_array( 'product_id', $fields, true ) ) {
692
+		if (in_array('product_id', $fields, true)) {
693 693
 			$data['product_id'] = (int) $review->comment_post_ID;
694 694
 		}
695
-		if ( in_array( 'status', $fields, true ) ) {
696
-			$data['status'] = $this->prepare_status_response( (string) $review->comment_approved );
695
+		if (in_array('status', $fields, true)) {
696
+			$data['status'] = $this->prepare_status_response((string) $review->comment_approved);
697 697
 		}
698
-		if ( in_array( 'reviewer', $fields, true ) ) {
698
+		if (in_array('reviewer', $fields, true)) {
699 699
 			$data['reviewer'] = $review->comment_author;
700 700
 		}
701
-		if ( in_array( 'reviewer_email', $fields, true ) ) {
701
+		if (in_array('reviewer_email', $fields, true)) {
702 702
 			$data['reviewer_email'] = $review->comment_author_email;
703 703
 		}
704
-		if ( in_array( 'review', $fields, true ) ) {
705
-			$data['review'] = 'view' === $context ? wpautop( $review->comment_content ) : $review->comment_content;
704
+		if (in_array('review', $fields, true)) {
705
+			$data['review'] = 'view' === $context ? wpautop($review->comment_content) : $review->comment_content;
706 706
 		}
707
-		if ( in_array( 'rating', $fields, true ) ) {
708
-			$data['rating'] = (int) get_comment_meta( $review->comment_ID, 'rating', true );
707
+		if (in_array('rating', $fields, true)) {
708
+			$data['rating'] = (int) get_comment_meta($review->comment_ID, 'rating', true);
709 709
 		}
710
-		if ( in_array( 'verified', $fields, true ) ) {
711
-			$data['verified'] = wc_review_is_from_verified_owner( $review->comment_ID );
710
+		if (in_array('verified', $fields, true)) {
711
+			$data['verified'] = wc_review_is_from_verified_owner($review->comment_ID);
712 712
 		}
713
-		if ( in_array( 'reviewer_avatar_urls', $fields, true ) ) {
714
-			$data['reviewer_avatar_urls'] = rest_get_avatar_urls( $review->comment_author_email );
713
+		if (in_array('reviewer_avatar_urls', $fields, true)) {
714
+			$data['reviewer_avatar_urls'] = rest_get_avatar_urls($review->comment_author_email);
715 715
 		}
716 716
 
717
-		$data = $this->add_additional_fields_to_object( $data, $request );
718
-		$data = $this->filter_response_by_context( $data, $context );
717
+		$data = $this->add_additional_fields_to_object($data, $request);
718
+		$data = $this->filter_response_by_context($data, $context);
719 719
 
720 720
 		// Wrap the data in a response object.
721
-		$response = rest_ensure_response( $data );
721
+		$response = rest_ensure_response($data);
722 722
 
723
-		$response->add_links( $this->prepare_links( $review ) );
723
+		$response->add_links($this->prepare_links($review));
724 724
 
725 725
 		/**
726 726
 		 * Filter product reviews object returned from the REST API.
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 		 * @param \WP_Comment       $review   Product review object used to create response.
730 730
 		 * @param \WP_REST_Request  $request  Request object.
731 731
 		 */
732
-		return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request );
732
+		return apply_filters('woocommerce_rest_prepare_product_review', $response, $review, $request);
733 733
 	}
734 734
 
735 735
 	/**
@@ -738,38 +738,38 @@  discard block
 block discarded – undo
738 738
 	 * @param  \WP_REST_Request $request Request object.
739 739
 	 * @return array|\WP_Error  $prepared_review
740 740
 	 */
741
-	protected function prepare_item_for_database( $request ) {
742
-		if ( isset( $request['id'] ) ) {
741
+	protected function prepare_item_for_database($request) {
742
+		if (isset($request['id'])) {
743 743
 			$prepared_review['comment_ID'] = (int) $request['id'];
744 744
 		}
745 745
 
746
-		if ( isset( $request['review'] ) ) {
746
+		if (isset($request['review'])) {
747 747
 			$prepared_review['comment_content'] = $request['review'];
748 748
 		}
749 749
 
750
-		if ( isset( $request['product_id'] ) ) {
750
+		if (isset($request['product_id'])) {
751 751
 			$prepared_review['comment_post_ID'] = (int) $request['product_id'];
752 752
 		}
753 753
 
754
-		if ( isset( $request['reviewer'] ) ) {
754
+		if (isset($request['reviewer'])) {
755 755
 			$prepared_review['comment_author'] = $request['reviewer'];
756 756
 		}
757 757
 
758
-		if ( isset( $request['reviewer_email'] ) ) {
758
+		if (isset($request['reviewer_email'])) {
759 759
 			$prepared_review['comment_author_email'] = $request['reviewer_email'];
760 760
 		}
761 761
 
762
-		if ( ! empty( $request['date_created'] ) ) {
763
-			$date_data = rest_get_date_with_gmt( $request['date_created'] );
762
+		if ( ! empty($request['date_created'])) {
763
+			$date_data = rest_get_date_with_gmt($request['date_created']);
764 764
 
765
-			if ( ! empty( $date_data ) ) {
766
-				list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data;
765
+			if ( ! empty($date_data)) {
766
+				list($prepared_review['comment_date'], $prepared_review['comment_date_gmt']) = $date_data;
767 767
 			}
768
-		} elseif ( ! empty( $request['date_created_gmt'] ) ) {
769
-			$date_data = rest_get_date_with_gmt( $request['date_created_gmt'], true );
768
+		} elseif ( ! empty($request['date_created_gmt'])) {
769
+			$date_data = rest_get_date_with_gmt($request['date_created_gmt'], true);
770 770
 
771
-			if ( ! empty( $date_data ) ) {
772
-				list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data;
771
+			if ( ! empty($date_data)) {
772
+				list($prepared_review['comment_date'], $prepared_review['comment_date_gmt']) = $date_data;
773 773
 			}
774 774
 		}
775 775
 
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 		 * @param array           $prepared_review The prepared review data for `wp_insert_comment`.
783 783
 		 * @param \WP_REST_Request $request         The current request.
784 784
 		 */
785
-		return apply_filters( 'woocommerce_rest_preprocess_product_review', $prepared_review, $request );
785
+		return apply_filters('woocommerce_rest_preprocess_product_review', $prepared_review, $request);
786 786
 	}
787 787
 
788 788
 	/**
@@ -791,24 +791,24 @@  discard block
 block discarded – undo
791 791
 	 * @param WP_Comment $review Product review object.
792 792
 	 * @return array Links for the given product review.
793 793
 	 */
794
-	protected function prepare_links( $review ) {
794
+	protected function prepare_links($review) {
795 795
 		$links = array(
796 796
 			'self'       => array(
797
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $review->comment_ID ) ),
797
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $review->comment_ID)),
798 798
 			),
799 799
 			'collection' => array(
800
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
800
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
801 801
 			),
802 802
 		);
803
-		if ( 0 !== (int) $review->comment_post_ID ) {
803
+		if (0 !== (int) $review->comment_post_ID) {
804 804
 			$links['up'] = array(
805
-				'href'       => rest_url( sprintf( '/%s/products/%d', $this->namespace, $review->comment_post_ID ) ),
805
+				'href'       => rest_url(sprintf('/%s/products/%d', $this->namespace, $review->comment_post_ID)),
806 806
 				'embeddable' => true,
807 807
 			);
808 808
 		}
809
-		if ( 0 !== (int) $review->user_id ) {
809
+		if (0 !== (int) $review->user_id) {
810 810
 			$links['reviewer'] = array(
811
-				'href'       => rest_url( 'wp/v2/users/' . $review->user_id ),
811
+				'href'       => rest_url('wp/v2/users/' . $review->user_id),
812 812
 				'embeddable' => true,
813 813
 			);
814 814
 		}
@@ -827,91 +827,91 @@  discard block
 block discarded – undo
827 827
 			'type'       => 'object',
828 828
 			'properties' => array(
829 829
 				'id'               => array(
830
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
830
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
831 831
 					'type'        => 'integer',
832
-					'context'     => array( 'view', 'edit' ),
832
+					'context'     => array('view', 'edit'),
833 833
 					'readonly'    => true,
834 834
 				),
835 835
 				'date_created'     => array(
836
-					'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ),
836
+					'description' => __("The date the review was created, in the site's timezone.", 'woocommerce'),
837 837
 					'type'        => 'date-time',
838
-					'context'     => array( 'view', 'edit' ),
838
+					'context'     => array('view', 'edit'),
839 839
 					'readonly'    => true,
840 840
 				),
841 841
 				'date_created_gmt' => array(
842
-					'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ),
842
+					'description' => __('The date the review was created, as GMT.', 'woocommerce'),
843 843
 					'type'        => 'date-time',
844
-					'context'     => array( 'view', 'edit' ),
844
+					'context'     => array('view', 'edit'),
845 845
 					'readonly'    => true,
846 846
 				),
847 847
 				'product_id'       => array(
848
-					'description' => __( 'Unique identifier for the product that the review belongs to.', 'woocommerce' ),
848
+					'description' => __('Unique identifier for the product that the review belongs to.', 'woocommerce'),
849 849
 					'type'        => 'integer',
850
-					'context'     => array( 'view', 'edit' ),
850
+					'context'     => array('view', 'edit'),
851 851
 				),
852 852
 				'status'           => array(
853
-					'description' => __( 'Status of the review.', 'woocommerce' ),
853
+					'description' => __('Status of the review.', 'woocommerce'),
854 854
 					'type'        => 'string',
855 855
 					'default'     => 'approved',
856
-					'enum'        => array( 'approved', 'hold', 'spam', 'unspam', 'trash', 'untrash' ),
857
-					'context'     => array( 'view', 'edit' ),
856
+					'enum'        => array('approved', 'hold', 'spam', 'unspam', 'trash', 'untrash'),
857
+					'context'     => array('view', 'edit'),
858 858
 				),
859 859
 				'reviewer'         => array(
860
-					'description' => __( 'Reviewer name.', 'woocommerce' ),
860
+					'description' => __('Reviewer name.', 'woocommerce'),
861 861
 					'type'        => 'string',
862
-					'context'     => array( 'view', 'edit' ),
862
+					'context'     => array('view', 'edit'),
863 863
 				),
864 864
 				'reviewer_email'   => array(
865
-					'description' => __( 'Reviewer email.', 'woocommerce' ),
865
+					'description' => __('Reviewer email.', 'woocommerce'),
866 866
 					'type'        => 'string',
867 867
 					'format'      => 'email',
868
-					'context'     => array( 'view', 'edit' ),
868
+					'context'     => array('view', 'edit'),
869 869
 				),
870 870
 				'review'           => array(
871
-					'description' => __( 'The content of the review.', 'woocommerce' ),
871
+					'description' => __('The content of the review.', 'woocommerce'),
872 872
 					'type'        => 'string',
873
-					'context'     => array( 'view', 'edit' ),
873
+					'context'     => array('view', 'edit'),
874 874
 					'arg_options' => array(
875 875
 						'sanitize_callback' => 'wp_filter_post_kses',
876 876
 					),
877 877
 				),
878 878
 				'rating'           => array(
879
-					'description' => __( 'Review rating (0 to 5).', 'woocommerce' ),
879
+					'description' => __('Review rating (0 to 5).', 'woocommerce'),
880 880
 					'type'        => 'integer',
881
-					'context'     => array( 'view', 'edit' ),
881
+					'context'     => array('view', 'edit'),
882 882
 				),
883 883
 				'verified'         => array(
884
-					'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ),
884
+					'description' => __('Shows if the reviewer bought the product or not.', 'woocommerce'),
885 885
 					'type'        => 'boolean',
886
-					'context'     => array( 'view', 'edit' ),
886
+					'context'     => array('view', 'edit'),
887 887
 					'readonly'    => true,
888 888
 				),
889 889
 			),
890 890
 		);
891 891
 
892
-		if ( get_option( 'show_avatars' ) ) {
892
+		if (get_option('show_avatars')) {
893 893
 			$avatar_properties = array();
894 894
 			$avatar_sizes      = rest_get_avatar_sizes();
895 895
 
896
-			foreach ( $avatar_sizes as $size ) {
897
-				$avatar_properties[ $size ] = array(
896
+			foreach ($avatar_sizes as $size) {
897
+				$avatar_properties[$size] = array(
898 898
 					/* translators: %d: avatar image size in pixels */
899
-					'description' => sprintf( __( 'Avatar URL with image size of %d pixels.', 'woocommerce' ), $size ),
899
+					'description' => sprintf(__('Avatar URL with image size of %d pixels.', 'woocommerce'), $size),
900 900
 					'type'        => 'string',
901 901
 					'format'      => 'uri',
902
-					'context'     => array( 'embed', 'view', 'edit' ),
902
+					'context'     => array('embed', 'view', 'edit'),
903 903
 				);
904 904
 			}
905 905
 			$schema['properties']['reviewer_avatar_urls'] = array(
906
-				'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce' ),
906
+				'description' => __('Avatar URLs for the object reviewer.', 'woocommerce'),
907 907
 				'type'        => 'object',
908
-				'context'     => array( 'view', 'edit' ),
908
+				'context'     => array('view', 'edit'),
909 909
 				'readonly'    => true,
910 910
 				'properties'  => $avatar_properties,
911 911
 			);
912 912
 		}
913 913
 
914
-		return $this->add_additional_fields_schema( $schema );
914
+		return $this->add_additional_fields_schema($schema);
915 915
 	}
916 916
 
917 917
 	/**
@@ -924,38 +924,38 @@  discard block
 block discarded – undo
924 924
 
925 925
 		$params['context']['default'] = 'view';
926 926
 
927
-		$params['after']            = array(
928
-			'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
927
+		$params['after'] = array(
928
+			'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
929 929
 			'type'        => 'string',
930 930
 			'format'      => 'date-time',
931 931
 		);
932
-		$params['before']           = array(
933
-			'description' => __( 'Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce' ),
932
+		$params['before'] = array(
933
+			'description' => __('Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce'),
934 934
 			'type'        => 'string',
935 935
 			'format'      => 'date-time',
936 936
 		);
937
-		$params['exclude']          = array(
938
-			'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
937
+		$params['exclude'] = array(
938
+			'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'),
939 939
 			'type'        => 'array',
940 940
 			'items'       => array(
941 941
 				'type' => 'integer',
942 942
 			),
943 943
 			'default'     => array(),
944 944
 		);
945
-		$params['include']          = array(
946
-			'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ),
945
+		$params['include'] = array(
946
+			'description' => __('Limit result set to specific IDs.', 'woocommerce'),
947 947
 			'type'        => 'array',
948 948
 			'items'       => array(
949 949
 				'type' => 'integer',
950 950
 			),
951 951
 			'default'     => array(),
952 952
 		);
953
-		$params['offset']           = array(
954
-			'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
953
+		$params['offset'] = array(
954
+			'description' => __('Offset the result set by a specific number of items.', 'woocommerce'),
955 955
 			'type'        => 'integer',
956 956
 		);
957
-		$params['order']            = array(
958
-			'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
957
+		$params['order'] = array(
958
+			'description' => __('Order sort attribute ascending or descending.', 'woocommerce'),
959 959
 			'type'        => 'string',
960 960
 			'default'     => 'desc',
961 961
 			'enum'        => array(
@@ -963,8 +963,8 @@  discard block
 block discarded – undo
963 963
 				'desc',
964 964
 			),
965 965
 		);
966
-		$params['orderby']          = array(
967
-			'description' => __( 'Sort collection by object attribute.', 'woocommerce' ),
966
+		$params['orderby'] = array(
967
+			'description' => __('Sort collection by object attribute.', 'woocommerce'),
968 968
 			'type'        => 'string',
969 969
 			'default'     => 'date_gmt',
970 970
 			'enum'        => array(
@@ -975,37 +975,37 @@  discard block
 block discarded – undo
975 975
 				'product',
976 976
 			),
977 977
 		);
978
-		$params['reviewer']         = array(
979
-			'description' => __( 'Limit result set to reviews assigned to specific user IDs.', 'woocommerce' ),
978
+		$params['reviewer'] = array(
979
+			'description' => __('Limit result set to reviews assigned to specific user IDs.', 'woocommerce'),
980 980
 			'type'        => 'array',
981 981
 			'items'       => array(
982 982
 				'type' => 'integer',
983 983
 			),
984 984
 		);
985 985
 		$params['reviewer_exclude'] = array(
986
-			'description' => __( 'Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce' ),
986
+			'description' => __('Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce'),
987 987
 			'type'        => 'array',
988 988
 			'items'       => array(
989 989
 				'type' => 'integer',
990 990
 			),
991 991
 		);
992
-		$params['reviewer_email']   = array(
992
+		$params['reviewer_email'] = array(
993 993
 			'default'     => null,
994
-			'description' => __( 'Limit result set to that from a specific author email.', 'woocommerce' ),
994
+			'description' => __('Limit result set to that from a specific author email.', 'woocommerce'),
995 995
 			'format'      => 'email',
996 996
 			'type'        => 'string',
997 997
 		);
998
-		$params['product']          = array(
998
+		$params['product'] = array(
999 999
 			'default'     => array(),
1000
-			'description' => __( 'Limit result set to reviews assigned to specific product IDs.', 'woocommerce' ),
1000
+			'description' => __('Limit result set to reviews assigned to specific product IDs.', 'woocommerce'),
1001 1001
 			'type'        => 'array',
1002 1002
 			'items'       => array(
1003 1003
 				'type' => 'integer',
1004 1004
 			),
1005 1005
 		);
1006
-		$params['status']           = array(
1006
+		$params['status'] = array(
1007 1007
 			'default'           => 'approved',
1008
-			'description'       => __( 'Limit result set to reviews assigned a specific status.', 'woocommerce' ),
1008
+			'description'       => __('Limit result set to reviews assigned a specific status.', 'woocommerce'),
1009 1009
 			'sanitize_callback' => 'sanitize_key',
1010 1010
 			'type'              => 'string',
1011 1011
 			'enum'              => array(
@@ -1027,7 +1027,7 @@  discard block
 block discarded – undo
1027 1027
 		 * @since 3.5.0
1028 1028
 		 * @param array $params JSON Schema-formatted collection parameters.
1029 1029
 		 */
1030
-		return apply_filters( 'woocommerce_rest_product_review_collection_params', $params );
1030
+		return apply_filters('woocommerce_rest_product_review_collection_params', $params);
1031 1031
 	}
1032 1032
 
1033 1033
 	/**
@@ -1037,24 +1037,24 @@  discard block
 block discarded – undo
1037 1037
 	 * @param int $id Supplied ID.
1038 1038
 	 * @return WP_Comment|\WP_Error Comment object if ID is valid, \WP_Error otherwise.
1039 1039
 	 */
1040
-	protected function get_review( $id ) {
1040
+	protected function get_review($id) {
1041 1041
 		$id    = (int) $id;
1042
-		$error = new \WP_Error( 'woocommerce_rest_review_invalid_id', __( 'Invalid review ID.', 'woocommerce' ), array( 'status' => 404 ) );
1042
+		$error = new \WP_Error('woocommerce_rest_review_invalid_id', __('Invalid review ID.', 'woocommerce'), array('status' => 404));
1043 1043
 
1044
-		if ( 0 >= $id ) {
1044
+		if (0 >= $id) {
1045 1045
 			return $error;
1046 1046
 		}
1047 1047
 
1048
-		$review = get_comment( $id );
1049
-		if ( empty( $review ) ) {
1048
+		$review = get_comment($id);
1049
+		if (empty($review)) {
1050 1050
 			return $error;
1051 1051
 		}
1052 1052
 
1053
-		if ( ! empty( $review->comment_post_ID ) ) {
1054
-			$post = get_post( (int) $review->comment_post_ID );
1053
+		if ( ! empty($review->comment_post_ID)) {
1054
+			$post = get_post((int) $review->comment_post_ID);
1055 1055
 
1056
-			if ( 'product' !== get_post_type( (int) $review->comment_post_ID ) ) {
1057
-				return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) );
1056
+			if ('product' !== get_post_type((int) $review->comment_post_ID)) {
1057
+				return new \WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404));
1058 1058
 			}
1059 1059
 		}
1060 1060
 
@@ -1068,10 +1068,10 @@  discard block
 block discarded – undo
1068 1068
 	 * @param string $query_param Query parameter.
1069 1069
 	 * @return string
1070 1070
 	 */
1071
-	protected function normalize_query_param( $query_param ) {
1071
+	protected function normalize_query_param($query_param) {
1072 1072
 		$prefix = 'comment_';
1073 1073
 
1074
-		switch ( $query_param ) {
1074
+		switch ($query_param) {
1075 1075
 			case 'id':
1076 1076
 				$normalized = $prefix . 'ID';
1077 1077
 				break;
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
 	 * @param string|int $comment_approved comment status.
1097 1097
 	 * @return string Comment status.
1098 1098
 	 */
1099
-	protected function prepare_status_response( $comment_approved ) {
1100
-		switch ( $comment_approved ) {
1099
+	protected function prepare_status_response($comment_approved) {
1100
+		switch ($comment_approved) {
1101 1101
 			case 'hold':
1102 1102
 			case '0':
1103 1103
 				$status = 'hold';
@@ -1124,34 +1124,34 @@  discard block
 block discarded – undo
1124 1124
 	 * @param int        $id         Review ID.
1125 1125
 	 * @return bool Whether the status was changed.
1126 1126
 	 */
1127
-	protected function handle_status_param( $new_status, $id ) {
1128
-		$old_status = wp_get_comment_status( $id );
1127
+	protected function handle_status_param($new_status, $id) {
1128
+		$old_status = wp_get_comment_status($id);
1129 1129
 
1130
-		if ( $new_status === $old_status ) {
1130
+		if ($new_status === $old_status) {
1131 1131
 			return false;
1132 1132
 		}
1133 1133
 
1134
-		switch ( $new_status ) {
1134
+		switch ($new_status) {
1135 1135
 			case 'approved':
1136 1136
 			case 'approve':
1137 1137
 			case '1':
1138
-				$changed = wp_set_comment_status( $id, 'approve' );
1138
+				$changed = wp_set_comment_status($id, 'approve');
1139 1139
 				break;
1140 1140
 			case 'hold':
1141 1141
 			case '0':
1142
-				$changed = wp_set_comment_status( $id, 'hold' );
1142
+				$changed = wp_set_comment_status($id, 'hold');
1143 1143
 				break;
1144 1144
 			case 'spam':
1145
-				$changed = wp_spam_comment( $id );
1145
+				$changed = wp_spam_comment($id);
1146 1146
 				break;
1147 1147
 			case 'unspam':
1148
-				$changed = wp_unspam_comment( $id );
1148
+				$changed = wp_unspam_comment($id);
1149 1149
 				break;
1150 1150
 			case 'trash':
1151
-				$changed = wp_trash_comment( $id );
1151
+				$changed = wp_trash_comment($id);
1152 1152
 				break;
1153 1153
 			case 'untrash':
1154
-				$changed = wp_untrash_comment( $id );
1154
+				$changed = wp_untrash_comment($id);
1155 1155
 				break;
1156 1156
 			default:
1157 1157
 				$changed = false;
Please login to merge, or discard this patch.
src/Controllers/Version4/Webhooks.php 1 patch
Spacing   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Webhooks controller class.
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
 			array(
41 41
 				array(
42 42
 					'methods'             => \WP_REST_Server::READABLE,
43
-					'callback'            => array( $this, 'get_items' ),
44
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
43
+					'callback'            => array($this, 'get_items'),
44
+					'permission_callback' => array($this, 'get_items_permissions_check'),
45 45
 					'args'                => $this->get_collection_params(),
46 46
 				),
47 47
 				array(
48 48
 					'methods'             => \WP_REST_Server::CREATABLE,
49
-					'callback'            => array( $this, 'create_item' ),
50
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
49
+					'callback'            => array($this, 'create_item'),
50
+					'permission_callback' => array($this, 'create_item_permissions_check'),
51 51
 					'args'                => array_merge(
52
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
52
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
53 53
 						array(
54 54
 							'topic'        => array(
55 55
 								'required'    => true,
56 56
 								'type'        => 'string',
57
-								'description' => __( 'Webhook topic.', 'woocommerce' ),
57
+								'description' => __('Webhook topic.', 'woocommerce'),
58 58
 							),
59 59
 							'delivery_url' => array(
60 60
 								'required'    => true,
61 61
 								'type'        => 'string',
62
-								'description' => __( 'Webhook delivery URL.', 'woocommerce' ),
62
+								'description' => __('Webhook delivery URL.', 'woocommerce'),
63 63
 							),
64 64
 						)
65 65
 					),
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
 		);
@@ -75,37 +75,37 @@  discard block
 block discarded – undo
75 75
 			array(
76 76
 				'args'   => array(
77 77
 					'id' => array(
78
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
78
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
79 79
 						'type'        => 'integer',
80 80
 					),
81 81
 				),
82 82
 				array(
83 83
 					'methods'             => \WP_REST_Server::READABLE,
84
-					'callback'            => array( $this, 'get_item' ),
85
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
84
+					'callback'            => array($this, 'get_item'),
85
+					'permission_callback' => array($this, 'get_item_permissions_check'),
86 86
 					'args'                => array(
87
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
87
+						'context' => $this->get_context_param(array('default' => 'view')),
88 88
 					),
89 89
 				),
90 90
 				array(
91 91
 					'methods'             => \WP_REST_Server::EDITABLE,
92
-					'callback'            => array( $this, 'update_item' ),
93
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
94
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
92
+					'callback'            => array($this, 'update_item'),
93
+					'permission_callback' => array($this, 'update_item_permissions_check'),
94
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
95 95
 				),
96 96
 				array(
97 97
 					'methods'             => \WP_REST_Server::DELETABLE,
98
-					'callback'            => array( $this, 'delete_item' ),
99
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
98
+					'callback'            => array($this, 'delete_item'),
99
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
100 100
 					'args'                => array(
101 101
 						'force' => array(
102 102
 							'default'     => false,
103 103
 							'type'        => 'boolean',
104
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
104
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
105 105
 						),
106 106
 					),
107 107
 				),
108
-				'schema' => array( $this, 'get_public_item_schema' ),
108
+				'schema' => array($this, 'get_public_item_schema'),
109 109
 			),
110 110
 			true
111 111
 		);
@@ -116,11 +116,11 @@  discard block
 block discarded – undo
116 116
 			array(
117 117
 				array(
118 118
 					'methods'             => \WP_REST_Server::EDITABLE,
119
-					'callback'            => array( $this, 'batch_items' ),
120
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
121
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
119
+					'callback'            => array($this, 'batch_items'),
120
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
121
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
122 122
 				),
123
-				'schema' => array( $this, 'get_public_batch_schema' ),
123
+				'schema' => array($this, 'get_public_batch_schema'),
124 124
 			),
125 125
 			true
126 126
 		);
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
 	 * @param  \WP_REST_Request $request Full details about the request.
133 133
 	 * @return \WP_Error|boolean
134 134
 	 */
135
-	public function get_items_permissions_check( $request ) {
136
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) {
137
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
135
+	public function get_items_permissions_check($request) {
136
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) {
137
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
138 138
 		}
139 139
 
140 140
 		return true;
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
 	 *
148 148
 	 * @return bool|\WP_Error
149 149
 	 */
150
-	public function create_item_permissions_check( $request ) {
151
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'create' ) ) {
152
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
150
+	public function create_item_permissions_check($request) {
151
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'create')) {
152
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
153 153
 		}
154 154
 
155 155
 		return true;
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 * @param  \WP_REST_Request $request Full details about the request.
162 162
 	 * @return \WP_Error|boolean
163 163
 	 */
164
-	public function get_item_permissions_check( $request ) {
165
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) {
166
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
164
+	public function get_item_permissions_check($request) {
165
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) {
166
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
167 167
 		}
168 168
 
169 169
 		return true;
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 	 *
177 177
 	 * @return bool|\WP_Error
178 178
 	 */
179
-	public function update_item_permissions_check( $request ) {
180
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'edit' ) ) {
181
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
179
+	public function update_item_permissions_check($request) {
180
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'edit')) {
181
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
182 182
 		}
183 183
 
184 184
 		return true;
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
 	 *
192 192
 	 * @return bool|\WP_Error
193 193
 	 */
194
-	public function delete_item_permissions_check( $request ) {
195
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'delete' ) ) {
196
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
194
+	public function delete_item_permissions_check($request) {
195
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'delete')) {
196
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
197 197
 		}
198 198
 
199 199
 		return true;
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 	 *
207 207
 	 * @return bool|\WP_Error
208 208
 	 */
209
-	public function batch_items_permissions_check( $request ) {
210
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'batch' ) ) {
211
-			return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
209
+	public function batch_items_permissions_check($request) {
210
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'batch')) {
211
+			return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
212 212
 		}
213 213
 
214 214
 		return true;
@@ -230,20 +230,20 @@  discard block
 block discarded – undo
230 230
 	 * @param \WP_REST_Request $request Full details about the request.
231 231
 	 * @return \WP_Error\WP_REST_Response
232 232
 	 */
233
-	public function get_items( $request ) {
233
+	public function get_items($request) {
234 234
 		$args            = array();
235 235
 		$args['order']   = $request['order'];
236 236
 		$args['orderby'] = $request['orderby'];
237 237
 		$args['status']  = 'all' === $request['status'] ? '' : $request['status'];
238
-		$args['include'] = implode( ',', $request['include'] );
239
-		$args['exclude'] = implode( ',', $request['exclude'] );
238
+		$args['include'] = implode(',', $request['include']);
239
+		$args['exclude'] = implode(',', $request['exclude']);
240 240
 		$args['limit']   = $request['per_page'];
241 241
 		$args['search']  = $request['search'];
242 242
 		$args['before']  = $request['before'];
243 243
 		$args['after']   = $request['after'];
244 244
 
245
-		if ( empty( $request['offset'] ) ) {
246
-			$args['offset'] = 1 < $request['page'] ? ( $request['page'] - 1 ) * $args['limit'] : 0;
245
+		if (empty($request['offset'])) {
246
+			$args['offset'] = 1 < $request['page'] ? ($request['page'] - 1) * $args['limit'] : 0;
247 247
 		}
248 248
 
249 249
 		/**
@@ -252,43 +252,43 @@  discard block
 block discarded – undo
252 252
 		 * @param array           $args    Array of arguments for $wpdb->get_results().
253 253
 		 * @param \WP_REST_Request $request The current request.
254 254
 		 */
255
-		$prepared_args = apply_filters( 'woocommerce_rest_webhook_query', $args, $request );
256
-		unset( $prepared_args['page'] );
255
+		$prepared_args = apply_filters('woocommerce_rest_webhook_query', $args, $request);
256
+		unset($prepared_args['page']);
257 257
 		$prepared_args['paginate'] = true;
258 258
 
259 259
 		// Get the webhooks.
260 260
 		$webhooks    = array();
261
-		$data_store  = \WC_Data_Store::load( 'webhook' );
262
-		$results     = $data_store->search_webhooks( $prepared_args );
261
+		$data_store  = \WC_Data_Store::load('webhook');
262
+		$results     = $data_store->search_webhooks($prepared_args);
263 263
 		$webhook_ids = $results->webhooks;
264 264
 
265
-		foreach ( $webhook_ids as $webhook_id ) {
266
-			$data       = $this->prepare_item_for_response( $webhook_id, $request );
267
-			$webhooks[] = $this->prepare_response_for_collection( $data );
265
+		foreach ($webhook_ids as $webhook_id) {
266
+			$data       = $this->prepare_item_for_response($webhook_id, $request);
267
+			$webhooks[] = $this->prepare_response_for_collection($data);
268 268
 		}
269 269
 
270
-		$response       = rest_ensure_response( $webhooks );
270
+		$response       = rest_ensure_response($webhooks);
271 271
 		$per_page       = (int) $prepared_args['limit'];
272
-		$page           = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
272
+		$page           = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
273 273
 		$total_webhooks = $results->total;
274 274
 		$max_pages      = $results->max_num_pages;
275
-		$base           = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
275
+		$base           = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
276 276
 
277
-		$response->header( 'X-WP-Total', $total_webhooks );
278
-		$response->header( 'X-WP-TotalPages', $max_pages );
277
+		$response->header('X-WP-Total', $total_webhooks);
278
+		$response->header('X-WP-TotalPages', $max_pages);
279 279
 
280
-		if ( $page > 1 ) {
280
+		if ($page > 1) {
281 281
 			$prev_page = $page - 1;
282
-			if ( $prev_page > $max_pages ) {
282
+			if ($prev_page > $max_pages) {
283 283
 				$prev_page = $max_pages;
284 284
 			}
285
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
286
-			$response->link_header( 'prev', $prev_link );
285
+			$prev_link = add_query_arg('page', $prev_page, $base);
286
+			$response->link_header('prev', $prev_link);
287 287
 		}
288
-		if ( $max_pages > $page ) {
288
+		if ($max_pages > $page) {
289 289
 			$next_page = $page + 1;
290
-			$next_link = add_query_arg( 'page', $next_page, $base );
291
-			$response->link_header( 'next', $next_link );
290
+			$next_link = add_query_arg('page', $next_page, $base);
291
+			$response->link_header('next', $next_link);
292 292
 		}
293 293
 
294 294
 		return $response;
@@ -300,15 +300,15 @@  discard block
 block discarded – undo
300 300
 	 * @param \WP_REST_Request $request Full details about the request.
301 301
 	 * @return \WP_Error\WP_REST_Response
302 302
 	 */
303
-	public function get_item( $request ) {
303
+	public function get_item($request) {
304 304
 		$id = (int) $request['id'];
305 305
 
306
-		if ( empty( $id ) ) {
307
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
306
+		if (empty($id)) {
307
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
308 308
 		}
309 309
 
310
-		$data     = $this->prepare_item_for_response( $id, $request );
311
-		$response = rest_ensure_response( $data );
310
+		$data     = $this->prepare_item_for_response($id, $request);
311
+		$response = rest_ensure_response($data);
312 312
 
313 313
 		return $response;
314 314
 	}
@@ -319,38 +319,38 @@  discard block
 block discarded – undo
319 319
 	 * @param \WP_REST_Request $request Full details about the request.
320 320
 	 * @return \WP_Error\WP_REST_Response
321 321
 	 */
322
-	public function create_item( $request ) {
323
-		if ( ! empty( $request['id'] ) ) {
322
+	public function create_item($request) {
323
+		if ( ! empty($request['id'])) {
324 324
 			/* translators: %s: post type */
325
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
325
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
326 326
 		}
327 327
 
328 328
 		// Validate topic.
329
-		if ( empty( $request['topic'] ) || ! wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) {
330
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic is required and must be valid.', 'woocommerce' ), array( 'status' => 400 ) );
329
+		if (empty($request['topic']) || ! wc_is_webhook_valid_topic(strtolower($request['topic']))) {
330
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic is required and must be valid.', 'woocommerce'), array('status' => 400));
331 331
 		}
332 332
 
333 333
 		// Validate delivery URL.
334
-		if ( empty( $request['delivery_url'] ) || ! wc_is_valid_url( $request['delivery_url'] ) ) {
335
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) );
334
+		if (empty($request['delivery_url']) || ! wc_is_valid_url($request['delivery_url'])) {
335
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400));
336 336
 		}
337 337
 
338
-		$post = $this->prepare_item_for_database( $request );
339
-		if ( is_wp_error( $post ) ) {
338
+		$post = $this->prepare_item_for_database($request);
339
+		if (is_wp_error($post)) {
340 340
 			return $post;
341 341
 		}
342 342
 
343 343
 		$webhook = new \WC_Webhook();
344
-		$webhook->set_name( $post->post_title );
345
-		$webhook->set_user_id( $post->post_author );
346
-		$webhook->set_status( 'publish' === $post->post_status ? 'active' : 'disabled' );
347
-		$webhook->set_topic( $request['topic'] );
348
-		$webhook->set_delivery_url( $request['delivery_url'] );
349
-		$webhook->set_secret( ! empty( $request['secret'] ) ? $request['secret'] : wp_generate_password( 50, true, true ) );
350
-		$webhook->set_api_version( $this->get_default_api_version() );
344
+		$webhook->set_name($post->post_title);
345
+		$webhook->set_user_id($post->post_author);
346
+		$webhook->set_status('publish' === $post->post_status ? 'active' : 'disabled');
347
+		$webhook->set_topic($request['topic']);
348
+		$webhook->set_delivery_url($request['delivery_url']);
349
+		$webhook->set_secret( ! empty($request['secret']) ? $request['secret'] : wp_generate_password(50, true, true));
350
+		$webhook->set_api_version($this->get_default_api_version());
351 351
 		$webhook->save();
352 352
 
353
-		$this->update_additional_fields_for_object( $webhook, $request );
353
+		$this->update_additional_fields_for_object($webhook, $request);
354 354
 
355 355
 		/**
356 356
 		 * Fires after a single item is created or updated via the REST API.
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
 		 * @param \WP_REST_Request $request  Request object.
360 360
 		 * @param bool            $creating True when creating item, false when updating.
361 361
 		 */
362
-		do_action( 'woocommerce_rest_insert_webhook_object', $webhook, $request, true );
362
+		do_action('woocommerce_rest_insert_webhook_object', $webhook, $request, true);
363 363
 
364
-		$request->set_param( 'context', 'edit' );
365
-		$response = $this->prepare_item_for_response( $webhook->get_id(), $request );
366
-		$response = rest_ensure_response( $response );
367
-		$response->set_status( 201 );
368
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id() ) ) );
364
+		$request->set_param('context', 'edit');
365
+		$response = $this->prepare_item_for_response($webhook->get_id(), $request);
366
+		$response = rest_ensure_response($response);
367
+		$response->set_status(201);
368
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id())));
369 369
 
370 370
 		// Send ping.
371 371
 		$webhook->deliver_ping();
@@ -379,58 +379,58 @@  discard block
 block discarded – undo
379 379
 	 * @param \WP_REST_Request $request Full details about the request.
380 380
 	 * @return \WP_Error\WP_REST_Response
381 381
 	 */
382
-	public function update_item( $request ) {
382
+	public function update_item($request) {
383 383
 		$id      = (int) $request['id'];
384
-		$webhook = wc_get_webhook( $id );
384
+		$webhook = wc_get_webhook($id);
385 385
 
386
-		if ( empty( $webhook ) || is_null( $webhook ) ) {
387
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
386
+		if (empty($webhook) || is_null($webhook)) {
387
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400));
388 388
 		}
389 389
 
390 390
 		// Update topic.
391
-		if ( ! empty( $request['topic'] ) ) {
392
-			if ( wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) {
393
-				$webhook->set_topic( $request['topic'] );
391
+		if ( ! empty($request['topic'])) {
392
+			if (wc_is_webhook_valid_topic(strtolower($request['topic']))) {
393
+				$webhook->set_topic($request['topic']);
394 394
 			} else {
395
-				return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic must be valid.', 'woocommerce' ), array( 'status' => 400 ) );
395
+				return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic must be valid.', 'woocommerce'), array('status' => 400));
396 396
 			}
397 397
 		}
398 398
 
399 399
 		// Update delivery URL.
400
-		if ( ! empty( $request['delivery_url'] ) ) {
401
-			if ( wc_is_valid_url( $request['delivery_url'] ) ) {
402
-				$webhook->set_delivery_url( $request['delivery_url'] );
400
+		if ( ! empty($request['delivery_url'])) {
401
+			if (wc_is_valid_url($request['delivery_url'])) {
402
+				$webhook->set_delivery_url($request['delivery_url']);
403 403
 			} else {
404
-				return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) );
404
+				return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400));
405 405
 			}
406 406
 		}
407 407
 
408 408
 		// Update secret.
409
-		if ( ! empty( $request['secret'] ) ) {
410
-			$webhook->set_secret( $request['secret'] );
409
+		if ( ! empty($request['secret'])) {
410
+			$webhook->set_secret($request['secret']);
411 411
 		}
412 412
 
413 413
 		// Update status.
414
-		if ( ! empty( $request['status'] ) ) {
415
-			if ( wc_is_webhook_valid_status( strtolower( $request['status'] ) ) ) {
416
-				$webhook->set_status( $request['status'] );
414
+		if ( ! empty($request['status'])) {
415
+			if (wc_is_webhook_valid_status(strtolower($request['status']))) {
416
+				$webhook->set_status($request['status']);
417 417
 			} else {
418
-				return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_status", __( 'Webhook status must be valid.', 'woocommerce' ), array( 'status' => 400 ) );
418
+				return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_status", __('Webhook status must be valid.', 'woocommerce'), array('status' => 400));
419 419
 			}
420 420
 		}
421 421
 
422
-		$post = $this->prepare_item_for_database( $request );
423
-		if ( is_wp_error( $post ) ) {
422
+		$post = $this->prepare_item_for_database($request);
423
+		if (is_wp_error($post)) {
424 424
 			return $post;
425 425
 		}
426 426
 
427
-		if ( isset( $post->post_title ) ) {
428
-			$webhook->set_name( $post->post_title );
427
+		if (isset($post->post_title)) {
428
+			$webhook->set_name($post->post_title);
429 429
 		}
430 430
 
431 431
 		$webhook->save();
432 432
 
433
-		$this->update_additional_fields_for_object( $webhook, $request );
433
+		$this->update_additional_fields_for_object($webhook, $request);
434 434
 
435 435
 		/**
436 436
 		 * Fires after a single item is created or updated via the REST API.
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
 		 * @param \WP_REST_Request $request  Request object.
440 440
 		 * @param bool            $creating True when creating item, false when updating.
441 441
 		 */
442
-		do_action( 'woocommerce_rest_insert_webhook_object', $webhook, $request, false );
442
+		do_action('woocommerce_rest_insert_webhook_object', $webhook, $request, false);
443 443
 
444
-		$request->set_param( 'context', 'edit' );
445
-		$response = $this->prepare_item_for_response( $webhook->get_id(), $request );
444
+		$request->set_param('context', 'edit');
445
+		$response = $this->prepare_item_for_response($webhook->get_id(), $request);
446 446
 
447
-		return rest_ensure_response( $response );
447
+		return rest_ensure_response($response);
448 448
 	}
449 449
 
450 450
 	/**
@@ -453,27 +453,27 @@  discard block
 block discarded – undo
453 453
 	 * @param \WP_REST_Request $request Full details about the request.
454 454
 	 * @return \WP_REST_Response|\WP_Error
455 455
 	 */
456
-	public function delete_item( $request ) {
456
+	public function delete_item($request) {
457 457
 		$id    = (int) $request['id'];
458
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
458
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
459 459
 
460 460
 		// We don't support trashing for this type, error out.
461
-		if ( ! $force ) {
462
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
461
+		if ( ! $force) {
462
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501));
463 463
 		}
464 464
 
465
-		$webhook = wc_get_webhook( $id );
465
+		$webhook = wc_get_webhook($id);
466 466
 
467
-		if ( empty( $webhook ) || is_null( $webhook ) ) {
468
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
467
+		if (empty($webhook) || is_null($webhook)) {
468
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
469 469
 		}
470 470
 
471
-		$request->set_param( 'context', 'edit' );
472
-		$previous = $this->prepare_item_for_response( $webhook, $request );
473
-		$result   = $webhook->delete( true );
474
-		if ( ! $result ) {
471
+		$request->set_param('context', 'edit');
472
+		$previous = $this->prepare_item_for_response($webhook, $request);
473
+		$result   = $webhook->delete(true);
474
+		if ( ! $result) {
475 475
 			/* translators: %s: post type */
476
-			return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
476
+			return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500));
477 477
 		}
478 478
 		$response = new \WP_REST_Response();
479 479
 		$response->set_data(
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 		 * @param \WP_REST_Response $response The response data.
491 491
 		 * @param \WP_REST_Request  $request  The request sent to the API.
492 492
 		 */
493
-		do_action( 'woocommerce_rest_delete_webhook_object', $webhook, $response, $request );
493
+		do_action('woocommerce_rest_delete_webhook_object', $webhook, $response, $request);
494 494
 
495 495
 		return $response;
496 496
 	}
@@ -501,17 +501,17 @@  discard block
 block discarded – undo
501 501
 	 * @param \WP_REST_Request $request Request object.
502 502
 	 * @return \WP_Error|stdClass $data Post object.
503 503
 	 */
504
-	protected function prepare_item_for_database( $request ) {
504
+	protected function prepare_item_for_database($request) {
505 505
 		$data = new \stdClass();
506 506
 
507 507
 		// Post ID.
508
-		if ( isset( $request['id'] ) ) {
509
-			$data->ID = absint( $request['id'] );
508
+		if (isset($request['id'])) {
509
+			$data->ID = absint($request['id']);
510 510
 		}
511 511
 
512 512
 		// Validate required POST fields.
513
-		if ( 'POST' === $request->get_method() && empty( $data->ID ) ) {
514
-			$data->post_title = ! empty( $request['name'] ) ? $request['name'] : sprintf( __( 'Webhook created on %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) ); // @codingStandardsIgnoreLine
513
+		if ('POST' === $request->get_method() && empty($data->ID)) {
514
+			$data->post_title = ! empty($request['name']) ? $request['name'] : sprintf(__('Webhook created on %s', 'woocommerce'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce'))); // @codingStandardsIgnoreLine
515 515
 
516 516
 			// Post author.
517 517
 			$data->post_author = get_current_user_id();
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 		} else {
525 525
 
526 526
 			// Allow edit post title.
527
-			if ( ! empty( $request['name'] ) ) {
527
+			if ( ! empty($request['name'])) {
528 528
 				$data->post_title = $request['name'];
529 529
 			}
530 530
 		}
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 		 *                                       for inserting or updating the database.
546 546
 		 * @param \WP_REST_Request $request       Request object.
547 547
 		 */
548
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $data, $request );
548
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $data, $request);
549 549
 	}
550 550
 
551 551
 	/**
@@ -555,11 +555,11 @@  discard block
 block discarded – undo
555 555
 	 * @param \WP_REST_Request $request  Request object.
556 556
 	 * @return \WP_REST_Response $response
557 557
 	 */
558
-	public function prepare_item_for_response( $id, $request ) {
559
-		$webhook = wc_get_webhook( $id );
558
+	public function prepare_item_for_response($id, $request) {
559
+		$webhook = wc_get_webhook($id);
560 560
 
561
-		if ( empty( $webhook ) || is_null( $webhook ) ) {
562
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
561
+		if (empty($webhook) || is_null($webhook)) {
562
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400));
563 563
 		}
564 564
 
565 565
 		$data = array(
@@ -571,20 +571,20 @@  discard block
 block discarded – undo
571 571
 			'event'             => $webhook->get_event(),
572 572
 			'hooks'             => $webhook->get_hooks(),
573 573
 			'delivery_url'      => $webhook->get_delivery_url(),
574
-			'date_created'      => wc_rest_prepare_date_response( $webhook->get_date_created(), false ),
575
-			'date_created_gmt'  => wc_rest_prepare_date_response( $webhook->get_date_created() ),
576
-			'date_modified'     => wc_rest_prepare_date_response( $webhook->get_date_modified(), false ),
577
-			'date_modified_gmt' => wc_rest_prepare_date_response( $webhook->get_date_modified() ),
574
+			'date_created'      => wc_rest_prepare_date_response($webhook->get_date_created(), false),
575
+			'date_created_gmt'  => wc_rest_prepare_date_response($webhook->get_date_created()),
576
+			'date_modified'     => wc_rest_prepare_date_response($webhook->get_date_modified(), false),
577
+			'date_modified_gmt' => wc_rest_prepare_date_response($webhook->get_date_modified()),
578 578
 		);
579 579
 
580
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
581
-		$data    = $this->add_additional_fields_to_object( $data, $request );
582
-		$data    = $this->filter_response_by_context( $data, $context );
580
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
581
+		$data    = $this->add_additional_fields_to_object($data, $request);
582
+		$data    = $this->filter_response_by_context($data, $context);
583 583
 
584 584
 		// Wrap the data in a response object.
585
-		$response = rest_ensure_response( $data );
585
+		$response = rest_ensure_response($data);
586 586
 
587
-		$response->add_links( $this->prepare_links( $webhook->get_id(), $request ) );
587
+		$response->add_links($this->prepare_links($webhook->get_id(), $request));
588 588
 
589 589
 		/**
590 590
 		 * Filter webhook object returned from the REST API.
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
 		 * @param WC_Webhook       $webhook  Webhook object used to create response.
594 594
 		 * @param \WP_REST_Request  $request  Request object.
595 595
 		 */
596
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request );
596
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request);
597 597
 	}
598 598
 
599 599
 	/**
@@ -602,13 +602,13 @@  discard block
 block discarded – undo
602 602
 	 * @param int $id Webhook ID.
603 603
 	 * @return array
604 604
 	 */
605
-	protected function prepare_links( $id ) {
605
+	protected function prepare_links($id) {
606 606
 		$links = array(
607 607
 			'self'       => array(
608
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $id ) ),
608
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $id)),
609 609
 			),
610 610
 			'collection' => array(
611
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
611
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
612 612
 			),
613 613
 		);
614 614
 
@@ -627,89 +627,89 @@  discard block
 block discarded – undo
627 627
 			'type'       => 'object',
628 628
 			'properties' => array(
629 629
 				'id'                => array(
630
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
630
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
631 631
 					'type'        => 'integer',
632
-					'context'     => array( 'view', 'edit' ),
632
+					'context'     => array('view', 'edit'),
633 633
 					'readonly'    => true,
634 634
 				),
635 635
 				'name'              => array(
636
-					'description' => __( 'A friendly name for the webhook.', 'woocommerce' ),
636
+					'description' => __('A friendly name for the webhook.', 'woocommerce'),
637 637
 					'type'        => 'string',
638
-					'context'     => array( 'view', 'edit' ),
638
+					'context'     => array('view', 'edit'),
639 639
 				),
640 640
 				'status'            => array(
641
-					'description' => __( 'Webhook status.', 'woocommerce' ),
641
+					'description' => __('Webhook status.', 'woocommerce'),
642 642
 					'type'        => 'string',
643 643
 					'default'     => 'active',
644
-					'enum'        => array_keys( wc_get_webhook_statuses() ),
645
-					'context'     => array( 'view', 'edit' ),
644
+					'enum'        => array_keys(wc_get_webhook_statuses()),
645
+					'context'     => array('view', 'edit'),
646 646
 				),
647 647
 				'topic'             => array(
648
-					'description' => __( 'Webhook topic.', 'woocommerce' ),
648
+					'description' => __('Webhook topic.', 'woocommerce'),
649 649
 					'type'        => 'string',
650
-					'context'     => array( 'view', 'edit' ),
650
+					'context'     => array('view', 'edit'),
651 651
 				),
652 652
 				'resource'          => array(
653
-					'description' => __( 'Webhook resource.', 'woocommerce' ),
653
+					'description' => __('Webhook resource.', 'woocommerce'),
654 654
 					'type'        => 'string',
655
-					'context'     => array( 'view', 'edit' ),
655
+					'context'     => array('view', 'edit'),
656 656
 					'readonly'    => true,
657 657
 				),
658 658
 				'event'             => array(
659
-					'description' => __( 'Webhook event.', 'woocommerce' ),
659
+					'description' => __('Webhook event.', 'woocommerce'),
660 660
 					'type'        => 'string',
661
-					'context'     => array( 'view', 'edit' ),
661
+					'context'     => array('view', 'edit'),
662 662
 					'readonly'    => true,
663 663
 				),
664 664
 				'hooks'             => array(
665
-					'description' => __( 'WooCommerce action names associated with the webhook.', 'woocommerce' ),
665
+					'description' => __('WooCommerce action names associated with the webhook.', 'woocommerce'),
666 666
 					'type'        => 'array',
667
-					'context'     => array( 'view', 'edit' ),
667
+					'context'     => array('view', 'edit'),
668 668
 					'readonly'    => true,
669 669
 					'items'       => array(
670 670
 						'type' => 'string',
671 671
 					),
672 672
 				),
673 673
 				'delivery_url'      => array(
674
-					'description' => __( 'The URL where the webhook payload is delivered.', 'woocommerce' ),
674
+					'description' => __('The URL where the webhook payload is delivered.', 'woocommerce'),
675 675
 					'type'        => 'string',
676 676
 					'format'      => 'uri',
677
-					'context'     => array( 'view', 'edit' ),
677
+					'context'     => array('view', 'edit'),
678 678
 					'readonly'    => true,
679 679
 				),
680 680
 				'secret'            => array(
681
-					'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ),
681
+					'description' => __("Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce'),
682 682
 					'type'        => 'string',
683
-					'context'     => array( 'edit' ),
683
+					'context'     => array('edit'),
684 684
 				),
685 685
 				'date_created'      => array(
686
-					'description' => __( "The date the webhook was created, in the site's timezone.", 'woocommerce' ),
686
+					'description' => __("The date the webhook was created, in the site's timezone.", 'woocommerce'),
687 687
 					'type'        => 'date-time',
688
-					'context'     => array( 'view', 'edit' ),
688
+					'context'     => array('view', 'edit'),
689 689
 					'readonly'    => true,
690 690
 				),
691 691
 				'date_created_gmt'  => array(
692
-					'description' => __( 'The date the webhook was created, as GMT.', 'woocommerce' ),
692
+					'description' => __('The date the webhook was created, as GMT.', 'woocommerce'),
693 693
 					'type'        => 'date-time',
694
-					'context'     => array( 'view', 'edit' ),
694
+					'context'     => array('view', 'edit'),
695 695
 					'readonly'    => true,
696 696
 				),
697 697
 				'date_modified'     => array(
698
-					'description' => __( "The date the webhook was last modified, in the site's timezone.", 'woocommerce' ),
698
+					'description' => __("The date the webhook was last modified, in the site's timezone.", 'woocommerce'),
699 699
 					'type'        => 'date-time',
700
-					'context'     => array( 'view', 'edit' ),
700
+					'context'     => array('view', 'edit'),
701 701
 					'readonly'    => true,
702 702
 				),
703 703
 				'date_modified_gmt' => array(
704
-					'description' => __( 'The date the webhook was last modified, as GMT.', 'woocommerce' ),
704
+					'description' => __('The date the webhook was last modified, as GMT.', 'woocommerce'),
705 705
 					'type'        => 'date-time',
706
-					'context'     => array( 'view', 'edit' ),
706
+					'context'     => array('view', 'edit'),
707 707
 					'readonly'    => true,
708 708
 				),
709 709
 			),
710 710
 		);
711 711
 
712
-		return $this->add_additional_fields_schema( $schema );
712
+		return $this->add_additional_fields_schema($schema);
713 713
 	}
714 714
 
715 715
 	/**
@@ -722,20 +722,20 @@  discard block
 block discarded – undo
722 722
 
723 723
 		$params['context']['default'] = 'view';
724 724
 
725
-		$params['after']   = array(
726
-			'description'       => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
725
+		$params['after'] = array(
726
+			'description'       => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
727 727
 			'type'              => 'string',
728 728
 			'format'            => 'date-time',
729 729
 			'validate_callback' => 'rest_validate_request_arg',
730 730
 		);
731
-		$params['before']  = array(
732
-			'description'       => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
731
+		$params['before'] = array(
732
+			'description'       => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
733 733
 			'type'              => 'string',
734 734
 			'format'            => 'date-time',
735 735
 			'validate_callback' => 'rest_validate_request_arg',
736 736
 		);
737 737
 		$params['exclude'] = array(
738
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
738
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
739 739
 			'type'              => 'array',
740 740
 			'items'             => array(
741 741
 				'type' => 'integer',
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 			'sanitize_callback' => 'wp_parse_id_list',
745 745
 		);
746 746
 		$params['include'] = array(
747
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
747
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
748 748
 			'type'              => 'array',
749 749
 			'items'             => array(
750 750
 				'type' > 'integer',
@@ -752,21 +752,21 @@  discard block
 block discarded – undo
752 752
 			'default'           => array(),
753 753
 			'sanitize_callback' => 'wp_parse_id_list',
754 754
 		);
755
-		$params['offset']  = array(
756
-			'description'       => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
755
+		$params['offset'] = array(
756
+			'description'       => __('Offset the result set by a specific number of items.', 'woocommerce'),
757 757
 			'type'              => 'integer',
758 758
 			'sanitize_callback' => 'absint',
759 759
 			'validate_callback' => 'rest_validate_request_arg',
760 760
 		);
761
-		$params['order']   = array(
762
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
761
+		$params['order'] = array(
762
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
763 763
 			'type'              => 'string',
764 764
 			'default'           => 'desc',
765
-			'enum'              => array( 'asc', 'desc' ),
765
+			'enum'              => array('asc', 'desc'),
766 766
 			'validate_callback' => 'rest_validate_request_arg',
767 767
 		);
768 768
 		$params['orderby'] = array(
769
-			'description'       => __( 'Sort collection by object attribute.', 'woocommerce' ),
769
+			'description'       => __('Sort collection by object attribute.', 'woocommerce'),
770 770
 			'type'              => 'string',
771 771
 			'default'           => 'date',
772 772
 			'enum'              => array(
@@ -776,11 +776,11 @@  discard block
 block discarded – undo
776 776
 			),
777 777
 			'validate_callback' => 'rest_validate_request_arg',
778 778
 		);
779
-		$params['status']  = array(
779
+		$params['status'] = array(
780 780
 			'default'           => 'all',
781
-			'description'       => __( 'Limit result set to webhooks assigned a specific status.', 'woocommerce' ),
781
+			'description'       => __('Limit result set to webhooks assigned a specific status.', 'woocommerce'),
782 782
 			'type'              => 'string',
783
-			'enum'              => array( 'all', 'active', 'paused', 'disabled' ),
783
+			'enum'              => array('all', 'active', 'paused', 'disabled'),
784 784
 			'sanitize_callback' => 'sanitize_key',
785 785
 			'validate_callback' => 'rest_validate_request_arg',
786 786
 		);
Please login to merge, or discard this patch.
src/Controllers/Version4/ShippingMethods.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * Shipping methods controller class.
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 			array(
34 34
 				array(
35 35
 					'methods'             => \WP_REST_Server::READABLE,
36
-					'callback'            => array( $this, 'get_items' ),
37
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
36
+					'callback'            => array($this, 'get_items'),
37
+					'permission_callback' => array($this, 'get_items_permissions_check'),
38 38
 					'args'                => $this->get_collection_params(),
39 39
 				),
40
-				'schema' => array( $this, 'get_public_item_schema' ),
40
+				'schema' => array($this, 'get_public_item_schema'),
41 41
 			),
42 42
 			true
43 43
 		);
@@ -47,19 +47,19 @@  discard block
 block discarded – undo
47 47
 			array(
48 48
 				'args'   => array(
49 49
 					'id' => array(
50
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
50
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
51 51
 						'type'        => 'string',
52 52
 					),
53 53
 				),
54 54
 				array(
55 55
 					'methods'             => \WP_REST_Server::READABLE,
56
-					'callback'            => array( $this, 'get_item' ),
57
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
56
+					'callback'            => array($this, 'get_item'),
57
+					'permission_callback' => array($this, 'get_item_permissions_check'),
58 58
 					'args'                => array(
59
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
59
+						'context' => $this->get_context_param(array('default' => 'view')),
60 60
 					),
61 61
 				),
62
-				'schema' => array( $this, 'get_public_item_schema' ),
62
+				'schema' => array($this, 'get_public_item_schema'),
63 63
 			),
64 64
 			true
65 65
 		);
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
 	 * @param  \WP_REST_Request $request Full details about the request.
72 72
 	 * @return \WP_Error|boolean
73 73
 	 */
74
-	public function get_items_permissions_check( $request ) {
75
-		if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) {
76
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
74
+	public function get_items_permissions_check($request) {
75
+		if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) {
76
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
77 77
 		}
78 78
 		return true;
79 79
 	}
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 	 * @param  \WP_REST_Request $request Full details about the request.
85 85
 	 * @return \WP_Error|boolean
86 86
 	 */
87
-	public function get_item_permissions_check( $request ) {
88
-		if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) {
89
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
87
+	public function get_item_permissions_check($request) {
88
+		if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) {
89
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
90 90
 		}
91 91
 		return true;
92 92
 	}
@@ -97,15 +97,15 @@  discard block
 block discarded – undo
97 97
 	 * @param \WP_REST_Request $request Full details about the request.
98 98
 	 * @return \WP_Error\WP_REST_Response
99 99
 	 */
100
-	public function get_items( $request ) {
100
+	public function get_items($request) {
101 101
 		$wc_shipping = \WC_Shipping::instance();
102 102
 		$response    = array();
103
-		foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) {
104
-			$method     = $this->prepare_item_for_response( $shipping_method, $request );
105
-			$method     = $this->prepare_response_for_collection( $method );
103
+		foreach ($wc_shipping->get_shipping_methods() as $id => $shipping_method) {
104
+			$method     = $this->prepare_item_for_response($shipping_method, $request);
105
+			$method     = $this->prepare_response_for_collection($method);
106 106
 			$response[] = $method;
107 107
 		}
108
-		return rest_ensure_response( $response );
108
+		return rest_ensure_response($response);
109 109
 	}
110 110
 
111 111
 	/**
@@ -114,17 +114,17 @@  discard block
 block discarded – undo
114 114
 	 * @param \WP_REST_Request $request Request data.
115 115
 	 * @return \WP_REST_Response|\WP_Error
116 116
 	 */
117
-	public function get_item( $request ) {
117
+	public function get_item($request) {
118 118
 		$wc_shipping = \WC_Shipping::instance();
119 119
 		$methods     = $wc_shipping->get_shipping_methods();
120
-		if ( empty( $methods[ $request['id'] ] ) ) {
121
-			return new \WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
120
+		if (empty($methods[$request['id']])) {
121
+			return new \WP_Error('woocommerce_rest_shipping_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
122 122
 		}
123 123
 
124
-		$method   = $methods[ $request['id'] ];
125
-		$response = $this->prepare_item_for_response( $method, $request );
124
+		$method   = $methods[$request['id']];
125
+		$response = $this->prepare_item_for_response($method, $request);
126 126
 
127
-		return rest_ensure_response( $response );
127
+		return rest_ensure_response($response);
128 128
 	}
129 129
 
130 130
 	/**
@@ -134,21 +134,21 @@  discard block
 block discarded – undo
134 134
 	 * @param  \WP_REST_Request    $request  Request object.
135 135
 	 * @return \WP_REST_Response   $response Response data.
136 136
 	 */
137
-	public function prepare_item_for_response( $method, $request ) {
137
+	public function prepare_item_for_response($method, $request) {
138 138
 		$data = array(
139 139
 			'id'          => $method->id,
140 140
 			'title'       => $method->method_title,
141 141
 			'description' => $method->method_description,
142 142
 		);
143 143
 
144
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
145
-		$data    = $this->add_additional_fields_to_object( $data, $request );
146
-		$data    = $this->filter_response_by_context( $data, $context );
144
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
145
+		$data    = $this->add_additional_fields_to_object($data, $request);
146
+		$data    = $this->filter_response_by_context($data, $context);
147 147
 
148 148
 		// Wrap the data in a response object.
149
-		$response = rest_ensure_response( $data );
149
+		$response = rest_ensure_response($data);
150 150
 
151
-		$response->add_links( $this->prepare_links( $method, $request ) );
151
+		$response->add_links($this->prepare_links($method, $request));
152 152
 
153 153
 		/**
154 154
 		 * Filter shipping methods object returned from the REST API.
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		 * @param WC_Shipping_Method $method   Shipping method object used to create response.
158 158
 		 * @param \WP_REST_Request    $request  Request object.
159 159
 		 */
160
-		return apply_filters( 'woocommerce_rest_prepare_shipping_method', $response, $method, $request );
160
+		return apply_filters('woocommerce_rest_prepare_shipping_method', $response, $method, $request);
161 161
 	}
162 162
 
163 163
 	/**
@@ -167,13 +167,13 @@  discard block
 block discarded – undo
167 167
 	 * @param \WP_REST_Request    $request Request object.
168 168
 	 * @return array
169 169
 	 */
170
-	protected function prepare_links( $method, $request ) {
170
+	protected function prepare_links($method, $request) {
171 171
 		$links = array(
172 172
 			'self'       => array(
173
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $method->id ) ),
173
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $method->id)),
174 174
 			),
175 175
 			'collection' => array(
176
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
176
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
177 177
 			),
178 178
 		);
179 179
 
@@ -192,27 +192,27 @@  discard block
 block discarded – undo
192 192
 			'type'       => 'object',
193 193
 			'properties' => array(
194 194
 				'id'          => array(
195
-					'description' => __( 'Method ID.', 'woocommerce' ),
195
+					'description' => __('Method ID.', 'woocommerce'),
196 196
 					'type'        => 'string',
197
-					'context'     => array( 'view' ),
197
+					'context'     => array('view'),
198 198
 					'readonly'    => true,
199 199
 				),
200 200
 				'title'       => array(
201
-					'description' => __( 'Shipping method title.', 'woocommerce' ),
201
+					'description' => __('Shipping method title.', 'woocommerce'),
202 202
 					'type'        => 'string',
203
-					'context'     => array( 'view' ),
203
+					'context'     => array('view'),
204 204
 					'readonly'    => true,
205 205
 				),
206 206
 				'description' => array(
207
-					'description' => __( 'Shipping method description.', 'woocommerce' ),
207
+					'description' => __('Shipping method description.', 'woocommerce'),
208 208
 					'type'        => 'string',
209
-					'context'     => array( 'view' ),
209
+					'context'     => array('view'),
210 210
 					'readonly'    => true,
211 211
 				),
212 212
 			),
213 213
 		);
214 214
 
215
-		return $this->add_additional_fields_schema( $schema );
215
+		return $this->add_additional_fields_schema($schema);
216 216
 	}
217 217
 
218 218
 	/**
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 */
223 223
 	public function get_collection_params() {
224 224
 		return array(
225
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
225
+			'context' => $this->get_context_param(array('default' => 'view')),
226 226
 		);
227 227
 	}
228 228
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/AbstractController.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 namespace WooCommerce\RestApi\Controllers\Version4;
17 17
 
18
-defined( 'ABSPATH' ) || exit;
18
+defined('ABSPATH') || exit;
19 19
 
20 20
 use \WP_REST_Controller;
21 21
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @return array
53 53
 	 */
54
-	protected function add_additional_fields_schema( $schema ) {
55
-		if ( empty( $schema['title'] ) ) {
54
+	protected function add_additional_fields_schema($schema) {
55
+		if (empty($schema['title'])) {
56 56
 			return $schema;
57 57
 		}
58 58
 
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
 		 */
62 62
 		$object_type = $schema['title'];
63 63
 
64
-		$additional_fields = $this->get_additional_fields( $object_type );
64
+		$additional_fields = $this->get_additional_fields($object_type);
65 65
 
66
-		foreach ( $additional_fields as $field_name => $field_options ) {
67
-			if ( ! $field_options['schema'] ) {
66
+		foreach ($additional_fields as $field_name => $field_options) {
67
+			if ( ! $field_options['schema']) {
68 68
 				continue;
69 69
 			}
70 70
 
71
-			$schema['properties'][ $field_name ] = $field_options['schema'];
71
+			$schema['properties'][$field_name] = $field_options['schema'];
72 72
 		}
73 73
 
74
-		$schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] );
74
+		$schema['properties'] = apply_filters('woocommerce_rest_' . $object_type . '_schema', $schema['properties']);
75 75
 
76 76
 		return $schema;
77 77
 	}
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 * @return string
83 83
 	 */
84 84
 	protected function get_normalized_rest_base() {
85
-		return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
85
+		return preg_replace('/\(.*\)\//i', '', $this->rest_base);
86 86
 	}
87 87
 
88 88
 	/**
@@ -91,25 +91,25 @@  discard block
 block discarded – undo
91 91
 	 * @param array $items Request items.
92 92
 	 * @return bool|\WP_Error
93 93
 	 */
94
-	protected function check_batch_limit( $items ) {
95
-		$limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
94
+	protected function check_batch_limit($items) {
95
+		$limit = apply_filters('woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base());
96 96
 		$total = 0;
97 97
 
98
-		if ( ! empty( $items['create'] ) ) {
99
-			$total += count( $items['create'] );
98
+		if ( ! empty($items['create'])) {
99
+			$total += count($items['create']);
100 100
 		}
101 101
 
102
-		if ( ! empty( $items['update'] ) ) {
103
-			$total += count( $items['update'] );
102
+		if ( ! empty($items['update'])) {
103
+			$total += count($items['update']);
104 104
 		}
105 105
 
106
-		if ( ! empty( $items['delete'] ) ) {
107
-			$total += count( $items['delete'] );
106
+		if ( ! empty($items['delete'])) {
107
+			$total += count($items['delete']);
108 108
 		}
109 109
 
110
-		if ( $total > $limit ) {
110
+		if ($total > $limit) {
111 111
 			/* translators: %s: items limit */
112
-			return new \WP_Error( 'woocommerce_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), array( 'status' => 413 ) );
112
+			return new \WP_Error('woocommerce_rest_request_entity_too_large', sprintf(__('Unable to accept more than %s items for this request.', 'woocommerce'), $limit), array('status' => 413));
113 113
 		}
114 114
 
115 115
 		return true;
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @param \WP_REST_Request $request Full details about the request.
122 122
 	 * @return array Of \WP_Error or \WP_REST_Response.
123 123
 	 */
124
-	public function batch_items( $request ) {
124
+	public function batch_items($request) {
125 125
 		/**
126 126
 		 * REST Server
127 127
 		 *
@@ -130,34 +130,34 @@  discard block
 block discarded – undo
130 130
 		global $wp_rest_server;
131 131
 
132 132
 		// Get the request params.
133
-		$items    = array_filter( $request->get_params() );
133
+		$items    = array_filter($request->get_params());
134 134
 		$response = array();
135 135
 
136 136
 		// Check batch limit.
137
-		$limit = $this->check_batch_limit( $items );
138
-		if ( is_wp_error( $limit ) ) {
137
+		$limit = $this->check_batch_limit($items);
138
+		if (is_wp_error($limit)) {
139 139
 			return $limit;
140 140
 		}
141 141
 
142
-		if ( ! empty( $items['create'] ) ) {
143
-			foreach ( $items['create'] as $item ) {
144
-				$_item = new \WP_REST_Request( 'POST' );
142
+		if ( ! empty($items['create'])) {
143
+			foreach ($items['create'] as $item) {
144
+				$_item = new \WP_REST_Request('POST');
145 145
 
146 146
 				// Default parameters.
147 147
 				$defaults = array();
148 148
 				$schema   = $this->get_public_item_schema();
149
-				foreach ( $schema['properties'] as $arg => $options ) {
150
-					if ( isset( $options['default'] ) ) {
151
-						$defaults[ $arg ] = $options['default'];
149
+				foreach ($schema['properties'] as $arg => $options) {
150
+					if (isset($options['default'])) {
151
+						$defaults[$arg] = $options['default'];
152 152
 					}
153 153
 				}
154
-				$_item->set_default_params( $defaults );
154
+				$_item->set_default_params($defaults);
155 155
 
156 156
 				// Set request parameters.
157
-				$_item->set_body_params( $item );
158
-				$_response = $this->create_item( $_item );
157
+				$_item->set_body_params($item);
158
+				$_response = $this->create_item($_item);
159 159
 
160
-				if ( is_wp_error( $_response ) ) {
160
+				if (is_wp_error($_response)) {
161 161
 					$response['create'][] = array(
162 162
 						'id'    => 0,
163 163
 						'error' => array(
@@ -167,18 +167,18 @@  discard block
 block discarded – undo
167 167
 						),
168 168
 					);
169 169
 				} else {
170
-					$response['create'][] = $wp_rest_server->response_to_data( $_response, '' );
170
+					$response['create'][] = $wp_rest_server->response_to_data($_response, '');
171 171
 				}
172 172
 			}
173 173
 		}
174 174
 
175
-		if ( ! empty( $items['update'] ) ) {
176
-			foreach ( $items['update'] as $item ) {
177
-				$_item = new \WP_REST_Request( 'PUT' );
178
-				$_item->set_body_params( $item );
179
-				$_response = $this->update_item( $_item );
175
+		if ( ! empty($items['update'])) {
176
+			foreach ($items['update'] as $item) {
177
+				$_item = new \WP_REST_Request('PUT');
178
+				$_item->set_body_params($item);
179
+				$_response = $this->update_item($_item);
180 180
 
181
-				if ( is_wp_error( $_response ) ) {
181
+				if (is_wp_error($_response)) {
182 182
 					$response['update'][] = array(
183 183
 						'id'    => $item['id'],
184 184
 						'error' => array(
@@ -188,29 +188,29 @@  discard block
 block discarded – undo
188 188
 						),
189 189
 					);
190 190
 				} else {
191
-					$response['update'][] = $wp_rest_server->response_to_data( $_response, '' );
191
+					$response['update'][] = $wp_rest_server->response_to_data($_response, '');
192 192
 				}
193 193
 			}
194 194
 		}
195 195
 
196
-		if ( ! empty( $items['delete'] ) ) {
197
-			foreach ( $items['delete'] as $id ) {
196
+		if ( ! empty($items['delete'])) {
197
+			foreach ($items['delete'] as $id) {
198 198
 				$id = (int) $id;
199 199
 
200
-				if ( 0 === $id ) {
200
+				if (0 === $id) {
201 201
 					continue;
202 202
 				}
203 203
 
204
-				$_item = new \WP_REST_Request( 'DELETE' );
204
+				$_item = new \WP_REST_Request('DELETE');
205 205
 				$_item->set_query_params(
206 206
 					array(
207 207
 						'id'    => $id,
208 208
 						'force' => true,
209 209
 					)
210 210
 				);
211
-				$_response = $this->delete_item( $_item );
211
+				$_response = $this->delete_item($_item);
212 212
 
213
-				if ( is_wp_error( $_response ) ) {
213
+				if (is_wp_error($_response)) {
214 214
 					$response['delete'][] = array(
215 215
 						'id'    => $id,
216 216
 						'error' => array(
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 						),
221 221
 					);
222 222
 				} else {
223
-					$response['delete'][] = $wp_rest_server->response_to_data( $_response, '' );
223
+					$response['delete'][] = $wp_rest_server->response_to_data($_response, '');
224 224
 				}
225 225
 			}
226 226
 		}
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
 	 * @param array  $setting Setting.
237 237
 	 * @return string
238 238
 	 */
239
-	public function validate_setting_text_field( $value, $setting ) {
240
-		$value = is_null( $value ) ? '' : $value;
241
-		return wp_kses_post( trim( stripslashes( $value ) ) );
239
+	public function validate_setting_text_field($value, $setting) {
240
+		$value = is_null($value) ? '' : $value;
241
+		return wp_kses_post(trim(stripslashes($value)));
242 242
 	}
243 243
 
244 244
 	/**
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
 	 * @param array  $setting Setting.
250 250
 	 * @return string|\WP_Error
251 251
 	 */
252
-	public function validate_setting_select_field( $value, $setting ) {
253
-		if ( array_key_exists( $value, $setting['options'] ) ) {
252
+	public function validate_setting_select_field($value, $setting) {
253
+		if (array_key_exists($value, $setting['options'])) {
254 254
 			return $value;
255 255
 		} else {
256
-			return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
256
+			return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
257 257
 		}
258 258
 	}
259 259
 
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 	 * @param array $setting Setting.
266 266
 	 * @return array|\WP_Error
267 267
 	 */
268
-	public function validate_setting_multiselect_field( $values, $setting ) {
269
-		if ( empty( $values ) ) {
268
+	public function validate_setting_multiselect_field($values, $setting) {
269
+		if (empty($values)) {
270 270
 			return array();
271 271
 		}
272 272
 
273
-		if ( ! is_array( $values ) ) {
274
-			return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
273
+		if ( ! is_array($values)) {
274
+			return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
275 275
 		}
276 276
 
277 277
 		$final_values = array();
278
-		foreach ( $values as $value ) {
279
-			if ( array_key_exists( $value, $setting['options'] ) ) {
278
+		foreach ($values as $value) {
279
+			if (array_key_exists($value, $setting['options'])) {
280 280
 				$final_values[] = $value;
281 281
 			}
282 282
 		}
@@ -292,19 +292,19 @@  discard block
 block discarded – undo
292 292
 	 * @param array $setting Setting.
293 293
 	 * @return string|\WP_Error
294 294
 	 */
295
-	public function validate_setting_image_width_field( $values, $setting ) {
296
-		if ( ! is_array( $values ) ) {
297
-			return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
295
+	public function validate_setting_image_width_field($values, $setting) {
296
+		if ( ! is_array($values)) {
297
+			return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
298 298
 		}
299 299
 
300 300
 		$current = $setting['value'];
301
-		if ( isset( $values['width'] ) ) {
302
-			$current['width'] = intval( $values['width'] );
301
+		if (isset($values['width'])) {
302
+			$current['width'] = intval($values['width']);
303 303
 		}
304
-		if ( isset( $values['height'] ) ) {
305
-			$current['height'] = intval( $values['height'] );
304
+		if (isset($values['height'])) {
305
+			$current['height'] = intval($values['height']);
306 306
 		}
307
-		if ( isset( $values['crop'] ) ) {
307
+		if (isset($values['crop'])) {
308 308
 			$current['crop'] = (bool) $values['crop'];
309 309
 		}
310 310
 		return $current;
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
 	 * @param array  $setting Setting.
319 319
 	 * @return string|\WP_Error
320 320
 	 */
321
-	public function validate_setting_radio_field( $value, $setting ) {
322
-		return $this->validate_setting_select_field( $value, $setting );
321
+	public function validate_setting_radio_field($value, $setting) {
322
+		return $this->validate_setting_select_field($value, $setting);
323 323
 	}
324 324
 
325 325
 	/**
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
 	 * @param array  $setting Setting.
331 331
 	 * @return string|\WP_Error
332 332
 	 */
333
-	public function validate_setting_checkbox_field( $value, $setting ) {
334
-		if ( in_array( $value, array( 'yes', 'no' ) ) ) {
333
+	public function validate_setting_checkbox_field($value, $setting) {
334
+		if (in_array($value, array('yes', 'no'))) {
335 335
 			return $value;
336
-		} elseif ( empty( $value ) ) {
337
-			$value = isset( $setting['default'] ) ? $setting['default'] : 'no';
336
+		} elseif (empty($value)) {
337
+			$value = isset($setting['default']) ? $setting['default'] : 'no';
338 338
 			return $value;
339 339
 		} else {
340
-			return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
340
+			return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
341 341
 		}
342 342
 	}
343 343
 
@@ -349,10 +349,10 @@  discard block
 block discarded – undo
349 349
 	 * @param array  $setting Setting.
350 350
 	 * @return string
351 351
 	 */
352
-	public function validate_setting_textarea_field( $value, $setting ) {
353
-		$value = is_null( $value ) ? '' : $value;
352
+	public function validate_setting_textarea_field($value, $setting) {
353
+		$value = is_null($value) ? '' : $value;
354 354
 		return wp_kses(
355
-			trim( stripslashes( $value ) ),
355
+			trim(stripslashes($value)),
356 356
 			array_merge(
357 357
 				array(
358 358
 					'iframe' => array(
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 						'class' => true,
363 363
 					),
364 364
 				),
365
-				wp_kses_allowed_html( 'post' )
365
+				wp_kses_allowed_html('post')
366 366
 			)
367 367
 		);
368 368
 	}
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * @param array $meta_query Meta query.
376 376
 	 * @return array
377 377
 	 */
378
-	protected function add_meta_query( $args, $meta_query ) {
379
-		if ( empty( $args['meta_query'] ) ) {
378
+	protected function add_meta_query($args, $meta_query) {
379
+		if (empty($args['meta_query'])) {
380 380
 			$args['meta_query'] = array();
381 381
 		}
382 382
 
@@ -397,25 +397,25 @@  discard block
 block discarded – undo
397 397
 			'type'       => 'object',
398 398
 			'properties' => array(
399 399
 				'create' => array(
400
-					'description' => __( 'List of created resources.', 'woocommerce' ),
400
+					'description' => __('List of created resources.', 'woocommerce'),
401 401
 					'type'        => 'array',
402
-					'context'     => array( 'view', 'edit' ),
402
+					'context'     => array('view', 'edit'),
403 403
 					'items'       => array(
404 404
 						'type'    => 'object',
405 405
 					),
406 406
 				),
407 407
 				'update' => array(
408
-					'description' => __( 'List of updated resources.', 'woocommerce' ),
408
+					'description' => __('List of updated resources.', 'woocommerce'),
409 409
 					'type'        => 'array',
410
-					'context'     => array( 'view', 'edit' ),
410
+					'context'     => array('view', 'edit'),
411 411
 					'items'       => array(
412 412
 						'type'    => 'object',
413 413
 					),
414 414
 				),
415 415
 				'delete' => array(
416
-					'description' => __( 'List of delete resources.', 'woocommerce' ),
416
+					'description' => __('List of delete resources.', 'woocommerce'),
417 417
 					'type'        => 'array',
418
-					'context'     => array( 'view', 'edit' ),
418
+					'context'     => array('view', 'edit'),
419 419
 					'items'       => array(
420 420
 						'type'    => 'integer',
421 421
 					),
@@ -435,32 +435,32 @@  discard block
 block discarded – undo
435 435
 	 * @param \WP_REST_Request $request Full details about the request.
436 436
 	 * @return array Fields to be included in the response.
437 437
 	 */
438
-	public function get_fields_for_response( $request ) {
438
+	public function get_fields_for_response($request) {
439 439
 		$schema = $this->get_item_schema();
440
-		$fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array();
440
+		$fields = isset($schema['properties']) ? array_keys($schema['properties']) : array();
441 441
 
442 442
 		$additional_fields = $this->get_additional_fields();
443
-		foreach ( $additional_fields as $field_name => $field_options ) {
443
+		foreach ($additional_fields as $field_name => $field_options) {
444 444
 			// For back-compat, include any field with an empty schema
445 445
 			// because it won't be present in $this->get_item_schema().
446
-			if ( is_null( $field_options['schema'] ) ) {
446
+			if (is_null($field_options['schema'])) {
447 447
 				$fields[] = $field_name;
448 448
 			}
449 449
 		}
450 450
 
451
-		if ( ! isset( $request['_fields'] ) ) {
451
+		if ( ! isset($request['_fields'])) {
452 452
 			return $fields;
453 453
 		}
454
-		$requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
455
-		if ( 0 === count( $requested_fields ) ) {
454
+		$requested_fields = is_array($request['_fields']) ? $request['_fields'] : preg_split('/[\s,]+/', $request['_fields']);
455
+		if (0 === count($requested_fields)) {
456 456
 			return $fields;
457 457
 		}
458 458
 		// Trim off outside whitespace from the comma delimited list.
459
-		$requested_fields = array_map( 'trim', $requested_fields );
459
+		$requested_fields = array_map('trim', $requested_fields);
460 460
 		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
461
-		if ( in_array( 'id', $fields, true ) ) {
461
+		if (in_array('id', $fields, true)) {
462 462
 			$requested_fields[] = 'id';
463 463
 		}
464
-		return array_intersect( $fields, $requested_fields );
464
+		return array_intersect($fields, $requested_fields);
465 465
 	}
466 466
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/Reports.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API reports controller class.
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 			array(
34 34
 				array(
35 35
 					'methods'             => \WP_REST_Server::READABLE,
36
-					'callback'            => array( $this, 'get_items' ),
37
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
36
+					'callback'            => array($this, 'get_items'),
37
+					'permission_callback' => array($this, 'get_items_permissions_check'),
38 38
 					'args'                => $this->get_collection_params(),
39 39
 				),
40
-				'schema' => array( $this, 'get_public_item_schema' ),
40
+				'schema' => array($this, 'get_public_item_schema'),
41 41
 			),
42 42
 			true
43 43
 		);
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	 * @param  \WP_REST_Request $request Full details about the request.
50 50
 	 * @return \WP_Error|boolean
51 51
 	 */
52
-	public function get_items_permissions_check( $request ) {
53
-		if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) {
54
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
52
+	public function get_items_permissions_check($request) {
53
+		if ( ! wc_rest_check_manager_permissions('reports', 'read')) {
54
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
55 55
 		}
56 56
 
57 57
 		return true;
@@ -64,66 +64,66 @@  discard block
 block discarded – undo
64 64
 	 * @param \WP_REST_Request $request Request data.
65 65
 	 * @return array|\WP_Error
66 66
 	 */
67
-	public function get_items( $request ) {
67
+	public function get_items($request) {
68 68
 		$data    = [];
69 69
 		$reports = [];
70
-		if ( class_exists( 'WC_Admin_Reports_Sync' ) ) {
70
+		if (class_exists('WC_Admin_Reports_Sync')) {
71 71
 			$reports = array(
72 72
 				array(
73 73
 					'slug'        => 'performance-indicators',
74
-					'description' => __( 'Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce' ),
74
+					'description' => __('Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce'),
75 75
 				),
76 76
 				array(
77 77
 					'slug'        => 'revenue/stats',
78
-					'description' => __( 'Stats about revenue.', 'woocommerce' ),
78
+					'description' => __('Stats about revenue.', 'woocommerce'),
79 79
 				),
80 80
 				array(
81 81
 					'slug'        => 'orders/stats',
82
-					'description' => __( 'Stats about orders.', 'woocommerce' ),
82
+					'description' => __('Stats about orders.', 'woocommerce'),
83 83
 				),
84 84
 				array(
85 85
 					'slug'        => 'products',
86
-					'description' => __( 'Products detailed reports.', 'woocommerce' ),
86
+					'description' => __('Products detailed reports.', 'woocommerce'),
87 87
 				),
88 88
 				array(
89 89
 					'slug'        => 'products/stats',
90
-					'description' => __( 'Stats about products.', 'woocommerce' ),
90
+					'description' => __('Stats about products.', 'woocommerce'),
91 91
 				),
92 92
 				array(
93 93
 					'slug'        => 'categories',
94
-					'description' => __( 'Product categories detailed reports.', 'woocommerce' ),
94
+					'description' => __('Product categories detailed reports.', 'woocommerce'),
95 95
 				),
96 96
 				array(
97 97
 					'slug'        => 'categories/stats',
98
-					'description' => __( 'Stats about product categories.', 'woocommerce' ),
98
+					'description' => __('Stats about product categories.', 'woocommerce'),
99 99
 				),
100 100
 				array(
101 101
 					'slug'        => 'coupons',
102
-					'description' => __( 'Coupons detailed reports.', 'woocommerce' ),
102
+					'description' => __('Coupons detailed reports.', 'woocommerce'),
103 103
 				),
104 104
 				array(
105 105
 					'slug'        => 'coupons/stats',
106
-					'description' => __( 'Stats about coupons.', 'woocommerce' ),
106
+					'description' => __('Stats about coupons.', 'woocommerce'),
107 107
 				),
108 108
 				array(
109 109
 					'slug'        => 'taxes',
110
-					'description' => __( 'Taxes detailed reports.', 'woocommerce' ),
110
+					'description' => __('Taxes detailed reports.', 'woocommerce'),
111 111
 				),
112 112
 				array(
113 113
 					'slug'        => 'taxes/stats',
114
-					'description' => __( 'Stats about taxes.', 'woocommerce' ),
114
+					'description' => __('Stats about taxes.', 'woocommerce'),
115 115
 				),
116 116
 				array(
117 117
 					'slug'        => 'downloads',
118
-					'description' => __( 'Product downloads detailed reports.', 'woocommerce' ),
118
+					'description' => __('Product downloads detailed reports.', 'woocommerce'),
119 119
 				),
120 120
 				array(
121 121
 					'slug'        => 'downloads/stats',
122
-					'description' => __( 'Stats about product downloads.', 'woocommerce' ),
122
+					'description' => __('Stats about product downloads.', 'woocommerce'),
123 123
 				),
124 124
 				array(
125 125
 					'slug'        => 'customers',
126
-					'description' => __( 'Customers detailed reports.', 'woocommerce' ),
126
+					'description' => __('Customers detailed reports.', 'woocommerce'),
127 127
 				),
128 128
 			);
129 129
 		}
@@ -135,22 +135,22 @@  discard block
 block discarded – undo
135 135
 		 *
136 136
 		 * @param array $endpoints The list of allowed reports..
137 137
 		 */
138
-		$reports = apply_filters( 'woocommerce_admin_reports', $reports );
138
+		$reports = apply_filters('woocommerce_admin_reports', $reports);
139 139
 
140
-		foreach ( $reports as $report ) {
141
-			if ( empty( $report['slug'] ) ) {
140
+		foreach ($reports as $report) {
141
+			if (empty($report['slug'])) {
142 142
 				continue;
143 143
 			}
144 144
 
145
-			if ( empty( $report['path'] ) ) {
145
+			if (empty($report['path'])) {
146 146
 				$report['path'] = '/' . $this->namespace . '/reports/' . $report['slug'];
147 147
 			}
148 148
 
149 149
 			// Allows a different admin page to be loaded here,
150 150
 			// or allows an empty url if no report exists for a set of performance indicators.
151
-			if ( ! isset( $report['url'] ) ) {
152
-				if ( '/stats' === substr( $report['slug'], -6 ) ) {
153
-					$url_slug = substr( $report['slug'], 0, -6 );
151
+			if ( ! isset($report['url'])) {
152
+				if ('/stats' === substr($report['slug'], -6)) {
153
+					$url_slug = substr($report['slug'], 0, -6);
154 154
 				} else {
155 155
 					$url_slug = $report['slug'];
156 156
 				}
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
 				$report['url'] = '/analytics/' . $url_slug;
159 159
 			}
160 160
 
161
-			$item   = $this->prepare_item_for_response( (object) $report, $request );
162
-			$data[] = $this->prepare_response_for_collection( $item );
161
+			$item   = $this->prepare_item_for_response((object) $report, $request);
162
+			$data[] = $this->prepare_response_for_collection($item);
163 163
 		}
164 164
 
165
-		return rest_ensure_response( $data );
165
+		return rest_ensure_response($data);
166 166
 	}
167 167
 
168 168
 	/**
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 	 * @param  int $order_id Order ID.
173 173
 	 * @return string
174 174
 	 */
175
-	public function get_order_number( $order_id ) {
176
-		$order = wc_get_order( $order_id );
175
+	public function get_order_number($order_id) {
176
+		$order = wc_get_order($order_id);
177 177
 
178
-		if ( 'shop_order_refund' === $order->get_type() ) {
179
-			$order = wc_get_order( $order->get_parent_id() );
178
+		if ('shop_order_refund' === $order->get_type()) {
179
+			$order = wc_get_order($order->get_parent_id());
180 180
 		}
181 181
 
182
-		if ( ! has_filter( 'woocommerce_order_number' ) ) {
182
+		if ( ! has_filter('woocommerce_order_number')) {
183 183
 			return $order->get_id();
184 184
 		}
185 185
 
@@ -193,29 +193,29 @@  discard block
 block discarded – undo
193 193
 	 * @param \WP_REST_Request $request Request object.
194 194
 	 * @return \WP_REST_Response
195 195
 	 */
196
-	public function prepare_item_for_response( $report, $request ) {
196
+	public function prepare_item_for_response($report, $request) {
197 197
 		$data = array(
198 198
 			'slug'        => $report->slug,
199 199
 			'description' => $report->description,
200 200
 			'path'        => $report->path,
201 201
 		);
202 202
 
203
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
204
-		$data    = $this->add_additional_fields_to_object( $data, $request );
205
-		$data    = $this->filter_response_by_context( $data, $context );
203
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
204
+		$data    = $this->add_additional_fields_to_object($data, $request);
205
+		$data    = $this->filter_response_by_context($data, $context);
206 206
 
207 207
 		// Wrap the data in a response object.
208
-		$response = rest_ensure_response( $data );
208
+		$response = rest_ensure_response($data);
209 209
 		$response->add_links(
210 210
 			array(
211 211
 				'self'       => array(
212
-					'href' => rest_url( $report->path ),
212
+					'href' => rest_url($report->path),
213 213
 				),
214 214
 				'report'     => array(
215 215
 					'href' => $report->url,
216 216
 				),
217 217
 				'collection' => array(
218
-					'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
218
+					'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)),
219 219
 				),
220 220
 			)
221 221
 		);
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		 * @param object           $report   The original report object.
230 230
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
231 231
 		 */
232
-		return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request );
232
+		return apply_filters('woocommerce_rest_prepare_report', $response, $report, $request);
233 233
 	}
234 234
 
235 235
 	/**
@@ -244,27 +244,27 @@  discard block
 block discarded – undo
244 244
 			'type'       => 'object',
245 245
 			'properties' => array(
246 246
 				'slug'        => array(
247
-					'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
247
+					'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'),
248 248
 					'type'        => 'string',
249
-					'context'     => array( 'view' ),
249
+					'context'     => array('view'),
250 250
 					'readonly'    => true,
251 251
 				),
252 252
 				'description' => array(
253
-					'description' => __( 'A human-readable description of the resource.', 'woocommerce' ),
253
+					'description' => __('A human-readable description of the resource.', 'woocommerce'),
254 254
 					'type'        => 'string',
255
-					'context'     => array( 'view' ),
255
+					'context'     => array('view'),
256 256
 					'readonly'    => true,
257 257
 				),
258 258
 				'path'        => array(
259
-					'description' => __( 'API path.', 'woocommerce' ),
259
+					'description' => __('API path.', 'woocommerce'),
260 260
 					'type'        => 'string',
261
-					'context'     => array( 'view' ),
261
+					'context'     => array('view'),
262 262
 					'readonly'    => true,
263 263
 				),
264 264
 			),
265 265
 		);
266 266
 
267
-		return $this->add_additional_fields_schema( $schema );
267
+		return $this->add_additional_fields_schema($schema);
268 268
 	}
269 269
 
270 270
 	/**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 */
275 275
 	public function get_collection_params() {
276 276
 		return array(
277
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
277
+			'context' => $this->get_context_param(array('default' => 'view')),
278 278
 		);
279 279
 	}
280 280
 
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 	public function get_order_statuses() {
287 287
 		$order_statuses = array();
288 288
 
289
-		foreach ( array_keys( wc_get_order_statuses() ) as $status ) {
290
-			$order_statuses[] = str_replace( 'wc-', '', $status );
289
+		foreach (array_keys(wc_get_order_statuses()) as $status) {
290
+			$order_statuses[] = str_replace('wc-', '', $status);
291 291
 		}
292 292
 
293 293
 		return $order_statuses;
Please login to merge, or discard this patch.
src/Controllers/Version4/ProductAttributes.php 1 patch
Spacing   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Product Attributes controller class.
@@ -40,26 +40,26 @@  discard block
 block discarded – undo
40 40
 			array(
41 41
 				array(
42 42
 					'methods'             => \WP_REST_Server::READABLE,
43
-					'callback'            => array( $this, 'get_items' ),
44
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
43
+					'callback'            => array($this, 'get_items'),
44
+					'permission_callback' => array($this, 'get_items_permissions_check'),
45 45
 					'args'                => $this->get_collection_params(),
46 46
 				),
47 47
 				array(
48 48
 					'methods'             => \WP_REST_Server::CREATABLE,
49
-					'callback'            => array( $this, 'create_item' ),
50
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
49
+					'callback'            => array($this, 'create_item'),
50
+					'permission_callback' => array($this, 'create_item_permissions_check'),
51 51
 					'args'                => array_merge(
52
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
52
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
53 53
 						array(
54 54
 							'name' => array(
55
-								'description' => __( 'Name for the resource.', 'woocommerce' ),
55
+								'description' => __('Name for the resource.', 'woocommerce'),
56 56
 								'type'        => 'string',
57 57
 								'required'    => true,
58 58
 							),
59 59
 						)
60 60
 					),
61 61
 				),
62
-				'schema' => array( $this, 'get_public_item_schema' ),
62
+				'schema' => array($this, 'get_public_item_schema'),
63 63
 			),
64 64
 			true
65 65
 		);
@@ -70,37 +70,37 @@  discard block
 block discarded – undo
70 70
 			array(
71 71
 				'args' => array(
72 72
 					'id' => array(
73
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
73
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
74 74
 						'type'        => 'integer',
75 75
 					),
76 76
 				),
77 77
 				array(
78 78
 					'methods'             => \WP_REST_Server::READABLE,
79
-					'callback'            => array( $this, 'get_item' ),
80
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
79
+					'callback'            => array($this, 'get_item'),
80
+					'permission_callback' => array($this, 'get_item_permissions_check'),
81 81
 					'args'                => array(
82
-						'context'         => $this->get_context_param( array( 'default' => 'view' ) ),
82
+						'context'         => $this->get_context_param(array('default' => 'view')),
83 83
 					),
84 84
 				),
85 85
 				array(
86 86
 					'methods'             => \WP_REST_Server::EDITABLE,
87
-					'callback'            => array( $this, 'update_item' ),
88
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
89
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
87
+					'callback'            => array($this, 'update_item'),
88
+					'permission_callback' => array($this, 'update_item_permissions_check'),
89
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
90 90
 				),
91 91
 				array(
92 92
 					'methods'             => \WP_REST_Server::DELETABLE,
93
-					'callback'            => array( $this, 'delete_item' ),
94
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
93
+					'callback'            => array($this, 'delete_item'),
94
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
95 95
 					'args'                => array(
96 96
 						'force' => array(
97 97
 							'default'     => true,
98 98
 							'type'        => 'boolean',
99
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
99
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
100 100
 						),
101 101
 					),
102 102
 				),
103
-				'schema' => array( $this, 'get_public_item_schema' ),
103
+				'schema' => array($this, 'get_public_item_schema'),
104 104
 			),
105 105
 			true
106 106
 		);
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 			array(
112 112
 				array(
113 113
 					'methods'             => \WP_REST_Server::EDITABLE,
114
-					'callback'            => array( $this, 'batch_items' ),
115
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
116
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
114
+					'callback'            => array($this, 'batch_items'),
115
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
116
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
117 117
 				),
118
-				'schema' => array( $this, 'get_public_batch_schema' ),
118
+				'schema' => array($this, 'get_public_batch_schema'),
119 119
 			),
120 120
 			true
121 121
 		);
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 	 * @param  \WP_REST_Request $request Full details about the request.
128 128
 	 * @return \WP_Error|boolean
129 129
 	 */
130
-	public function get_items_permissions_check( $request ) {
131
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) {
132
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
130
+	public function get_items_permissions_check($request) {
131
+		if ( ! wc_rest_check_manager_permissions('attributes', 'read')) {
132
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
133 133
 		}
134 134
 
135 135
 		return true;
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @param  \WP_REST_Request $request Full details about the request.
142 142
 	 * @return \WP_Error|boolean
143 143
 	 */
144
-	public function create_item_permissions_check( $request ) {
145
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'create' ) ) {
146
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you cannot create new resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
144
+	public function create_item_permissions_check($request) {
145
+		if ( ! wc_rest_check_manager_permissions('attributes', 'create')) {
146
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you cannot create new resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
147 147
 		}
148 148
 
149 149
 		return true;
@@ -155,13 +155,13 @@  discard block
 block discarded – undo
155 155
 	 * @param  \WP_REST_Request $request Full details about the request.
156 156
 	 * @return \WP_Error|boolean
157 157
 	 */
158
-	public function get_item_permissions_check( $request ) {
159
-		if ( ! $this->get_taxonomy( $request ) ) {
160
-			return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
158
+	public function get_item_permissions_check($request) {
159
+		if ( ! $this->get_taxonomy($request)) {
160
+			return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
161 161
 		}
162 162
 
163
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) {
164
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
163
+		if ( ! wc_rest_check_manager_permissions('attributes', 'read')) {
164
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
165 165
 		}
166 166
 
167 167
 		return true;
@@ -173,13 +173,13 @@  discard block
 block discarded – undo
173 173
 	 * @param  \WP_REST_Request $request Full details about the request.
174 174
 	 * @return \WP_Error|boolean
175 175
 	 */
176
-	public function update_item_permissions_check( $request ) {
177
-		if ( ! $this->get_taxonomy( $request ) ) {
178
-			return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
176
+	public function update_item_permissions_check($request) {
177
+		if ( ! $this->get_taxonomy($request)) {
178
+			return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
179 179
 		}
180 180
 
181
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'edit' ) ) {
182
-			return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
181
+		if ( ! wc_rest_check_manager_permissions('attributes', 'edit')) {
182
+			return new \WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
183 183
 		}
184 184
 
185 185
 		return true;
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
 	 * @param  \WP_REST_Request $request Full details about the request.
192 192
 	 * @return \WP_Error|boolean
193 193
 	 */
194
-	public function delete_item_permissions_check( $request ) {
195
-		if ( ! $this->get_taxonomy( $request ) ) {
196
-			return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
194
+	public function delete_item_permissions_check($request) {
195
+		if ( ! $this->get_taxonomy($request)) {
196
+			return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
197 197
 		}
198 198
 
199
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'delete' ) ) {
200
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
199
+		if ( ! wc_rest_check_manager_permissions('attributes', 'delete')) {
200
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
201 201
 		}
202 202
 
203 203
 		return true;
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
 	 *
211 211
 	 * @return bool|\WP_Error
212 212
 	 */
213
-	public function batch_items_permissions_check( $request ) {
214
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'batch' ) ) {
215
-			return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
213
+	public function batch_items_permissions_check($request) {
214
+		if ( ! wc_rest_check_manager_permissions('attributes', 'batch')) {
215
+			return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
216 216
 		}
217 217
 
218 218
 		return true;
@@ -224,16 +224,16 @@  discard block
 block discarded – undo
224 224
 	 * @param \WP_REST_Request $request Request params.
225 225
 	 * @return array
226 226
 	 */
227
-	public function get_items( $request ) {
227
+	public function get_items($request) {
228 228
 		$attributes = wc_get_attribute_taxonomies();
229 229
 		$data       = array();
230
-		foreach ( $attributes as $attribute_obj ) {
231
-			$attribute = $this->prepare_item_for_response( $attribute_obj, $request );
232
-			$attribute = $this->prepare_response_for_collection( $attribute );
230
+		foreach ($attributes as $attribute_obj) {
231
+			$attribute = $this->prepare_item_for_response($attribute_obj, $request);
232
+			$attribute = $this->prepare_response_for_collection($attribute);
233 233
 			$data[]    = $attribute;
234 234
 		}
235 235
 
236
-		return rest_ensure_response( $data );
236
+		return rest_ensure_response($data);
237 237
 	}
238 238
 
239 239
 	/**
@@ -242,31 +242,31 @@  discard block
 block discarded – undo
242 242
 	 * @param \WP_REST_Request $request Full details about the request.
243 243
 	 * @return \WP_REST_Request|\WP_Error
244 244
 	 */
245
-	public function create_item( $request ) {
245
+	public function create_item($request) {
246 246
 		global $wpdb;
247 247
 
248 248
 		$id = wc_create_attribute(
249 249
 			array(
250 250
 				'name'         => $request['name'],
251
-				'slug'         => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ),
252
-				'type'         => ! empty( $request['type'] ) ? $request['type'] : 'select',
253
-				'order_by'     => ! empty( $request['order_by'] ) ? $request['order_by'] : 'menu_order',
251
+				'slug'         => wc_sanitize_taxonomy_name(stripslashes($request['slug'])),
252
+				'type'         => ! empty($request['type']) ? $request['type'] : 'select',
253
+				'order_by'     => ! empty($request['order_by']) ? $request['order_by'] : 'menu_order',
254 254
 				'has_archives' => true === $request['has_archives'],
255 255
 			)
256 256
 		);
257 257
 
258 258
 		// Checks for errors.
259
-		if ( is_wp_error( $id ) ) {
260
-			return new \WP_Error( 'woocommerce_rest_cannot_create', $id->get_error_message(), array( 'status' => 400 ) );
259
+		if (is_wp_error($id)) {
260
+			return new \WP_Error('woocommerce_rest_cannot_create', $id->get_error_message(), array('status' => 400));
261 261
 		}
262 262
 
263
-		$attribute = $this->get_attribute( $id );
263
+		$attribute = $this->get_attribute($id);
264 264
 
265
-		if ( is_wp_error( $attribute ) ) {
265
+		if (is_wp_error($attribute)) {
266 266
 			return $attribute;
267 267
 		}
268 268
 
269
-		$this->update_additional_fields_for_object( $attribute, $request );
269
+		$this->update_additional_fields_for_object($attribute, $request);
270 270
 
271 271
 		/**
272 272
 		 * Fires after a single product attribute is created or updated via the REST API.
@@ -275,13 +275,13 @@  discard block
 block discarded – undo
275 275
 		 * @param \WP_REST_Request $request   Request object.
276 276
 		 * @param boolean         $creating  True when creating attribute, false when updating.
277 277
 		 */
278
-		do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, true );
278
+		do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, true);
279 279
 
280
-		$request->set_param( 'context', 'edit' );
281
-		$response = $this->prepare_item_for_response( $attribute, $request );
282
-		$response = rest_ensure_response( $response );
283
-		$response->set_status( 201 );
284
-		$response->header( 'Location', rest_url( '/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id ) );
280
+		$request->set_param('context', 'edit');
281
+		$response = $this->prepare_item_for_response($attribute, $request);
282
+		$response = rest_ensure_response($response);
283
+		$response->set_status(201);
284
+		$response->header('Location', rest_url('/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id));
285 285
 
286 286
 		return $response;
287 287
 	}
@@ -292,16 +292,16 @@  discard block
 block discarded – undo
292 292
 	 * @param \WP_REST_Request $request Full details about the request.
293 293
 	 * @return \WP_REST_Request|\WP_Error
294 294
 	 */
295
-	public function get_item( $request ) {
296
-		$attribute = $this->get_attribute( (int) $request['id'] );
295
+	public function get_item($request) {
296
+		$attribute = $this->get_attribute((int) $request['id']);
297 297
 
298
-		if ( is_wp_error( $attribute ) ) {
298
+		if (is_wp_error($attribute)) {
299 299
 			return $attribute;
300 300
 		}
301 301
 
302
-		$response = $this->prepare_item_for_response( $attribute, $request );
302
+		$response = $this->prepare_item_for_response($attribute, $request);
303 303
 
304
-		return rest_ensure_response( $response );
304
+		return rest_ensure_response($response);
305 305
 	}
306 306
 
307 307
 	/**
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	 * @param \WP_REST_Request $request Full details about the request.
311 311
 	 * @return \WP_REST_Request|\WP_Error
312 312
 	 */
313
-	public function update_item( $request ) {
313
+	public function update_item($request) {
314 314
 		global $wpdb;
315 315
 
316 316
 		$id     = (int) $request['id'];
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 			$id,
319 319
 			array(
320 320
 				'name'         => $request['name'],
321
-				'slug'         => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ),
321
+				'slug'         => wc_sanitize_taxonomy_name(stripslashes($request['slug'])),
322 322
 				'type'         => $request['type'],
323 323
 				'order_by'     => $request['order_by'],
324 324
 				'has_archives' => $request['has_archives'],
@@ -326,17 +326,17 @@  discard block
 block discarded – undo
326 326
 		);
327 327
 
328 328
 		// Checks for errors.
329
-		if ( is_wp_error( $edited ) ) {
330
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', $edited->get_error_message(), array( 'status' => 400 ) );
329
+		if (is_wp_error($edited)) {
330
+			return new \WP_Error('woocommerce_rest_cannot_edit', $edited->get_error_message(), array('status' => 400));
331 331
 		}
332 332
 
333
-		$attribute = $this->get_attribute( $id );
333
+		$attribute = $this->get_attribute($id);
334 334
 
335
-		if ( is_wp_error( $attribute ) ) {
335
+		if (is_wp_error($attribute)) {
336 336
 			return $attribute;
337 337
 		}
338 338
 
339
-		$this->update_additional_fields_for_object( $attribute, $request );
339
+		$this->update_additional_fields_for_object($attribute, $request);
340 340
 
341 341
 		/**
342 342
 		 * Fires after a single product attribute is created or updated via the REST API.
@@ -345,12 +345,12 @@  discard block
 block discarded – undo
345 345
 		 * @param \WP_REST_Request $request   Request object.
346 346
 		 * @param boolean         $creating  True when creating attribute, false when updating.
347 347
 		 */
348
-		do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, false );
348
+		do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, false);
349 349
 
350
-		$request->set_param( 'context', 'edit' );
351
-		$response = $this->prepare_item_for_response( $attribute, $request );
350
+		$request->set_param('context', 'edit');
351
+		$response = $this->prepare_item_for_response($attribute, $request);
352 352
 
353
-		return rest_ensure_response( $response );
353
+		return rest_ensure_response($response);
354 354
 	}
355 355
 
356 356
 	/**
@@ -359,26 +359,26 @@  discard block
 block discarded – undo
359 359
 	 * @param \WP_REST_Request $request Full details about the request.
360 360
 	 * @return \WP_REST_Response|\WP_Error
361 361
 	 */
362
-	public function delete_item( $request ) {
363
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
362
+	public function delete_item($request) {
363
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
364 364
 
365 365
 		// We don't support trashing for this type, error out.
366
-		if ( ! $force ) {
367
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
366
+		if ( ! $force) {
367
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Resource does not support trashing.', 'woocommerce'), array('status' => 501));
368 368
 		}
369 369
 
370
-		$attribute = $this->get_attribute( (int) $request['id'] );
370
+		$attribute = $this->get_attribute((int) $request['id']);
371 371
 
372
-		if ( is_wp_error( $attribute ) ) {
372
+		if (is_wp_error($attribute)) {
373 373
 			return $attribute;
374 374
 		}
375 375
 
376
-		$request->set_param( 'context', 'edit' );
377
-		$previous = $this->prepare_item_for_response( $attribute, $request );
378
-		$deleted  = wc_delete_attribute( $attribute->attribute_id );
376
+		$request->set_param('context', 'edit');
377
+		$previous = $this->prepare_item_for_response($attribute, $request);
378
+		$deleted  = wc_delete_attribute($attribute->attribute_id);
379 379
 
380
-		if ( false === $deleted ) {
381
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
380
+		if (false === $deleted) {
381
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
382 382
 		}
383 383
 
384 384
 		$response = new \WP_REST_Response();
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 		 * @param \WP_REST_Response $response The response data.
397 397
 		 * @param \WP_REST_Request  $request  The request sent to the API.
398 398
 		 */
399
-		do_action( 'woocommerce_rest_delete_product_attribute', $attribute, $response, $request );
399
+		do_action('woocommerce_rest_delete_product_attribute', $attribute, $response, $request);
400 400
 
401 401
 		return $response;
402 402
 	}
@@ -408,23 +408,23 @@  discard block
 block discarded – undo
408 408
 	 * @param \WP_REST_Request $request Request params.
409 409
 	 * @return \WP_REST_Response $response
410 410
 	 */
411
-	public function prepare_item_for_response( $item, $request ) {
411
+	public function prepare_item_for_response($item, $request) {
412 412
 		$data = array(
413 413
 			'id'           => (int) $item->attribute_id,
414 414
 			'name'         => $item->attribute_label,
415
-			'slug'         => wc_attribute_taxonomy_name( $item->attribute_name ),
415
+			'slug'         => wc_attribute_taxonomy_name($item->attribute_name),
416 416
 			'type'         => $item->attribute_type,
417 417
 			'order_by'     => $item->attribute_orderby,
418 418
 			'has_archives' => (bool) $item->attribute_public,
419 419
 		);
420 420
 
421
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
422
-		$data    = $this->add_additional_fields_to_object( $data, $request );
423
-		$data    = $this->filter_response_by_context( $data, $context );
421
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
422
+		$data    = $this->add_additional_fields_to_object($data, $request);
423
+		$data    = $this->filter_response_by_context($data, $context);
424 424
 
425
-		$response = rest_ensure_response( $data );
425
+		$response = rest_ensure_response($data);
426 426
 
427
-		$response->add_links( $this->prepare_links( $item ) );
427
+		$response->add_links($this->prepare_links($item));
428 428
 
429 429
 		/**
430 430
 		 * Filter a attribute item returned from the API.
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 		 * @param object            $item      The original attribute object.
436 436
 		 * @param \WP_REST_Request   $request   Request used to generate the response.
437 437
 		 */
438
-		return apply_filters( 'woocommerce_rest_prepare_product_attribute', $response, $item, $request );
438
+		return apply_filters('woocommerce_rest_prepare_product_attribute', $response, $item, $request);
439 439
 	}
440 440
 
441 441
 	/**
@@ -444,14 +444,14 @@  discard block
 block discarded – undo
444 444
 	 * @param object $attribute Attribute object.
445 445
 	 * @return array Links for the given attribute.
446 446
 	 */
447
-	protected function prepare_links( $attribute ) {
447
+	protected function prepare_links($attribute) {
448 448
 		$base  = '/' . $this->namespace . '/' . $this->rest_base;
449 449
 		$links = array(
450 450
 			'self' => array(
451
-				'href' => rest_url( trailingslashit( $base ) . $attribute->attribute_id ),
451
+				'href' => rest_url(trailingslashit($base) . $attribute->attribute_id),
452 452
 			),
453 453
 			'collection' => array(
454
-				'href' => rest_url( $base ),
454
+				'href' => rest_url($base),
455 455
 			),
456 456
 		);
457 457
 
@@ -470,51 +470,51 @@  discard block
 block discarded – undo
470 470
 			'type'                 => 'object',
471 471
 			'properties'           => array(
472 472
 				'id' => array(
473
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
473
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
474 474
 					'type'        => 'integer',
475
-					'context'     => array( 'view', 'edit' ),
475
+					'context'     => array('view', 'edit'),
476 476
 					'readonly'    => true,
477 477
 				),
478 478
 				'name' => array(
479
-					'description' => __( 'Attribute name.', 'woocommerce' ),
479
+					'description' => __('Attribute name.', 'woocommerce'),
480 480
 					'type'        => 'string',
481
-					'context'     => array( 'view', 'edit' ),
481
+					'context'     => array('view', 'edit'),
482 482
 					'arg_options' => array(
483 483
 						'sanitize_callback' => 'sanitize_text_field',
484 484
 					),
485 485
 				),
486 486
 				'slug' => array(
487
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
487
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
488 488
 					'type'        => 'string',
489
-					'context'     => array( 'view', 'edit' ),
489
+					'context'     => array('view', 'edit'),
490 490
 					'arg_options' => array(
491 491
 						'sanitize_callback' => 'sanitize_title',
492 492
 					),
493 493
 				),
494 494
 				'type' => array(
495
-					'description' => __( 'Type of attribute.', 'woocommerce' ),
495
+					'description' => __('Type of attribute.', 'woocommerce'),
496 496
 					'type'        => 'string',
497 497
 					'default'     => 'select',
498
-					'enum'        => array_keys( wc_get_attribute_types() ),
499
-					'context'     => array( 'view', 'edit' ),
498
+					'enum'        => array_keys(wc_get_attribute_types()),
499
+					'context'     => array('view', 'edit'),
500 500
 				),
501 501
 				'order_by' => array(
502
-					'description' => __( 'Default sort order.', 'woocommerce' ),
502
+					'description' => __('Default sort order.', 'woocommerce'),
503 503
 					'type'        => 'string',
504 504
 					'default'     => 'menu_order',
505
-					'enum'        => array( 'menu_order', 'name', 'name_num', 'id' ),
506
-					'context'     => array( 'view', 'edit' ),
505
+					'enum'        => array('menu_order', 'name', 'name_num', 'id'),
506
+					'context'     => array('view', 'edit'),
507 507
 				),
508 508
 				'has_archives' => array(
509
-					'description' => __( 'Enable/Disable attribute archives.', 'woocommerce' ),
509
+					'description' => __('Enable/Disable attribute archives.', 'woocommerce'),
510 510
 					'type'        => 'boolean',
511 511
 					'default'     => false,
512
-					'context'     => array( 'view', 'edit' ),
512
+					'context'     => array('view', 'edit'),
513 513
 				),
514 514
 			),
515 515
 		);
516 516
 
517
-		return $this->add_additional_fields_schema( $schema );
517
+		return $this->add_additional_fields_schema($schema);
518 518
 	}
519 519
 
520 520
 	/**
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 	 */
525 525
 	public function get_collection_params() {
526 526
 		$params = array();
527
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
527
+		$params['context'] = $this->get_context_param(array('default' => 'view'));
528 528
 
529 529
 		return $params;
530 530
 	}
@@ -535,13 +535,13 @@  discard block
 block discarded – undo
535 535
 	 * @param \WP_REST_Request $request Full details about the request.
536 536
 	 * @return string
537 537
 	 */
538
-	protected function get_taxonomy( $request ) {
539
-		if ( '' !== $this->attribute ) {
538
+	protected function get_taxonomy($request) {
539
+		if ('' !== $this->attribute) {
540 540
 			return $this->attribute;
541 541
 		}
542 542
 
543
-		if ( $request['id'] ) {
544
-			$name = wc_attribute_taxonomy_name_by_id( (int) $request['id'] );
543
+		if ($request['id']) {
544
+			$name = wc_attribute_taxonomy_name_by_id((int) $request['id']);
545 545
 
546 546
 			$this->attribute = $name;
547 547
 		}
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
 	 * @param int $id Attribute ID.
556 556
 	 * @return stdClass|\WP_Error
557 557
 	 */
558
-	protected function get_attribute( $id ) {
558
+	protected function get_attribute($id) {
559 559
 		global $wpdb;
560 560
 
561 561
 		$attribute = $wpdb->get_row(
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
 			)
570 570
 		);
571 571
 
572
-		if ( is_wp_error( $attribute ) || is_null( $attribute ) ) {
573
-			return new \WP_Error( 'woocommerce_rest_attribute_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
572
+		if (is_wp_error($attribute) || is_null($attribute)) {
573
+			return new \WP_Error('woocommerce_rest_attribute_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
574 574
 		}
575 575
 
576 576
 		return $attribute;
@@ -584,16 +584,16 @@  discard block
 block discarded – undo
584 584
 	 * @param bool   $new_data Is the data new or old.
585 585
 	 * @return bool|\WP_Error
586 586
 	 */
587
-	protected function validate_attribute_slug( $slug, $new_data = true ) {
588
-		if ( strlen( $slug ) >= 28 ) {
587
+	protected function validate_attribute_slug($slug, $new_data = true) {
588
+		if (strlen($slug) >= 28) {
589 589
 			/* Translators: %s slug. */
590
-			return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
591
-		} elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) {
590
+			return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf(__('Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce'), $slug), array('status' => 400));
591
+		} elseif (wc_check_if_attribute_name_is_reserved($slug)) {
592 592
 			/* Translators: %s slug. */
593
-			return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
594
-		} elseif ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) {
593
+			return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf(__('Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce'), $slug), array('status' => 400));
594
+		} elseif ($new_data && taxonomy_exists(wc_attribute_taxonomy_name($slug))) {
595 595
 			/* Translators: %s slug. */
596
-			return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
596
+			return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf(__('Slug "%s" is already in use. Change it, please.', 'woocommerce'), $slug), array('status' => 400));
597 597
 		}
598 598
 
599 599
 		return true;
@@ -606,6 +606,6 @@  discard block
 block discarded – undo
606 606
 	 * @since 3.0.0
607 607
 	 */
608 608
 	protected function flush_rewrite_rules() {
609
-		wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' );
609
+		wp_schedule_single_event(time(), 'woocommerce_flush_rewrite_rules');
610 610
 	}
611 611
 }
Please login to merge, or discard this patch.
src/Server.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use WooCommerce\RestApi\Utilities\SingletonTrait;
13 13
 
@@ -28,17 +28,17 @@  discard block
 block discarded – undo
28 28
 	 * Hook into WordPress ready to init the REST API as needed.
29 29
 	 */
30 30
 	public function init() {
31
-		add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 );
31
+		add_action('rest_api_init', array($this, 'register_rest_routes'), 10);
32 32
 	}
33 33
 
34 34
 	/**
35 35
 	 * Register REST API routes.
36 36
 	 */
37 37
 	public function register_rest_routes() {
38
-		foreach ( $this->get_rest_namespaces() as $namespace => $controllers ) {
39
-			foreach ( $controllers as $controller_name => $controller_class ) {
40
-				$this->controllers[ $namespace ][ $controller_name ] = new $controller_class();
41
-				$this->controllers[ $namespace ][ $controller_name ]->register_routes();
38
+		foreach ($this->get_rest_namespaces() as $namespace => $controllers) {
39
+			foreach ($controllers as $controller_name => $controller_class) {
40
+				$this->controllers[$namespace][$controller_name] = new $controller_class();
41
+				$this->controllers[$namespace][$controller_name]->register_routes();
42 42
 			}
43 43
 		}
44 44
 	}
Please login to merge, or discard this patch.
src/Autoloader.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 namespace WooCommerce\RestApi;
17 17
 
18
-defined( 'ABSPATH' ) || exit;
18
+defined('ABSPATH') || exit;
19 19
 
20 20
 /**
21 21
  * Autoloader class.
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param array $classmap Classmap of files to include.
36 36
 	 */
37
-	public static function register( $classmap ) {
37
+	public static function register($classmap) {
38 38
 		self::$classmap = (array) $classmap;
39
-		spl_autoload_register( array( __CLASS__, 'autoload_class' ) );
39
+		spl_autoload_register(array(__CLASS__, 'autoload_class'));
40 40
 	}
41 41
 
42 42
 	/**
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
 	 * @param string $class Class being autoloaded.
46 46
 	 * @return boolean
47 47
 	 */
48
-	public static function autoload_class( $class ) {
48
+	public static function autoload_class($class) {
49 49
 		$prefix   = 'WooCommerce\\RestApi\\';
50 50
 		$base_dir = __DIR__ . '/';
51 51
 
52 52
 		// does the class use the namespace prefix?
53
-		$len = strlen( $prefix );
53
+		$len = strlen($prefix);
54 54
 
55
-		if ( strncmp( $prefix, $class, $len ) !== 0 ) {
56
-			return self::autoload_from_classmap( $class );
55
+		if (strncmp($prefix, $class, $len) !== 0) {
56
+			return self::autoload_from_classmap($class);
57 57
 		}
58 58
 
59
-		$relative_class = substr( $class, $len );
60
-		$file           = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
59
+		$relative_class = substr($class, $len);
60
+		$file           = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
61 61
 
62
-		if ( file_exists( $file ) ) {
62
+		if (file_exists($file)) {
63 63
 			return include $file;
64 64
 		}
65 65
 	}
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
 	 * @param string $class Class being autoloaded.
71 71
 	 * @return boolean
72 72
 	 */
73
-	protected static function autoload_from_classmap( $class ) {
74
-		if ( empty( self::$classmap ) ) {
73
+	protected static function autoload_from_classmap($class) {
74
+		if (empty(self::$classmap)) {
75 75
 			return false;
76 76
 		}
77 77
 
78
-		if ( array_key_exists( $class, self::$classmap ) ) {
79
-			return include self::$classmap[ $class ];
78
+		if (array_key_exists($class, self::$classmap)) {
79
+			return include self::$classmap[$class];
80 80
 		}
81 81
 	}
82 82
 }
Please login to merge, or discard this patch.
init.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,12 +6,12 @@
 block discarded – undo
6 6
  */
7 7
 
8 8
 return function() {
9
-	if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
9
+	if (file_exists(__DIR__ . '/vendor/autoload.php')) {
10 10
 		require __DIR__ . '/vendor/autoload.php';
11 11
 	} else {
12 12
 		require __DIR__ . '/src/Autoloader.php';
13 13
 		$classmap = require 'classmap.php';
14
-		\WooCommerce\RestApi\Autoloader::register( $classmap );
14
+		\WooCommerce\RestApi\Autoloader::register($classmap);
15 15
 	}
16 16
 	\WooCommerce\RestApi\Server::instance()->init();
17 17
 };
Please login to merge, or discard this patch.