Completed
Push — master ( ceae39...0753e3 )
by Mike
254:22 queued 209:15
created
src/RestApi/Version4/Controllers/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\Version4\Controllers;
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/RestApi/Version4/Controllers/OrderNotes.php 1 patch
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Order Notes controller class.
@@ -40,29 +40,29 @@  discard block
 block discarded – undo
40 40
 			array(
41 41
 				'args' => array(
42 42
 					'order_id'  => array(
43
-						'description' => __( 'The order ID.', 'woocommerce' ),
43
+						'description' => __('The order ID.', 'woocommerce'),
44 44
 						'type'        => 'integer',
45 45
 					),
46 46
 				),
47 47
 				array(
48 48
 					'methods'             => \WP_REST_Server::READABLE,
49
-					'callback'            => array( $this, 'get_items' ),
50
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
49
+					'callback'            => array($this, 'get_items'),
50
+					'permission_callback' => array($this, 'get_items_permissions_check'),
51 51
 					'args'                => $this->get_collection_params(),
52 52
 				),
53 53
 				array(
54 54
 					'methods'             => \WP_REST_Server::CREATABLE,
55
-					'callback'            => array( $this, 'create_item' ),
56
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
57
-					'args'                => array_merge( $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), array(
55
+					'callback'            => array($this, 'create_item'),
56
+					'permission_callback' => array($this, 'create_item_permissions_check'),
57
+					'args'                => array_merge($this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), array(
58 58
 						'note' => array(
59 59
 							'type'        => 'string',
60
-							'description' => __( 'Order note content.', 'woocommerce' ),
60
+							'description' => __('Order note content.', 'woocommerce'),
61 61
 							'required'    => true,
62 62
 						),
63
-					) ),
63
+					)),
64 64
 				),
65
-				'schema' => array( $this, 'get_public_item_schema' ),
65
+				'schema' => array($this, 'get_public_item_schema'),
66 66
 			),
67 67
 			true
68 68
 		);
@@ -73,35 +73,35 @@  discard block
 block discarded – undo
73 73
 			array(
74 74
 				'args' => array(
75 75
 					'id' => array(
76
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
76
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
77 77
 						'type'        => 'integer',
78 78
 					),
79 79
 					'order_id'  => array(
80
-						'description' => __( 'The order ID.', 'woocommerce' ),
80
+						'description' => __('The order ID.', 'woocommerce'),
81 81
 						'type'        => 'integer',
82 82
 					),
83 83
 				),
84 84
 				array(
85 85
 					'methods'             => \WP_REST_Server::READABLE,
86
-					'callback'            => array( $this, 'get_item' ),
87
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
86
+					'callback'            => array($this, 'get_item'),
87
+					'permission_callback' => array($this, 'get_item_permissions_check'),
88 88
 					'args'                => array(
89
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
89
+						'context' => $this->get_context_param(array('default' => 'view')),
90 90
 					),
91 91
 				),
92 92
 				array(
93 93
 					'methods'             => \WP_REST_Server::DELETABLE,
94
-					'callback'            => array( $this, 'delete_item' ),
95
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
94
+					'callback'            => array($this, 'delete_item'),
95
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
96 96
 					'args'                => array(
97 97
 						'force' => array(
98 98
 							'default'     => false,
99 99
 							'type'        => 'boolean',
100
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
100
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
101 101
 						),
102 102
 					),
103 103
 				),
104
-				'schema' => array( $this, 'get_public_item_schema' ),
104
+				'schema' => array($this, 'get_public_item_schema'),
105 105
 			),
106 106
 			true
107 107
 		);
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 	 * @param  \WP_REST_Request $request Full details about the request.
114 114
 	 * @return \WP_Error|boolean
115 115
 	 */
116
-	public function get_items_permissions_check( $request ) {
117
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) {
118
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
116
+	public function get_items_permissions_check($request) {
117
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) {
118
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
119 119
 		}
120 120
 
121 121
 		return true;
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 	 *
129 129
 	 * @return bool|\WP_Error
130 130
 	 */
131
-	public function create_item_permissions_check( $request ) {
132
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) {
133
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
131
+	public function create_item_permissions_check($request) {
132
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) {
133
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
134 134
 		}
135 135
 
136 136
 		return true;
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @param  \WP_REST_Request $request Full details about the request.
143 143
 	 * @return \WP_Error|boolean
144 144
 	 */
145
-	public function get_item_permissions_check( $request ) {
146
-		$order = wc_get_order( (int) $request['order_id'] );
145
+	public function get_item_permissions_check($request) {
146
+		$order = wc_get_order((int) $request['order_id']);
147 147
 
148
-		if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'read', $order->get_id() ) ) {
149
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
148
+		if ($order && ! wc_rest_check_post_permissions($this->post_type, 'read', $order->get_id())) {
149
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
150 150
 		}
151 151
 
152 152
 		return true;
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @return bool|\WP_Error
161 161
 	 */
162
-	public function delete_item_permissions_check( $request ) {
163
-		$order = wc_get_order( (int) $request['order_id'] );
162
+	public function delete_item_permissions_check($request) {
163
+		$order = wc_get_order((int) $request['order_id']);
164 164
 
165
-		if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $order->get_id() ) ) {
166
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
165
+		if ($order && ! wc_rest_check_post_permissions($this->post_type, 'delete', $order->get_id())) {
166
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
167 167
 		}
168 168
 
169 169
 		return true;
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 	 *
177 177
 	 * @return array|\WP_Error
178 178
 	 */
179
-	public function get_items( $request ) {
180
-		$order = wc_get_order( (int) $request['order_id'] );
179
+	public function get_items($request) {
180
+		$order = wc_get_order((int) $request['order_id']);
181 181
 
182
-		if ( ! $order || $this->post_type !== $order->get_type() ) {
183
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) );
182
+		if ( ! $order || $this->post_type !== $order->get_type()) {
183
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid order ID.', 'woocommerce'), array('status' => 404));
184 184
 		}
185 185
 
186 186
 		$args = array(
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		);
191 191
 
192 192
 		// Allow filter by order note type.
193
-		if ( 'customer' === $request['type'] ) {
193
+		if ('customer' === $request['type']) {
194 194
 			$args['meta_query'] = array( // WPCS: slow query ok.
195 195
 				array(
196 196
 					'key'     => 'is_customer_note',
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 					'compare' => '=',
199 199
 				),
200 200
 			);
201
-		} elseif ( 'internal' === $request['type'] ) {
201
+		} elseif ('internal' === $request['type']) {
202 202
 			$args['meta_query'] = array( // WPCS: slow query ok.
203 203
 				array(
204 204
 					'key'     => 'is_customer_note',
@@ -207,20 +207,20 @@  discard block
 block discarded – undo
207 207
 			);
208 208
 		}
209 209
 
210
-		remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
210
+		remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1);
211 211
 
212
-		$notes = get_comments( $args );
212
+		$notes = get_comments($args);
213 213
 
214
-		add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
214
+		add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1);
215 215
 
216 216
 		$data = array();
217
-		foreach ( $notes as $note ) {
218
-			$order_note = $this->prepare_item_for_response( $note, $request );
219
-			$order_note = $this->prepare_response_for_collection( $order_note );
217
+		foreach ($notes as $note) {
218
+			$order_note = $this->prepare_item_for_response($note, $request);
219
+			$order_note = $this->prepare_response_for_collection($order_note);
220 220
 			$data[]     = $order_note;
221 221
 		}
222 222
 
223
-		return rest_ensure_response( $data );
223
+		return rest_ensure_response($data);
224 224
 	}
225 225
 
226 226
 	/**
@@ -229,27 +229,27 @@  discard block
 block discarded – undo
229 229
 	 * @param \WP_REST_Request $request Full details about the request.
230 230
 	 * @return \WP_Error\WP_REST_Response
231 231
 	 */
232
-	public function create_item( $request ) {
233
-		if ( ! empty( $request['id'] ) ) {
232
+	public function create_item($request) {
233
+		if ( ! empty($request['id'])) {
234 234
 			/* translators: %s: post type */
235
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
235
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
236 236
 		}
237 237
 
238
-		$order = wc_get_order( (int) $request['order_id'] );
238
+		$order = wc_get_order((int) $request['order_id']);
239 239
 
240
-		if ( ! $order || $this->post_type !== $order->get_type() ) {
241
-			return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) );
240
+		if ( ! $order || $this->post_type !== $order->get_type()) {
241
+			return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404));
242 242
 		}
243 243
 
244 244
 		// Create the note.
245
-		$note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] );
245
+		$note_id = $order->add_order_note($request['note'], $request['customer_note'], $request['added_by_user']);
246 246
 
247
-		if ( ! $note_id ) {
248
-			return new \WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) );
247
+		if ( ! $note_id) {
248
+			return new \WP_Error('woocommerce_api_cannot_create_order_note', __('Cannot create order note, please try again.', 'woocommerce'), array('status' => 500));
249 249
 		}
250 250
 
251
-		$note = get_comment( $note_id );
252
-		$this->update_additional_fields_for_object( $note, $request );
251
+		$note = get_comment($note_id);
252
+		$this->update_additional_fields_for_object($note, $request);
253 253
 
254 254
 		/**
255 255
 		 * Fires after a order note is created or updated via the REST API.
@@ -258,13 +258,13 @@  discard block
 block discarded – undo
258 258
 		 * @param \WP_REST_Request $request   Request object.
259 259
 		 * @param boolean         $creating  True when creating item, false when updating.
260 260
 		 */
261
-		do_action( 'woocommerce_rest_insert_order_note', $note, $request, true );
261
+		do_action('woocommerce_rest_insert_order_note', $note, $request, true);
262 262
 
263
-		$request->set_param( 'context', 'edit' );
264
-		$response = $this->prepare_item_for_response( $note, $request );
265
-		$response = rest_ensure_response( $response );
266
-		$response->set_status( 201 );
267
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, str_replace( '(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base ), $note_id ) ) );
263
+		$request->set_param('context', 'edit');
264
+		$response = $this->prepare_item_for_response($note, $request);
265
+		$response = rest_ensure_response($response);
266
+		$response->set_status(201);
267
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, str_replace('(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base), $note_id)));
268 268
 
269 269
 		return $response;
270 270
 	}
@@ -275,22 +275,22 @@  discard block
 block discarded – undo
275 275
 	 * @param \WP_REST_Request $request Full details about the request.
276 276
 	 * @return \WP_Error\WP_REST_Response
277 277
 	 */
278
-	public function get_item( $request ) {
278
+	public function get_item($request) {
279 279
 		$id    = (int) $request['id'];
280
-		$order = wc_get_order( (int) $request['order_id'] );
280
+		$order = wc_get_order((int) $request['order_id']);
281 281
 
282
-		if ( ! $order || $this->post_type !== $order->get_type() ) {
283
-			return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) );
282
+		if ( ! $order || $this->post_type !== $order->get_type()) {
283
+			return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404));
284 284
 		}
285 285
 
286
-		$note = get_comment( $id );
286
+		$note = get_comment($id);
287 287
 
288
-		if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) {
289
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
288
+		if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) {
289
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
290 290
 		}
291 291
 
292
-		$order_note = $this->prepare_item_for_response( $note, $request );
293
-		$response   = rest_ensure_response( $order_note );
292
+		$order_note = $this->prepare_item_for_response($note, $request);
293
+		$response   = rest_ensure_response($order_note);
294 294
 
295 295
 		return $response;
296 296
 	}
@@ -301,33 +301,33 @@  discard block
 block discarded – undo
301 301
 	 * @param \WP_REST_Request $request Full details about the request.
302 302
 	 * @return \WP_REST_Response|\WP_Error
303 303
 	 */
304
-	public function delete_item( $request ) {
304
+	public function delete_item($request) {
305 305
 		$id    = (int) $request['id'];
306
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
306
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
307 307
 
308 308
 		// We don't support trashing for this type, error out.
309
-		if ( ! $force ) {
310
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
309
+		if ( ! $force) {
310
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501));
311 311
 		}
312 312
 
313
-		$order = wc_get_order( (int) $request['order_id'] );
313
+		$order = wc_get_order((int) $request['order_id']);
314 314
 
315
-		if ( ! $order || $this->post_type !== $order->get_type() ) {
316
-			return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) );
315
+		if ( ! $order || $this->post_type !== $order->get_type()) {
316
+			return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404));
317 317
 		}
318 318
 
319
-		$note = get_comment( $id );
319
+		$note = get_comment($id);
320 320
 
321
-		if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) {
322
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
321
+		if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) {
322
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
323 323
 		}
324 324
 
325
-		$request->set_param( 'context', 'edit' );
326
-		$previous = $this->prepare_item_for_response( $note, $request );
327
-		$result   = wc_delete_order_note( $note->comment_ID );
325
+		$request->set_param('context', 'edit');
326
+		$previous = $this->prepare_item_for_response($note, $request);
327
+		$result   = wc_delete_order_note($note->comment_ID);
328 328
 
329
-		if ( ! $result ) {
330
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), 'order_note' ), array( 'status' => 500 ) );
329
+		if ( ! $result) {
330
+			return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), 'order_note'), array('status' => 500));
331 331
 		}
332 332
 
333 333
 		$response = new \WP_REST_Response();
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 		 * @param \WP_REST_Response $response The response data.
346 346
 		 * @param \WP_REST_Request  $request  The request sent to the API.
347 347
 		 */
348
-		do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request );
348
+		do_action('woocommerce_rest_delete_order_note', $note, $response, $request);
349 349
 
350 350
 		return $response;
351 351
 	}
@@ -357,24 +357,24 @@  discard block
 block discarded – undo
357 357
 	 * @param \WP_REST_Request $request Request object.
358 358
 	 * @return \WP_REST_Response $response Response data.
359 359
 	 */
360
-	public function prepare_item_for_response( $note, $request ) {
360
+	public function prepare_item_for_response($note, $request) {
361 361
 		$data = array(
362 362
 			'id'               => (int) $note->comment_ID,
363
-			'author'           => __( 'WooCommerce', 'woocommerce' ) === $note->comment_author ? 'system' : $note->comment_author,
364
-			'date_created'     => wc_rest_prepare_date_response( $note->comment_date ),
365
-			'date_created_gmt' => wc_rest_prepare_date_response( $note->comment_date_gmt ),
363
+			'author'           => __('WooCommerce', 'woocommerce') === $note->comment_author ? 'system' : $note->comment_author,
364
+			'date_created'     => wc_rest_prepare_date_response($note->comment_date),
365
+			'date_created_gmt' => wc_rest_prepare_date_response($note->comment_date_gmt),
366 366
 			'note'             => $note->comment_content,
367
-			'customer_note'    => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ),
367
+			'customer_note'    => (bool) get_comment_meta($note->comment_ID, 'is_customer_note', true),
368 368
 		);
369 369
 
370
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
371
-		$data    = $this->add_additional_fields_to_object( $data, $request );
372
-		$data    = $this->filter_response_by_context( $data, $context );
370
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
371
+		$data    = $this->add_additional_fields_to_object($data, $request);
372
+		$data    = $this->filter_response_by_context($data, $context);
373 373
 
374 374
 		// Wrap the data in a response object.
375
-		$response = rest_ensure_response( $data );
375
+		$response = rest_ensure_response($data);
376 376
 
377
-		$response->add_links( $this->prepare_links( $note ) );
377
+		$response->add_links($this->prepare_links($note));
378 378
 
379 379
 		/**
380 380
 		 * Filter order note object returned from the REST API.
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 		 * @param WP_Comment       $note     Order note object used to create response.
384 384
 		 * @param \WP_REST_Request  $request  Request object.
385 385
 		 */
386
-		return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request );
386
+		return apply_filters('woocommerce_rest_prepare_order_note', $response, $note, $request);
387 387
 	}
388 388
 
389 389
 	/**
@@ -392,18 +392,18 @@  discard block
 block discarded – undo
392 392
 	 * @param WP_Comment $note Delivery order_note object.
393 393
 	 * @return array Links for the given order note.
394 394
 	 */
395
-	protected function prepare_links( $note ) {
395
+	protected function prepare_links($note) {
396 396
 		$order_id = (int) $note->comment_post_ID;
397
-		$base     = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base );
397
+		$base     = str_replace('(?P<order_id>[\d]+)', $order_id, $this->rest_base);
398 398
 		$links    = array(
399 399
 			'self' => array(
400
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $note->comment_ID ) ),
400
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $note->comment_ID)),
401 401
 			),
402 402
 			'collection' => array(
403
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
403
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)),
404 404
 			),
405 405
 			'up' => array(
406
-				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ),
406
+				'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order_id)),
407 407
 			),
408 408
 		);
409 409
 
@@ -422,50 +422,50 @@  discard block
 block discarded – undo
422 422
 			'type'       => 'object',
423 423
 			'properties' => array(
424 424
 				'id'               => array(
425
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
425
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
426 426
 					'type'        => 'integer',
427
-					'context'     => array( 'view', 'edit' ),
427
+					'context'     => array('view', 'edit'),
428 428
 					'readonly'    => true,
429 429
 				),
430 430
 				'author'           => array(
431
-					'description' => __( 'Order note author.', 'woocommerce' ),
431
+					'description' => __('Order note author.', 'woocommerce'),
432 432
 					'type'        => 'string',
433
-					'context'     => array( 'view', 'edit' ),
433
+					'context'     => array('view', 'edit'),
434 434
 					'readonly'    => true,
435 435
 				),
436 436
 				'date_created'     => array(
437
-					'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ),
437
+					'description' => __("The date the order note was created, in the site's timezone.", 'woocommerce'),
438 438
 					'type'        => 'date-time',
439
-					'context'     => array( 'view', 'edit' ),
439
+					'context'     => array('view', 'edit'),
440 440
 					'readonly'    => true,
441 441
 				),
442 442
 				'date_created_gmt' => array(
443
-					'description' => __( 'The date the order note was created, as GMT.', 'woocommerce' ),
443
+					'description' => __('The date the order note was created, as GMT.', 'woocommerce'),
444 444
 					'type'        => 'date-time',
445
-					'context'     => array( 'view', 'edit' ),
445
+					'context'     => array('view', 'edit'),
446 446
 					'readonly'    => true,
447 447
 				),
448 448
 				'note'             => array(
449
-					'description' => __( 'Order note content.', 'woocommerce' ),
449
+					'description' => __('Order note content.', 'woocommerce'),
450 450
 					'type'        => 'string',
451
-					'context'     => array( 'view', 'edit' ),
451
+					'context'     => array('view', 'edit'),
452 452
 				),
453 453
 				'customer_note'    => array(
454
-					'description' => __( 'If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce' ),
454
+					'description' => __('If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce'),
455 455
 					'type'        => 'boolean',
456 456
 					'default'     => false,
457
-					'context'     => array( 'view', 'edit' ),
457
+					'context'     => array('view', 'edit'),
458 458
 				),
459 459
 				'added_by_user'    => array(
460
-					'description' => __( 'If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce' ),
460
+					'description' => __('If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce'),
461 461
 					'type'        => 'boolean',
462 462
 					'default'     => false,
463
-					'context'     => array( 'edit' ),
463
+					'context'     => array('edit'),
464 464
 				),
465 465
 			),
466 466
 		);
467 467
 
468
-		return $this->add_additional_fields_schema( $schema );
468
+		return $this->add_additional_fields_schema($schema);
469 469
 	}
470 470
 
471 471
 	/**
@@ -475,12 +475,12 @@  discard block
 block discarded – undo
475 475
 	 */
476 476
 	public function get_collection_params() {
477 477
 		$params            = array();
478
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
478
+		$params['context'] = $this->get_context_param(array('default' => 'view'));
479 479
 		$params['type']    = array(
480 480
 			'default'           => 'any',
481
-			'description'       => __( 'Limit result to customers or internal notes.', 'woocommerce' ),
481
+			'description'       => __('Limit result to customers or internal notes.', 'woocommerce'),
482 482
 			'type'              => 'string',
483
-			'enum'              => array( 'any', 'customer', 'internal' ),
483
+			'enum'              => array('any', 'customer', 'internal'),
484 484
 			'sanitize_callback' => 'sanitize_key',
485 485
 			'validate_callback' => 'rest_validate_request_arg',
486 486
 		);
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/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\Version4\Controllers;
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/RestApi/Version4/Controllers/Taxes.php 1 patch
Spacing   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Taxes controller class.
@@ -33,17 +33,17 @@  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' ),
44
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
42
+					'callback'            => array($this, 'create_item'),
43
+					'permission_callback' => array($this, 'create_item_permissions_check'),
44
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
45 45
 				),
46
-				'schema' => array( $this, 'get_public_item_schema' ),
46
+				'schema' => array($this, 'get_public_item_schema'),
47 47
 			),
48 48
 			true
49 49
 		);
@@ -54,37 +54,37 @@  discard block
 block discarded – undo
54 54
 			array(
55 55
 				'args' => array(
56 56
 					'id' => array(
57
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
57
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
58 58
 						'type'        => 'integer',
59 59
 					),
60 60
 				),
61 61
 				array(
62 62
 					'methods'             => \WP_REST_Server::READABLE,
63
-					'callback'            => array( $this, 'get_item' ),
64
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
63
+					'callback'            => array($this, 'get_item'),
64
+					'permission_callback' => array($this, 'get_item_permissions_check'),
65 65
 					'args'                => array(
66
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
66
+						'context' => $this->get_context_param(array('default' => 'view')),
67 67
 					),
68 68
 				),
69 69
 				array(
70 70
 					'methods'             => \WP_REST_Server::EDITABLE,
71
-					'callback'            => array( $this, 'update_item' ),
72
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
73
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
71
+					'callback'            => array($this, 'update_item'),
72
+					'permission_callback' => array($this, 'update_item_permissions_check'),
73
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
74 74
 				),
75 75
 				array(
76 76
 					'methods'             => \WP_REST_Server::DELETABLE,
77
-					'callback'            => array( $this, 'delete_item' ),
78
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
77
+					'callback'            => array($this, 'delete_item'),
78
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
79 79
 					'args'                => array(
80 80
 						'force' => array(
81 81
 							'default'     => false,
82 82
 							'type'        => 'boolean',
83
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
83
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
84 84
 						),
85 85
 					),
86 86
 				),
87
-				'schema' => array( $this, 'get_public_item_schema' ),
87
+				'schema' => array($this, 'get_public_item_schema'),
88 88
 			),
89 89
 			true
90 90
 		);
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
 			array(
96 96
 				array(
97 97
 					'methods'             => \WP_REST_Server::EDITABLE,
98
-					'callback'            => array( $this, 'batch_items' ),
99
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
100
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
98
+					'callback'            => array($this, 'batch_items'),
99
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
100
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
101 101
 				),
102
-				'schema' => array( $this, 'get_public_batch_schema' ),
102
+				'schema' => array($this, 'get_public_batch_schema'),
103 103
 			),
104 104
 			true
105 105
 		);
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 	 * @param  \WP_REST_Request $request Full details about the request.
112 112
 	 * @return \WP_Error|boolean
113 113
 	 */
114
-	public function get_items_permissions_check( $request ) {
115
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
116
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
114
+	public function get_items_permissions_check($request) {
115
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
116
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
117 117
 		}
118 118
 
119 119
 		return true;
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 	 *
127 127
 	 * @return bool|\WP_Error
128 128
 	 */
129
-	public function create_item_permissions_check( $request ) {
130
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) {
131
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
129
+	public function create_item_permissions_check($request) {
130
+		if ( ! wc_rest_check_manager_permissions('settings', 'create')) {
131
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
132 132
 		}
133 133
 
134 134
 		return true;
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 	 * @param  \WP_REST_Request $request Full details about the request.
141 141
 	 * @return \WP_Error|boolean
142 142
 	 */
143
-	public function get_item_permissions_check( $request ) {
144
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
145
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
143
+	public function get_item_permissions_check($request) {
144
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
145
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
146 146
 		}
147 147
 
148 148
 		return true;
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 	 *
156 156
 	 * @return bool|\WP_Error
157 157
 	 */
158
-	public function update_item_permissions_check( $request ) {
159
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
160
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
158
+	public function update_item_permissions_check($request) {
159
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
160
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
161 161
 		}
162 162
 
163 163
 		return true;
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @return bool|\WP_Error
172 172
 	 */
173
-	public function delete_item_permissions_check( $request ) {
174
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
175
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
173
+	public function delete_item_permissions_check($request) {
174
+		if ( ! wc_rest_check_manager_permissions('settings', 'delete')) {
175
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
176 176
 		}
177 177
 
178 178
 		return true;
@@ -185,9 +185,9 @@  discard block
 block discarded – undo
185 185
 	 *
186 186
 	 * @return bool|\WP_Error
187 187
 	 */
188
-	public function batch_items_permissions_check( $request ) {
189
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'batch' ) ) {
190
-			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() ) );
188
+	public function batch_items_permissions_check($request) {
189
+		if ( ! wc_rest_check_manager_permissions('settings', 'batch')) {
190
+			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()));
191 191
 		}
192 192
 
193 193
 		return true;
@@ -199,22 +199,22 @@  discard block
 block discarded – undo
199 199
 	 * @param \WP_REST_Request $request Full details about the request.
200 200
 	 * @return \WP_Error\WP_REST_Response
201 201
 	 */
202
-	public function get_items( $request ) {
202
+	public function get_items($request) {
203 203
 		global $wpdb;
204 204
 
205 205
 		$prepared_args           = array();
206 206
 		$prepared_args['order']  = $request['order'];
207 207
 		$prepared_args['number'] = $request['per_page'];
208
-		if ( ! empty( $request['offset'] ) ) {
208
+		if ( ! empty($request['offset'])) {
209 209
 			$prepared_args['offset'] = $request['offset'];
210 210
 		} else {
211
-			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
211
+			$prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number'];
212 212
 		}
213 213
 		$orderby_possibles        = array(
214 214
 			'id'    => 'tax_rate_id',
215 215
 			'order' => 'tax_rate_order',
216 216
 		);
217
-		$prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ];
217
+		$prepared_args['orderby'] = $orderby_possibles[$request['orderby']];
218 218
 		$prepared_args['class']   = $request['class'];
219 219
 		$prepared_args['code']    = $request['code'];
220 220
 		$prepared_args['include'] = $request['include'];
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 		 * @param array           $prepared_args Array of arguments for $wpdb->get_results().
226 226
 		 * @param \WP_REST_Request $request       The current request.
227 227
 		 */
228
-		$prepared_args = apply_filters( 'woocommerce_rest_tax_query', $prepared_args, $request );
228
+		$prepared_args = apply_filters('woocommerce_rest_tax_query', $prepared_args, $request);
229 229
 
230 230
 		$query = "
231 231
 			SELECT *
@@ -234,69 +234,69 @@  discard block
 block discarded – undo
234 234
 		";
235 235
 
236 236
 		// Filter by tax class.
237
-		if ( ! empty( $prepared_args['class'] ) ) {
238
-			$class  = 'standard' !== $prepared_args['class'] ? sanitize_title( $prepared_args['class'] ) : '';
237
+		if ( ! empty($prepared_args['class'])) {
238
+			$class  = 'standard' !== $prepared_args['class'] ? sanitize_title($prepared_args['class']) : '';
239 239
 			$query .= " AND tax_rate_class = '$class'";
240 240
 		}
241 241
 
242 242
 		// Filter by tax code.
243 243
 		$tax_code_search = $prepared_args['code'];
244
-		if ( $tax_code_search ) {
245
-			$tax_code_search = $wpdb->esc_like( $tax_code_search );
244
+		if ($tax_code_search) {
245
+			$tax_code_search = $wpdb->esc_like($tax_code_search);
246 246
 			$tax_code_search = ' \'%' . $tax_code_search . '%\'';
247 247
 			$query          .= ' AND CONCAT_WS( "-", NULLIF(tax_rate_country, ""), NULLIF(tax_rate_state, ""), NULLIF(tax_rate_name, ""), NULLIF(tax_rate_priority, "") ) LIKE ' . $tax_code_search;
248 248
 		}
249 249
 
250 250
 		// Filter by included tax rate IDs.
251 251
 		$included_taxes = $prepared_args['include'];
252
-		if ( ! empty( $included_taxes ) ) {
253
-			$included_taxes = implode( ',', $prepared_args['include'] );
252
+		if ( ! empty($included_taxes)) {
253
+			$included_taxes = implode(',', $prepared_args['include']);
254 254
 			$query         .= " AND tax_rate_id IN ({$included_taxes})";
255 255
 		}
256 256
 
257 257
 		// Order tax rates.
258
-		$order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args['orderby'] ) );
258
+		$order_by = sprintf(' ORDER BY %s', sanitize_key($prepared_args['orderby']));
259 259
 
260 260
 		// Pagination.
261
-		$pagination = sprintf( ' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number'] );
261
+		$pagination = sprintf(' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number']);
262 262
 
263 263
 		// Query taxes.
264
-		$results = $wpdb->get_results( $query . $order_by . $pagination ); // @codingStandardsIgnoreLine.
264
+		$results = $wpdb->get_results($query . $order_by . $pagination); // @codingStandardsIgnoreLine.
265 265
 
266 266
 		$taxes = array();
267
-		foreach ( $results as $tax ) {
268
-			$data    = $this->prepare_item_for_response( $tax, $request );
269
-			$taxes[] = $this->prepare_response_for_collection( $data );
267
+		foreach ($results as $tax) {
268
+			$data    = $this->prepare_item_for_response($tax, $request);
269
+			$taxes[] = $this->prepare_response_for_collection($data);
270 270
 		}
271 271
 
272
-		$response = rest_ensure_response( $taxes );
272
+		$response = rest_ensure_response($taxes);
273 273
 
274 274
 		// Store pagination values for headers then unset for count query.
275 275
 		$per_page = (int) $prepared_args['number'];
276
-		$page     = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
276
+		$page     = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
277 277
 
278 278
 		// Query only for ids.
279
-		$wpdb->get_results( str_replace( 'SELECT *', 'SELECT tax_rate_id', $query ) ); // @codingStandardsIgnoreLine.
279
+		$wpdb->get_results(str_replace('SELECT *', 'SELECT tax_rate_id', $query)); // @codingStandardsIgnoreLine.
280 280
 
281 281
 		// Calculate totals.
282 282
 		$total_taxes = (int) $wpdb->num_rows;
283
-		$response->header( 'X-WP-Total', (int) $total_taxes );
284
-		$max_pages = ceil( $total_taxes / $per_page );
285
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
283
+		$response->header('X-WP-Total', (int) $total_taxes);
284
+		$max_pages = ceil($total_taxes / $per_page);
285
+		$response->header('X-WP-TotalPages', (int) $max_pages);
286 286
 
287
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
288
-		if ( $page > 1 ) {
287
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
288
+		if ($page > 1) {
289 289
 			$prev_page = $page - 1;
290
-			if ( $prev_page > $max_pages ) {
290
+			if ($prev_page > $max_pages) {
291 291
 				$prev_page = $max_pages;
292 292
 			}
293
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
294
-			$response->link_header( 'prev', $prev_link );
293
+			$prev_link = add_query_arg('page', $prev_page, $base);
294
+			$response->link_header('prev', $prev_link);
295 295
 		}
296
-		if ( $max_pages > $page ) {
296
+		if ($max_pages > $page) {
297 297
 			$next_page = $page + 1;
298
-			$next_link = add_query_arg( 'page', $next_page, $base );
299
-			$response->link_header( 'next', $next_link );
298
+			$next_link = add_query_arg('page', $next_page, $base);
299
+			$response->link_header('next', $next_link);
300 300
 		}
301 301
 
302 302
 		return $response;
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
 	 * @param stdClass|null   $current Existing tax object.
310 310
 	 * @return object
311 311
 	 */
312
-	protected function create_or_update_tax( $request, $current = null ) {
313
-		$id          = absint( isset( $request['id'] ) ? $request['id'] : 0 );
312
+	protected function create_or_update_tax($request, $current = null) {
313
+		$id          = absint(isset($request['id']) ? $request['id'] : 0);
314 314
 		$data        = array();
315 315
 		$fields      = array(
316 316
 			'tax_rate_country',
@@ -324,52 +324,52 @@  discard block
 block discarded – undo
324 324
 			'tax_rate_class',
325 325
 		);
326 326
 
327
-		foreach ( $fields as $field ) {
327
+		foreach ($fields as $field) {
328 328
 			// Keys via API differ from the stored names returned by _get_tax_rate.
329
-			$key = 'tax_rate' === $field ? 'rate' : str_replace( 'tax_rate_', '', $field );
329
+			$key = 'tax_rate' === $field ? 'rate' : str_replace('tax_rate_', '', $field);
330 330
 
331 331
 			// Remove data that was not posted.
332
-			if ( ! isset( $request[ $key ] ) ) {
332
+			if ( ! isset($request[$key])) {
333 333
 				continue;
334 334
 			}
335 335
 
336 336
 			// Test new data against current data.
337
-			if ( $current && $current->$field === $request[ $key ] ) {
337
+			if ($current && $current->$field === $request[$key]) {
338 338
 				continue;
339 339
 			}
340 340
 
341 341
 			// Add to data array.
342
-			switch ( $key ) {
342
+			switch ($key) {
343 343
 				case 'tax_rate_priority':
344 344
 				case 'tax_rate_compound':
345 345
 				case 'tax_rate_shipping':
346 346
 				case 'tax_rate_order':
347
-					$data[ $field ] = absint( $request[ $key ] );
347
+					$data[$field] = absint($request[$key]);
348 348
 					break;
349 349
 				case 'tax_rate_class':
350
-					$data[ $field ] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : '';
350
+					$data[$field] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : '';
351 351
 					break;
352 352
 				default:
353
-					$data[ $field ] = wc_clean( $request[ $key ] );
353
+					$data[$field] = wc_clean($request[$key]);
354 354
 					break;
355 355
 			}
356 356
 		}
357 357
 
358
-		if ( $id ) {
359
-			\WC_Tax::_update_tax_rate( $id, $data );
358
+		if ($id) {
359
+			\WC_Tax::_update_tax_rate($id, $data);
360 360
 		} else {
361
-			$id = \WC_Tax::_insert_tax_rate( $data );
361
+			$id = \WC_Tax::_insert_tax_rate($data);
362 362
 		}
363 363
 
364 364
 		// Add locales.
365
-		if ( ! empty( $request['postcode'] ) ) {
366
-			\WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request['postcode'] ) );
365
+		if ( ! empty($request['postcode'])) {
366
+			\WC_Tax::_update_tax_rate_postcodes($id, wc_clean($request['postcode']));
367 367
 		}
368
-		if ( ! empty( $request['city'] ) ) {
369
-			\WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request['city'] ) );
368
+		if ( ! empty($request['city'])) {
369
+			\WC_Tax::_update_tax_rate_cities($id, wc_clean($request['city']));
370 370
 		}
371 371
 
372
-		return \WC_Tax::_get_tax_rate( $id, OBJECT );
372
+		return \WC_Tax::_get_tax_rate($id, OBJECT);
373 373
 	}
374 374
 
375 375
 	/**
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
 	 * @param \WP_REST_Request $request Full details about the request.
379 379
 	 * @return \WP_Error\WP_REST_Response
380 380
 	 */
381
-	public function create_item( $request ) {
382
-		if ( ! empty( $request['id'] ) ) {
383
-			return new \WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) );
381
+	public function create_item($request) {
382
+		if ( ! empty($request['id'])) {
383
+			return new \WP_Error('woocommerce_rest_tax_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400));
384 384
 		}
385 385
 
386
-		$tax = $this->create_or_update_tax( $request );
386
+		$tax = $this->create_or_update_tax($request);
387 387
 
388
-		$this->update_additional_fields_for_object( $tax, $request );
388
+		$this->update_additional_fields_for_object($tax, $request);
389 389
 
390 390
 		/**
391 391
 		 * Fires after a tax is created or updated via the REST API.
@@ -394,13 +394,13 @@  discard block
 block discarded – undo
394 394
 		 * @param \WP_REST_Request $request   Request object.
395 395
 		 * @param boolean         $creating  True when creating tax, false when updating tax.
396 396
 		 */
397
-		do_action( 'woocommerce_rest_insert_tax', $tax, $request, true );
397
+		do_action('woocommerce_rest_insert_tax', $tax, $request, true);
398 398
 
399
-		$request->set_param( 'context', 'edit' );
400
-		$response = $this->prepare_item_for_response( $tax, $request );
401
-		$response = rest_ensure_response( $response );
402
-		$response->set_status( 201 );
403
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ) );
399
+		$request->set_param('context', 'edit');
400
+		$response = $this->prepare_item_for_response($tax, $request);
401
+		$response = rest_ensure_response($response);
402
+		$response->set_status(201);
403
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id)));
404 404
 
405 405
 		return $response;
406 406
 	}
@@ -411,16 +411,16 @@  discard block
 block discarded – undo
411 411
 	 * @param \WP_REST_Request $request Full details about the request.
412 412
 	 * @return \WP_Error\WP_REST_Response
413 413
 	 */
414
-	public function get_item( $request ) {
414
+	public function get_item($request) {
415 415
 		$id      = (int) $request['id'];
416
-		$tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT );
416
+		$tax_obj = \WC_Tax::_get_tax_rate($id, OBJECT);
417 417
 
418
-		if ( empty( $id ) || empty( $tax_obj ) ) {
419
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
418
+		if (empty($id) || empty($tax_obj)) {
419
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
420 420
 		}
421 421
 
422
-		$tax      = $this->prepare_item_for_response( $tax_obj, $request );
423
-		$response = rest_ensure_response( $tax );
422
+		$tax      = $this->prepare_item_for_response($tax_obj, $request);
423
+		$response = rest_ensure_response($tax);
424 424
 
425 425
 		return $response;
426 426
 	}
@@ -431,17 +431,17 @@  discard block
 block discarded – undo
431 431
 	 * @param \WP_REST_Request $request Full details about the request.
432 432
 	 * @return \WP_Error\WP_REST_Response
433 433
 	 */
434
-	public function update_item( $request ) {
434
+	public function update_item($request) {
435 435
 		$id      = (int) $request['id'];
436
-		$tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT );
436
+		$tax_obj = \WC_Tax::_get_tax_rate($id, OBJECT);
437 437
 
438
-		if ( empty( $id ) || empty( $tax_obj ) ) {
439
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
438
+		if (empty($id) || empty($tax_obj)) {
439
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
440 440
 		}
441 441
 
442
-		$tax = $this->create_or_update_tax( $request, $tax_obj );
442
+		$tax = $this->create_or_update_tax($request, $tax_obj);
443 443
 
444
-		$this->update_additional_fields_for_object( $tax, $request );
444
+		$this->update_additional_fields_for_object($tax, $request);
445 445
 
446 446
 		/**
447 447
 		 * Fires after a tax is created or updated via the REST API.
@@ -450,11 +450,11 @@  discard block
 block discarded – undo
450 450
 		 * @param \WP_REST_Request $request   Request object.
451 451
 		 * @param boolean         $creating  True when creating tax, false when updating tax.
452 452
 		 */
453
-		do_action( 'woocommerce_rest_insert_tax', $tax, $request, false );
453
+		do_action('woocommerce_rest_insert_tax', $tax, $request, false);
454 454
 
455
-		$request->set_param( 'context', 'edit' );
456
-		$response = $this->prepare_item_for_response( $tax, $request );
457
-		$response = rest_ensure_response( $response );
455
+		$request->set_param('context', 'edit');
456
+		$response = $this->prepare_item_for_response($tax, $request);
457
+		$response = rest_ensure_response($response);
458 458
 
459 459
 		return $response;
460 460
 	}
@@ -465,30 +465,30 @@  discard block
 block discarded – undo
465 465
 	 * @param \WP_REST_Request $request Full details about the request.
466 466
 	 * @return \WP_Error\WP_REST_Response
467 467
 	 */
468
-	public function delete_item( $request ) {
468
+	public function delete_item($request) {
469 469
 		global $wpdb;
470 470
 
471 471
 		$id    = (int) $request['id'];
472
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
472
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
473 473
 
474 474
 		// We don't support trashing for this type, error out.
475
-		if ( ! $force ) {
476
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
475
+		if ( ! $force) {
476
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501));
477 477
 		}
478 478
 
479
-		$tax = \WC_Tax::_get_tax_rate( $id, OBJECT );
479
+		$tax = \WC_Tax::_get_tax_rate($id, OBJECT);
480 480
 
481
-		if ( empty( $id ) || empty( $tax ) ) {
482
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 400 ) );
481
+		if (empty($id) || empty($tax)) {
482
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 400));
483 483
 		}
484 484
 
485
-		$request->set_param( 'context', 'edit' );
486
-		$response = $this->prepare_item_for_response( $tax, $request );
485
+		$request->set_param('context', 'edit');
486
+		$response = $this->prepare_item_for_response($tax, $request);
487 487
 
488
-		\WC_Tax::_delete_tax_rate( $id );
488
+		\WC_Tax::_delete_tax_rate($id);
489 489
 
490
-		if ( 0 === $wpdb->rows_affected ) {
491
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
490
+		if (0 === $wpdb->rows_affected) {
491
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
492 492
 		}
493 493
 
494 494
 		/**
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
 		 * @param \WP_REST_Response $response The response returned from the API.
499 499
 		 * @param \WP_REST_Request  $request  The request sent to the API.
500 500
 		 */
501
-		do_action( 'woocommerce_rest_delete_tax', $tax, $response, $request );
501
+		do_action('woocommerce_rest_delete_tax', $tax, $response, $request);
502 502
 
503 503
 		return $response;
504 504
 	}
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 * @param \WP_REST_Request $request Request object.
511 511
 	 * @return \WP_REST_Response $response Response data.
512 512
 	 */
513
-	public function prepare_item_for_response( $tax, $request ) {
513
+	public function prepare_item_for_response($tax, $request) {
514 514
 		global $wpdb;
515 515
 
516 516
 		$id   = (int) $tax->tax_rate_id;
@@ -541,20 +541,20 @@  discard block
 block discarded – undo
541 541
 			)
542 542
 		);
543 543
 
544
-		if ( ! is_wp_error( $tax ) && ! is_null( $tax ) ) {
545
-			foreach ( $locales as $locale ) {
546
-				$data[ $locale->location_type ] = $locale->location_code;
544
+		if ( ! is_wp_error($tax) && ! is_null($tax)) {
545
+			foreach ($locales as $locale) {
546
+				$data[$locale->location_type] = $locale->location_code;
547 547
 			}
548 548
 		}
549 549
 
550
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
551
-		$data    = $this->add_additional_fields_to_object( $data, $request );
552
-		$data    = $this->filter_response_by_context( $data, $context );
550
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
551
+		$data    = $this->add_additional_fields_to_object($data, $request);
552
+		$data    = $this->filter_response_by_context($data, $context);
553 553
 
554 554
 		// Wrap the data in a response object.
555
-		$response = rest_ensure_response( $data );
555
+		$response = rest_ensure_response($data);
556 556
 
557
-		$response->add_links( $this->prepare_links( $tax ) );
557
+		$response->add_links($this->prepare_links($tax));
558 558
 
559 559
 		/**
560 560
 		 * Filter tax object returned from the REST API.
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 		 * @param stdClass         $tax      Tax object used to create response.
564 564
 		 * @param \WP_REST_Request  $request  Request object.
565 565
 		 */
566
-		return apply_filters( 'woocommerce_rest_prepare_tax', $response, $tax, $request );
566
+		return apply_filters('woocommerce_rest_prepare_tax', $response, $tax, $request);
567 567
 	}
568 568
 
569 569
 	/**
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
 	 * @param stdClass $tax Tax object.
573 573
 	 * @return array Links for the given tax.
574 574
 	 */
575
-	protected function prepare_links( $tax ) {
575
+	protected function prepare_links($tax) {
576 576
 		$links = array(
577 577
 			'self' => array(
578
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ),
578
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id)),
579 579
 			),
580 580
 			'collection' => array(
581
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
581
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
582 582
 			),
583 583
 		);
584 584
 
@@ -597,75 +597,75 @@  discard block
 block discarded – undo
597 597
 			'type'       => 'object',
598 598
 			'properties' => array(
599 599
 				'id' => array(
600
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
600
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
601 601
 					'type'        => 'integer',
602
-					'context'     => array( 'view', 'edit' ),
602
+					'context'     => array('view', 'edit'),
603 603
 					'readonly'    => true,
604 604
 				),
605 605
 				'country' => array(
606
-					'description' => __( 'Country ISO 3166 code.', 'woocommerce' ),
606
+					'description' => __('Country ISO 3166 code.', 'woocommerce'),
607 607
 					'type'        => 'string',
608
-					'context'     => array( 'view', 'edit' ),
608
+					'context'     => array('view', 'edit'),
609 609
 				),
610 610
 				'state' => array(
611
-					'description' => __( 'State code.', 'woocommerce' ),
611
+					'description' => __('State code.', 'woocommerce'),
612 612
 					'type'        => 'string',
613
-					'context'     => array( 'view', 'edit' ),
613
+					'context'     => array('view', 'edit'),
614 614
 				),
615 615
 				'postcode' => array(
616
-					'description' => __( 'Postcode / ZIP.', 'woocommerce' ),
616
+					'description' => __('Postcode / ZIP.', 'woocommerce'),
617 617
 					'type'        => 'string',
618
-					'context'     => array( 'view', 'edit' ),
618
+					'context'     => array('view', 'edit'),
619 619
 				),
620 620
 				'city' => array(
621
-					'description' => __( 'City name.', 'woocommerce' ),
621
+					'description' => __('City name.', 'woocommerce'),
622 622
 					'type'        => 'string',
623
-					'context'     => array( 'view', 'edit' ),
623
+					'context'     => array('view', 'edit'),
624 624
 				),
625 625
 				'rate' => array(
626
-					'description' => __( 'Tax rate.', 'woocommerce' ),
626
+					'description' => __('Tax rate.', 'woocommerce'),
627 627
 					'type'        => 'string',
628
-					'context'     => array( 'view', 'edit' ),
628
+					'context'     => array('view', 'edit'),
629 629
 				),
630 630
 				'name' => array(
631
-					'description' => __( 'Tax rate name.', 'woocommerce' ),
631
+					'description' => __('Tax rate name.', 'woocommerce'),
632 632
 					'type'        => 'string',
633
-					'context'     => array( 'view', 'edit' ),
633
+					'context'     => array('view', 'edit'),
634 634
 				),
635 635
 				'priority' => array(
636
-					'description' => __( 'Tax priority.', 'woocommerce' ),
636
+					'description' => __('Tax priority.', 'woocommerce'),
637 637
 					'type'        => 'integer',
638 638
 					'default'     => 1,
639
-					'context'     => array( 'view', 'edit' ),
639
+					'context'     => array('view', 'edit'),
640 640
 				),
641 641
 				'compound' => array(
642
-					'description' => __( 'Whether or not this is a compound rate.', 'woocommerce' ),
642
+					'description' => __('Whether or not this is a compound rate.', 'woocommerce'),
643 643
 					'type'        => 'boolean',
644 644
 					'default'     => false,
645
-					'context'     => array( 'view', 'edit' ),
645
+					'context'     => array('view', 'edit'),
646 646
 				),
647 647
 				'shipping' => array(
648
-					'description' => __( 'Whether or not this tax rate also gets applied to shipping.', 'woocommerce' ),
648
+					'description' => __('Whether or not this tax rate also gets applied to shipping.', 'woocommerce'),
649 649
 					'type'        => 'boolean',
650 650
 					'default'     => true,
651
-					'context'     => array( 'view', 'edit' ),
651
+					'context'     => array('view', 'edit'),
652 652
 				),
653 653
 				'order' => array(
654
-					'description' => __( 'Indicates the order that will appear in queries.', 'woocommerce' ),
654
+					'description' => __('Indicates the order that will appear in queries.', 'woocommerce'),
655 655
 					'type'        => 'integer',
656
-					'context'     => array( 'view', 'edit' ),
656
+					'context'     => array('view', 'edit'),
657 657
 				),
658 658
 				'class' => array(
659
-					'description' => __( 'Tax class.', 'woocommerce' ),
659
+					'description' => __('Tax class.', 'woocommerce'),
660 660
 					'type'        => 'string',
661 661
 					'default'     => 'standard',
662
-					'enum'        => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ),
663
-					'context'     => array( 'view', 'edit' ),
662
+					'enum'        => array_merge(array('standard'), \WC_Tax::get_tax_class_slugs()),
663
+					'context'     => array('view', 'edit'),
664 664
 				),
665 665
 			),
666 666
 		);
667 667
 
668
-		return $this->add_additional_fields_schema( $schema );
668
+		return $this->add_additional_fields_schema($schema);
669 669
 	}
670 670
 
671 671
 	/**
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
 		$params['context']['default'] = 'view';
680 680
 
681 681
 		$params['page'] = array(
682
-			'description'        => __( 'Current page of the collection.', 'woocommerce' ),
682
+			'description'        => __('Current page of the collection.', 'woocommerce'),
683 683
 			'type'               => 'integer',
684 684
 			'default'            => 1,
685 685
 			'sanitize_callback'  => 'absint',
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 			'minimum'            => 1,
688 688
 		);
689 689
 		$params['per_page'] = array(
690
-			'description'        => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
690
+			'description'        => __('Maximum number of items to be returned in result set.', 'woocommerce'),
691 691
 			'type'               => 'integer',
692 692
 			'default'            => 10,
693 693
 			'minimum'            => 1,
@@ -696,22 +696,22 @@  discard block
 block discarded – undo
696 696
 			'validate_callback'  => 'rest_validate_request_arg',
697 697
 		);
698 698
 		$params['offset'] = array(
699
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
699
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
700 700
 			'type'               => 'integer',
701 701
 			'sanitize_callback'  => 'absint',
702 702
 			'validate_callback'  => 'rest_validate_request_arg',
703 703
 		);
704 704
 		$params['order'] = array(
705 705
 			'default'            => 'asc',
706
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
707
-			'enum'               => array( 'asc', 'desc' ),
706
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
707
+			'enum'               => array('asc', 'desc'),
708 708
 			'sanitize_callback'  => 'sanitize_key',
709 709
 			'type'               => 'string',
710 710
 			'validate_callback'  => 'rest_validate_request_arg',
711 711
 		);
712 712
 		$params['orderby'] = array(
713 713
 			'default'            => 'order',
714
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
714
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
715 715
 			'enum'               => array(
716 716
 				'id',
717 717
 				'order',
@@ -721,19 +721,19 @@  discard block
 block discarded – undo
721 721
 			'validate_callback'  => 'rest_validate_request_arg',
722 722
 		);
723 723
 		$params['class'] = array(
724
-			'description'        => __( 'Sort by tax class.', 'woocommerce' ),
725
-			'enum'               => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ),
724
+			'description'        => __('Sort by tax class.', 'woocommerce'),
725
+			'enum'               => array_merge(array('standard'), \WC_Tax::get_tax_class_slugs()),
726 726
 			'sanitize_callback'  => 'sanitize_title',
727 727
 			'type'               => 'string',
728 728
 			'validate_callback'  => 'rest_validate_request_arg',
729 729
 		);
730
-		$params['code']    = array(
731
-			'description'       => __( 'Search by similar tax code.', 'woocommerce' ),
730
+		$params['code'] = array(
731
+			'description'       => __('Search by similar tax code.', 'woocommerce'),
732 732
 			'type'              => 'string',
733 733
 			'validate_callback' => 'rest_validate_request_arg',
734 734
 		);
735 735
 		$params['include'] = array(
736
-			'description'       => __( 'Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce' ),
736
+			'description'       => __('Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce'),
737 737
 			'type'              => 'array',
738 738
 			'items'             => array(
739 739
 				'type' => 'integer',
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/ProductTags.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Product Tags controller class.
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 * @param \WP_REST_Request $request Request params.
38 38
 	 * @return \WP_REST_Response $response
39 39
 	 */
40
-	public function prepare_item_for_response( $item, $request ) {
40
+	public function prepare_item_for_response($item, $request) {
41 41
 		$data = array(
42 42
 			'id'          => (int) $item->term_id,
43 43
 			'name'        => $item->name,
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 			'count'       => (int) $item->count,
47 47
 		);
48 48
 
49
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
50
-		$data    = $this->add_additional_fields_to_object( $data, $request );
51
-		$data    = $this->filter_response_by_context( $data, $context );
49
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
50
+		$data    = $this->add_additional_fields_to_object($data, $request);
51
+		$data    = $this->filter_response_by_context($data, $context);
52 52
 
53
-		$response = rest_ensure_response( $data );
53
+		$response = rest_ensure_response($data);
54 54
 
55
-		$response->add_links( $this->prepare_links( $item, $request ) );
55
+		$response->add_links($this->prepare_links($item, $request));
56 56
 
57 57
 		/**
58 58
 		 * Filter a term item returned from the API.
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 		 * @param object            $item      The original term object.
64 64
 		 * @param \WP_REST_Request   $request   Request used to generate the response.
65 65
 		 */
66
-		return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request );
66
+		return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
67 67
 	}
68 68
 
69 69
 	/**
@@ -78,44 +78,44 @@  discard block
 block discarded – undo
78 78
 			'type'                 => 'object',
79 79
 			'properties'           => 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
-					'context'     => array( 'view', 'edit' ),
83
+					'context'     => array('view', 'edit'),
84 84
 					'readonly'    => true,
85 85
 				),
86 86
 				'name' => array(
87
-					'description' => __( 'Tag name.', 'woocommerce' ),
87
+					'description' => __('Tag name.', 'woocommerce'),
88 88
 					'type'        => 'string',
89
-					'context'     => array( 'view', 'edit' ),
89
+					'context'     => array('view', 'edit'),
90 90
 					'arg_options' => array(
91 91
 						'sanitize_callback' => 'sanitize_text_field',
92 92
 					),
93 93
 				),
94 94
 				'slug' => array(
95
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
95
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
96 96
 					'type'        => 'string',
97
-					'context'     => array( 'view', 'edit' ),
97
+					'context'     => array('view', 'edit'),
98 98
 					'arg_options' => array(
99 99
 						'sanitize_callback' => 'sanitize_title',
100 100
 					),
101 101
 				),
102 102
 				'description' => array(
103
-					'description' => __( 'HTML description of the resource.', 'woocommerce' ),
103
+					'description' => __('HTML description of the resource.', 'woocommerce'),
104 104
 					'type'        => 'string',
105
-					'context'     => array( 'view', 'edit' ),
105
+					'context'     => array('view', 'edit'),
106 106
 					'arg_options' => array(
107 107
 						'sanitize_callback' => 'wp_filter_post_kses',
108 108
 					),
109 109
 				),
110 110
 				'count' => array(
111
-					'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
111
+					'description' => __('Number of published products for the resource.', 'woocommerce'),
112 112
 					'type'        => 'integer',
113
-					'context'     => array( 'view', 'edit' ),
113
+					'context'     => array('view', 'edit'),
114 114
 					'readonly'    => true,
115 115
 				),
116 116
 			),
117 117
 		);
118 118
 
119
-		return $this->add_additional_fields_schema( $schema );
119
+		return $this->add_additional_fields_schema($schema);
120 120
 	}
121 121
 }
Please login to merge, or discard this patch.
src/Utilities/SingletonTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 	 * @return object Instance.
34 34
 	 */
35 35
 	final public static function instance() {
36
-		if ( null === static::$instance ) {
36
+		if (null === static::$instance) {
37 37
 			static::$instance = new static();
38 38
 		}
39 39
 		return static::$instance;
Please login to merge, or discard this patch.
src/RestApi.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -7,9 +7,9 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12
-if ( file_exists( __DIR__ . '/../vendor/autoload.php' ) ) {
12
+if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
13 13
 	require __DIR__ . '/../vendor/autoload.php';
14 14
 } else {
15 15
 	return;
@@ -34,19 +34,19 @@  discard block
 block discarded – undo
34 34
 	 * Hook into WordPress ready to init the REST API as needed.
35 35
 	 */
36 36
 	public function init() {
37
-		add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 );
37
+		add_action('rest_api_init', array($this, 'register_rest_routes'), 10);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register REST API routes.
42 42
 	 */
43 43
 	public function register_rest_routes() {
44
-		foreach ( $this->get_rest_namespaces() as $namespace => $namespace_class ) {
44
+		foreach ($this->get_rest_namespaces() as $namespace => $namespace_class) {
45 45
 			$controllers = $namespace_class::get_controllers();
46 46
 
47
-			foreach ( $controllers as $controller_name => $controller_class ) {
48
-				$this->endpoints[ $namespace ][ $controller_name ] = new $controller_class();
49
-				$this->endpoints[ $namespace ][ $controller_name ]->register_routes();
47
+			foreach ($controllers as $controller_name => $controller_class) {
48
+				$this->endpoints[$namespace][$controller_name] = new $controller_class();
49
+				$this->endpoints[$namespace][$controller_name]->register_routes();
50 50
 			}
51 51
 		}
52 52
 	}
@@ -73,17 +73,17 @@  discard block
 block discarded – undo
73 73
 	 * @param array  $params Params to passwith request.
74 74
 	 * @return array|WP_Error
75 75
 	 */
76
-	public function get_endpoint_data( $endpoint, $params = array() ) {
77
-		$request = new \WP_REST_Request( 'GET', $endpoint );
76
+	public function get_endpoint_data($endpoint, $params = array()) {
77
+		$request = new \WP_REST_Request('GET', $endpoint);
78 78
 
79
-		if ( $params ) {
80
-			$request->set_query_params( $params );
79
+		if ($params) {
80
+			$request->set_query_params($params);
81 81
 		}
82 82
 
83
-		$response = \rest_do_request( $request );
83
+		$response = \rest_do_request($request);
84 84
 		$server   = \rest_get_server();
85
-		$json     = wp_json_encode( $server->response_to_data( $response, false ) );
85
+		$json     = wp_json_encode($server->response_to_data($response, false));
86 86
 
87
-		return json_decode( $json, true );
87
+		return json_decode($json, true);
88 88
 	}
89 89
 }
Please login to merge, or discard this patch.
src/RestApi/Blocks/Version1/class-wc-rest-blocks-controllers.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
  * @package WooCommerce/RestApi
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Controllers class.
Please login to merge, or discard this patch.