Completed
Push — master ( ee9494...a1e9b4 )
by Mike
45:32
created
src/Controllers/Version4/Data.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Coupons controller class.
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 			array(
36 36
 				array(
37 37
 					'methods'             => \WP_REST_Server::READABLE,
38
-					'callback'            => array( $this, 'get_items' ),
39
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
38
+					'callback'            => array($this, 'get_items'),
39
+					'permission_callback' => array($this, 'get_items_permissions_check'),
40 40
 				),
41
-				'schema' => array( $this, 'get_public_item_schema' ),
41
+				'schema' => array($this, 'get_public_item_schema'),
42 42
 			),
43 43
 			true
44 44
 		);
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 	 * @param  \WP_REST_Request $request Full details about the request.
51 51
 	 * @return \WP_Error|boolean
52 52
 	 */
53
-	public function get_items_permissions_check( $request ) {
54
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
55
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
53
+	public function get_items_permissions_check($request) {
54
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
55
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
56 56
 		}
57 57
 
58 58
 		return true;
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 * @param  \WP_REST_Request $request Full details about the request.
65 65
 	 * @return \WP_Error|boolean
66 66
 	 */
67
-	public function get_item_permissions_check( $request ) {
68
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
69
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
67
+	public function get_item_permissions_check($request) {
68
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
69
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
70 70
 		}
71 71
 
72 72
 		return true;
@@ -79,33 +79,33 @@  discard block
 block discarded – undo
79 79
 	 * @param  \WP_REST_Request $request Request data.
80 80
 	 * @return \WP_Error\WP_REST_Response
81 81
 	 */
82
-	public function get_items( $request ) {
82
+	public function get_items($request) {
83 83
 		$data      = array();
84 84
 		$resources = array(
85 85
 			array(
86 86
 				'slug'        => 'continents',
87
-				'description' => __( 'List of supported continents, countries, and states.', 'woocommerce' ),
87
+				'description' => __('List of supported continents, countries, and states.', 'woocommerce'),
88 88
 			),
89 89
 			array(
90 90
 				'slug'        => 'countries',
91
-				'description' => __( 'List of supported states in a given country.', 'woocommerce' ),
91
+				'description' => __('List of supported states in a given country.', 'woocommerce'),
92 92
 			),
93 93
 			array(
94 94
 				'slug'        => 'currencies',
95
-				'description' => __( 'List of supported currencies.', 'woocommerce' ),
95
+				'description' => __('List of supported currencies.', 'woocommerce'),
96 96
 			),
97 97
 			array(
98 98
 				'slug'        => 'download-ips',
99
-				'description' => __( 'An endpoint used for searching download logs for a specific IP address.', 'woocommerce' ),
99
+				'description' => __('An endpoint used for searching download logs for a specific IP address.', 'woocommerce'),
100 100
 			),
101 101
 		);
102 102
 
103
-		foreach ( $resources as $resource ) {
104
-			$item   = $this->prepare_item_for_response( (object) $resource, $request );
105
-			$data[] = $this->prepare_response_for_collection( $item );
103
+		foreach ($resources as $resource) {
104
+			$item   = $this->prepare_item_for_response((object) $resource, $request);
105
+			$data[] = $this->prepare_response_for_collection($item);
106 106
 		}
107 107
 
108
-		return rest_ensure_response( $data );
108
+		return rest_ensure_response($data);
109 109
 	}
110 110
 
111 111
 	/**
@@ -115,18 +115,18 @@  discard block
 block discarded – undo
115 115
 	 * @param \WP_REST_Request $request  Request object.
116 116
 	 * @return \WP_REST_Response $response Response data.
117 117
 	 */
118
-	public function prepare_item_for_response( $resource, $request ) {
118
+	public function prepare_item_for_response($resource, $request) {
119 119
 		$data = array(
120 120
 			'slug'        => $resource->slug,
121 121
 			'description' => $resource->description,
122 122
 		);
123 123
 
124
-		$data = $this->add_additional_fields_to_object( $data, $request );
125
-		$data = $this->filter_response_by_context( $data, 'view' );
124
+		$data = $this->add_additional_fields_to_object($data, $request);
125
+		$data = $this->filter_response_by_context($data, 'view');
126 126
 
127 127
 		// Wrap the data in a response object.
128
-		$response = rest_ensure_response( $data );
129
-		$response->add_links( $this->prepare_links( $resource ) );
128
+		$response = rest_ensure_response($data);
129
+		$response->add_links($this->prepare_links($resource));
130 130
 
131 131
 		return $response;
132 132
 	}
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
 	 * @param object $item Data object.
138 138
 	 * @return array Links for the given country.
139 139
 	 */
140
-	protected function prepare_links( $item ) {
140
+	protected function prepare_links($item) {
141 141
 		$links = array(
142 142
 			'self'       => array(
143
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug ) ),
143
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug)),
144 144
 			),
145 145
 			'collection' => array(
146
-				'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
146
+				'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)),
147 147
 			),
148 148
 		);
149 149
 
@@ -163,20 +163,20 @@  discard block
 block discarded – undo
163 163
 			'type'       => 'object',
164 164
 			'properties' => array(
165 165
 				'slug'        => array(
166
-					'description' => __( 'Data resource ID.', 'woocommerce' ),
166
+					'description' => __('Data resource ID.', 'woocommerce'),
167 167
 					'type'        => 'string',
168
-					'context'     => array( 'view' ),
168
+					'context'     => array('view'),
169 169
 					'readonly'    => true,
170 170
 				),
171 171
 				'description' => array(
172
-					'description' => __( 'Data resource description.', 'woocommerce' ),
172
+					'description' => __('Data resource description.', 'woocommerce'),
173 173
 					'type'        => 'string',
174
-					'context'     => array( 'view' ),
174
+					'context'     => array('view'),
175 175
 					'readonly'    => true,
176 176
 				),
177 177
 			),
178 178
 		);
179 179
 
180
-		return $this->add_additional_fields_schema( $schema );
180
+		return $this->add_additional_fields_schema($schema);
181 181
 	}
182 182
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/PaymentGateways.php 1 patch
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * Payment gateways 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,25 +47,25 @@  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 62
 				array(
63 63
 					'methods'             => \WP_REST_Server::EDITABLE,
64
-					'callback'            => array( $this, 'update_item' ),
65
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
66
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
64
+					'callback'            => array($this, 'update_item'),
65
+					'permission_callback' => array($this, 'update_items_permissions_check'),
66
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
67 67
 				),
68
-				'schema' => array( $this, 'get_public_item_schema' ),
68
+				'schema' => array($this, 'get_public_item_schema'),
69 69
 			),
70 70
 			true
71 71
 		);
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 	 * @param  \WP_REST_Request $request Full details about the request.
78 78
 	 * @return \WP_Error|boolean
79 79
 	 */
80
-	public function get_items_permissions_check( $request ) {
81
-		if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'read' ) ) {
82
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
80
+	public function get_items_permissions_check($request) {
81
+		if ( ! wc_rest_check_manager_permissions('payment_gateways', 'read')) {
82
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
83 83
 		}
84 84
 		return true;
85 85
 	}
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 	 * @param  \WP_REST_Request $request Full details about the request.
91 91
 	 * @return \WP_Error|boolean
92 92
 	 */
93
-	public function get_item_permissions_check( $request ) {
94
-		if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'read' ) ) {
95
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
93
+	public function get_item_permissions_check($request) {
94
+		if ( ! wc_rest_check_manager_permissions('payment_gateways', 'read')) {
95
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
96 96
 		}
97 97
 		return true;
98 98
 	}
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
 	 * @param  \WP_REST_Request $request Full details about the request.
104 104
 	 * @return \WP_Error|boolean
105 105
 	 */
106
-	public function update_items_permissions_check( $request ) {
107
-		if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'edit' ) ) {
108
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
106
+	public function update_items_permissions_check($request) {
107
+		if ( ! wc_rest_check_manager_permissions('payment_gateways', 'edit')) {
108
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
109 109
 		}
110 110
 		return true;
111 111
 	}
@@ -116,16 +116,16 @@  discard block
 block discarded – undo
116 116
 	 * @param \WP_REST_Request $request Full details about the request.
117 117
 	 * @return \WP_Error\WP_REST_Response
118 118
 	 */
119
-	public function get_items( $request ) {
119
+	public function get_items($request) {
120 120
 		$payment_gateways = WC()->payment_gateways->payment_gateways();
121 121
 		$response         = array();
122
-		foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) {
122
+		foreach ($payment_gateways as $payment_gateway_id => $payment_gateway) {
123 123
 			$payment_gateway->id = $payment_gateway_id;
124
-			$gateway             = $this->prepare_item_for_response( $payment_gateway, $request );
125
-			$gateway             = $this->prepare_response_for_collection( $gateway );
124
+			$gateway             = $this->prepare_item_for_response($payment_gateway, $request);
125
+			$gateway             = $this->prepare_response_for_collection($gateway);
126 126
 			$response[]          = $gateway;
127 127
 		}
128
-		return rest_ensure_response( $response );
128
+		return rest_ensure_response($response);
129 129
 	}
130 130
 
131 131
 	/**
@@ -134,15 +134,15 @@  discard block
 block discarded – undo
134 134
 	 * @param \WP_REST_Request $request Request data.
135 135
 	 * @return \WP_REST_Response|\WP_Error
136 136
 	 */
137
-	public function get_item( $request ) {
138
-		$gateway = $this->get_gateway( $request );
137
+	public function get_item($request) {
138
+		$gateway = $this->get_gateway($request);
139 139
 
140
-		if ( is_null( $gateway ) ) {
141
-			return new \WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
140
+		if (is_null($gateway)) {
141
+			return new \WP_Error('woocommerce_rest_payment_gateway_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
142 142
 		}
143 143
 
144
-		$gateway = $this->prepare_item_for_response( $gateway, $request );
145
-		return rest_ensure_response( $gateway );
144
+		$gateway = $this->prepare_item_for_response($gateway, $request);
145
+		return rest_ensure_response($gateway);
146 146
 	}
147 147
 
148 148
 	/**
@@ -151,11 +151,11 @@  discard block
 block discarded – undo
151 151
 	 * @param \WP_REST_Request $request Request data.
152 152
 	 * @return \WP_REST_Response|\WP_Error
153 153
 	 */
154
-	public function update_item( $request ) {
155
-		$gateway = $this->get_gateway( $request );
154
+	public function update_item($request) {
155
+		$gateway = $this->get_gateway($request);
156 156
 
157
-		if ( is_null( $gateway ) ) {
158
-			return new \WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
157
+		if (is_null($gateway)) {
158
+			return new \WP_Error('woocommerce_rest_payment_gateway_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
159 159
 		}
160 160
 
161 161
 		// Get settings.
@@ -163,60 +163,60 @@  discard block
 block discarded – undo
163 163
 		$settings = $gateway->settings;
164 164
 
165 165
 		// Update settings.
166
-		if ( isset( $request['settings'] ) ) {
166
+		if (isset($request['settings'])) {
167 167
 			$errors_found = false;
168
-			foreach ( $gateway->form_fields as $key => $field ) {
169
-				if ( isset( $request['settings'][ $key ] ) ) {
170
-					if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) {
171
-						$value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field );
168
+			foreach ($gateway->form_fields as $key => $field) {
169
+				if (isset($request['settings'][$key])) {
170
+					if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) {
171
+						$value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field);
172 172
 					} else {
173
-						$value = $this->validate_setting_text_field( $request['settings'][ $key ], $field );
173
+						$value = $this->validate_setting_text_field($request['settings'][$key], $field);
174 174
 					}
175
-					if ( is_wp_error( $value ) ) {
175
+					if (is_wp_error($value)) {
176 176
 						$errors_found = true;
177 177
 						break;
178 178
 					}
179
-					$settings[ $key ] = $value;
179
+					$settings[$key] = $value;
180 180
 				}
181 181
 			}
182 182
 
183
-			if ( $errors_found ) {
184
-				return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
183
+			if ($errors_found) {
184
+				return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
185 185
 			}
186 186
 		}
187 187
 
188 188
 		// Update if this method is enabled or not.
189
-		if ( isset( $request['enabled'] ) ) {
190
-			$settings['enabled'] = wc_bool_to_string( $request['enabled'] );
189
+		if (isset($request['enabled'])) {
190
+			$settings['enabled'] = wc_bool_to_string($request['enabled']);
191 191
 			$gateway->enabled    = $settings['enabled'];
192 192
 		}
193 193
 
194 194
 		// Update title.
195
-		if ( isset( $request['title'] ) ) {
195
+		if (isset($request['title'])) {
196 196
 			$settings['title'] = $request['title'];
197 197
 			$gateway->title    = $settings['title'];
198 198
 		}
199 199
 
200 200
 		// Update description.
201
-		if ( isset( $request['description'] ) ) {
201
+		if (isset($request['description'])) {
202 202
 			$settings['description'] = $request['description'];
203 203
 			$gateway->description    = $settings['description'];
204 204
 		}
205 205
 
206 206
 		// Update options.
207 207
 		$gateway->settings = $settings;
208
-		update_option( $gateway->get_option_key(), apply_filters( 'woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway ) );
208
+		update_option($gateway->get_option_key(), apply_filters('woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway));
209 209
 
210 210
 		// Update order.
211
-		if ( isset( $request['order'] ) ) {
212
-			$order                 = (array) get_option( 'woocommerce_gateway_order' );
213
-			$order[ $gateway->id ] = $request['order'];
214
-			update_option( 'woocommerce_gateway_order', $order );
215
-			$gateway->order = absint( $request['order'] );
211
+		if (isset($request['order'])) {
212
+			$order                 = (array) get_option('woocommerce_gateway_order');
213
+			$order[$gateway->id] = $request['order'];
214
+			update_option('woocommerce_gateway_order', $order);
215
+			$gateway->order = absint($request['order']);
216 216
 		}
217 217
 
218
-		$gateway = $this->prepare_item_for_response( $gateway, $request );
219
-		return rest_ensure_response( $gateway );
218
+		$gateway = $this->prepare_item_for_response($gateway, $request);
219
+		return rest_ensure_response($gateway);
220 220
 	}
221 221
 
222 222
 	/**
@@ -225,11 +225,11 @@  discard block
 block discarded – undo
225 225
 	 * @param \WP_REST_Request $request Request data.
226 226
 	 * @return \WP_REST_Response|null
227 227
 	 */
228
-	public function get_gateway( $request ) {
228
+	public function get_gateway($request) {
229 229
 		$gateway          = null;
230 230
 		$payment_gateways = WC()->payment_gateways->payment_gateways();
231
-		foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) {
232
-			if ( $request['id'] !== $payment_gateway_id ) {
231
+		foreach ($payment_gateways as $payment_gateway_id => $payment_gateway) {
232
+			if ($request['id'] !== $payment_gateway_id) {
233 233
 				continue;
234 234
 			}
235 235
 			$payment_gateway->id = $payment_gateway_id;
@@ -245,26 +245,26 @@  discard block
 block discarded – undo
245 245
 	 * @param  \WP_REST_Request    $request    Request object.
246 246
 	 * @return \WP_REST_Response   $response   Response data.
247 247
 	 */
248
-	public function prepare_item_for_response( $gateway, $request ) {
249
-		$order = (array) get_option( 'woocommerce_gateway_order' );
248
+	public function prepare_item_for_response($gateway, $request) {
249
+		$order = (array) get_option('woocommerce_gateway_order');
250 250
 		$item  = array(
251 251
 			'id'                 => $gateway->id,
252 252
 			'title'              => $gateway->title,
253 253
 			'description'        => $gateway->description,
254
-			'order'              => isset( $order[ $gateway->id ] ) ? $order[ $gateway->id ] : '',
255
-			'enabled'            => ( 'yes' === $gateway->enabled ),
254
+			'order'              => isset($order[$gateway->id]) ? $order[$gateway->id] : '',
255
+			'enabled'            => ('yes' === $gateway->enabled),
256 256
 			'method_title'       => $gateway->get_method_title(),
257 257
 			'method_description' => $gateway->get_method_description(),
258 258
 			'method_supports'    => $gateway->supports,
259
-			'settings'           => $this->get_settings( $gateway ),
259
+			'settings'           => $this->get_settings($gateway),
260 260
 		);
261 261
 
262
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
263
-		$data    = $this->add_additional_fields_to_object( $item, $request );
264
-		$data    = $this->filter_response_by_context( $data, $context );
262
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
263
+		$data    = $this->add_additional_fields_to_object($item, $request);
264
+		$data    = $this->filter_response_by_context($data, $context);
265 265
 
266
-		$response = rest_ensure_response( $data );
267
-		$response->add_links( $this->prepare_links( $gateway, $request ) );
266
+		$response = rest_ensure_response($data);
267
+		$response->add_links($this->prepare_links($gateway, $request));
268 268
 
269 269
 		/**
270 270
 		 * Filter payment gateway objects returned from the REST API.
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 		 * @param WC_Payment_Gateway $gateway  Payment gateway object.
274 274
 		 * @param \WP_REST_Request    $request  Request object.
275 275
 		 */
276
-		return apply_filters( 'woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request );
276
+		return apply_filters('woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request);
277 277
 	}
278 278
 
279 279
 	/**
@@ -283,34 +283,34 @@  discard block
 block discarded – undo
283 283
 	 *
284 284
 	 * @return array
285 285
 	 */
286
-	public function get_settings( $gateway ) {
286
+	public function get_settings($gateway) {
287 287
 		$settings = array();
288 288
 		$gateway->init_form_fields();
289
-		foreach ( $gateway->form_fields as $id => $field ) {
289
+		foreach ($gateway->form_fields as $id => $field) {
290 290
 			// Make sure we at least have a title and type.
291
-			if ( empty( $field['title'] ) || empty( $field['type'] ) ) {
291
+			if (empty($field['title']) || empty($field['type'])) {
292 292
 				continue;
293 293
 			}
294 294
 
295 295
 			// Ignore 'enabled' and 'description' which get included elsewhere.
296
-			if ( in_array( $id, array( 'enabled', 'description' ), true ) ) {
296
+			if (in_array($id, array('enabled', 'description'), true)) {
297 297
 				continue;
298 298
 			}
299 299
 
300 300
 			$data = array(
301 301
 				'id'          => $id,
302
-				'label'       => empty( $field['label'] ) ? $field['title'] : $field['label'],
303
-				'description' => empty( $field['description'] ) ? '' : $field['description'],
302
+				'label'       => empty($field['label']) ? $field['title'] : $field['label'],
303
+				'description' => empty($field['description']) ? '' : $field['description'],
304 304
 				'type'        => $field['type'],
305
-				'value'       => empty( $gateway->settings[ $id ] ) ? '' : $gateway->settings[ $id ],
306
-				'default'     => empty( $field['default'] ) ? '' : $field['default'],
307
-				'tip'         => empty( $field['description'] ) ? '' : $field['description'],
308
-				'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'],
305
+				'value'       => empty($gateway->settings[$id]) ? '' : $gateway->settings[$id],
306
+				'default'     => empty($field['default']) ? '' : $field['default'],
307
+				'tip'         => empty($field['description']) ? '' : $field['description'],
308
+				'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'],
309 309
 			);
310
-			if ( ! empty( $field['options'] ) ) {
310
+			if ( ! empty($field['options'])) {
311 311
 				$data['options'] = $field['options'];
312 312
 			}
313
-			$settings[ $id ] = $data;
313
+			$settings[$id] = $data;
314 314
 		}
315 315
 		return $settings;
316 316
 	}
@@ -322,13 +322,13 @@  discard block
 block discarded – undo
322 322
 	 * @param  \WP_REST_Request    $request    Request object.
323 323
 	 * @return array
324 324
 	 */
325
-	protected function prepare_links( $gateway, $request ) {
325
+	protected function prepare_links($gateway, $request) {
326 326
 		$links = array(
327 327
 			'self'       => array(
328
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $gateway->id ) ),
328
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $gateway->id)),
329 329
 			),
330 330
 			'collection' => array(
331
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
331
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
332 332
 			),
333 333
 		);
334 334
 
@@ -347,106 +347,106 @@  discard block
 block discarded – undo
347 347
 			'type'       => 'object',
348 348
 			'properties' => array(
349 349
 				'id'                 => array(
350
-					'description' => __( 'Payment gateway ID.', 'woocommerce' ),
350
+					'description' => __('Payment gateway ID.', 'woocommerce'),
351 351
 					'type'        => 'string',
352
-					'context'     => array( 'view', 'edit' ),
352
+					'context'     => array('view', 'edit'),
353 353
 					'readonly'    => true,
354 354
 				),
355 355
 				'title'              => array(
356
-					'description' => __( 'Payment gateway title on checkout.', 'woocommerce' ),
356
+					'description' => __('Payment gateway title on checkout.', 'woocommerce'),
357 357
 					'type'        => 'string',
358
-					'context'     => array( 'view', 'edit' ),
358
+					'context'     => array('view', 'edit'),
359 359
 				),
360 360
 				'description'        => array(
361
-					'description' => __( 'Payment gateway description on checkout.', 'woocommerce' ),
361
+					'description' => __('Payment gateway description on checkout.', 'woocommerce'),
362 362
 					'type'        => 'string',
363
-					'context'     => array( 'view', 'edit' ),
363
+					'context'     => array('view', 'edit'),
364 364
 				),
365 365
 				'order'              => array(
366
-					'description' => __( 'Payment gateway sort order.', 'woocommerce' ),
366
+					'description' => __('Payment gateway sort order.', 'woocommerce'),
367 367
 					'type'        => 'integer',
368
-					'context'     => array( 'view', 'edit' ),
368
+					'context'     => array('view', 'edit'),
369 369
 					'arg_options' => array(
370 370
 						'sanitize_callback' => 'absint',
371 371
 					),
372 372
 				),
373 373
 				'enabled'            => array(
374
-					'description' => __( 'Payment gateway enabled status.', 'woocommerce' ),
374
+					'description' => __('Payment gateway enabled status.', 'woocommerce'),
375 375
 					'type'        => 'boolean',
376
-					'context'     => array( 'view', 'edit' ),
376
+					'context'     => array('view', 'edit'),
377 377
 				),
378 378
 				'method_title'       => array(
379
-					'description' => __( 'Payment gateway method title.', 'woocommerce' ),
379
+					'description' => __('Payment gateway method title.', 'woocommerce'),
380 380
 					'type'        => 'string',
381
-					'context'     => array( 'view', 'edit' ),
381
+					'context'     => array('view', 'edit'),
382 382
 					'readonly'    => true,
383 383
 				),
384 384
 				'method_description' => array(
385
-					'description' => __( 'Payment gateway method description.', 'woocommerce' ),
385
+					'description' => __('Payment gateway method description.', 'woocommerce'),
386 386
 					'type'        => 'string',
387
-					'context'     => array( 'view', 'edit' ),
387
+					'context'     => array('view', 'edit'),
388 388
 					'readonly'    => true,
389 389
 				),
390 390
 				'method_supports'    => array(
391
-					'description' => __( 'Supported features for this payment gateway.', 'woocommerce' ),
391
+					'description' => __('Supported features for this payment gateway.', 'woocommerce'),
392 392
 					'type'        => 'array',
393
-					'context'     => array( 'view', 'edit' ),
393
+					'context'     => array('view', 'edit'),
394 394
 					'readonly'    => true,
395 395
 					'items'       => array(
396 396
 						'type' => 'string',
397 397
 					),
398 398
 				),
399 399
 				'settings'           => array(
400
-					'description' => __( 'Payment gateway settings.', 'woocommerce' ),
400
+					'description' => __('Payment gateway settings.', 'woocommerce'),
401 401
 					'type'        => 'object',
402
-					'context'     => array( 'view', 'edit' ),
402
+					'context'     => array('view', 'edit'),
403 403
 					'properties'  => array(
404 404
 						'id'          => array(
405
-							'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
405
+							'description' => __('A unique identifier for the setting.', 'woocommerce'),
406 406
 							'type'        => 'string',
407
-							'context'     => array( 'view', 'edit' ),
407
+							'context'     => array('view', 'edit'),
408 408
 							'readonly'    => true,
409 409
 						),
410 410
 						'label'       => array(
411
-							'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
411
+							'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'),
412 412
 							'type'        => 'string',
413
-							'context'     => array( 'view', 'edit' ),
413
+							'context'     => array('view', 'edit'),
414 414
 							'readonly'    => true,
415 415
 						),
416 416
 						'description' => array(
417
-							'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
417
+							'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'),
418 418
 							'type'        => 'string',
419
-							'context'     => array( 'view', 'edit' ),
419
+							'context'     => array('view', 'edit'),
420 420
 							'readonly'    => true,
421 421
 						),
422 422
 						'type'        => array(
423
-							'description' => __( 'Type of setting.', 'woocommerce' ),
423
+							'description' => __('Type of setting.', 'woocommerce'),
424 424
 							'type'        => 'string',
425
-							'context'     => array( 'view', 'edit' ),
426
-							'enum'        => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
425
+							'context'     => array('view', 'edit'),
426
+							'enum'        => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'),
427 427
 							'readonly'    => true,
428 428
 						),
429 429
 						'value'       => array(
430
-							'description' => __( 'Setting value.', 'woocommerce' ),
430
+							'description' => __('Setting value.', 'woocommerce'),
431 431
 							'type'        => 'string',
432
-							'context'     => array( 'view', 'edit' ),
432
+							'context'     => array('view', 'edit'),
433 433
 						),
434 434
 						'default'     => array(
435
-							'description' => __( 'Default value for the setting.', 'woocommerce' ),
435
+							'description' => __('Default value for the setting.', 'woocommerce'),
436 436
 							'type'        => 'string',
437
-							'context'     => array( 'view', 'edit' ),
437
+							'context'     => array('view', 'edit'),
438 438
 							'readonly'    => true,
439 439
 						),
440 440
 						'tip'         => array(
441
-							'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
441
+							'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'),
442 442
 							'type'        => 'string',
443
-							'context'     => array( 'view', 'edit' ),
443
+							'context'     => array('view', 'edit'),
444 444
 							'readonly'    => true,
445 445
 						),
446 446
 						'placeholder' => array(
447
-							'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
447
+							'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'),
448 448
 							'type'        => 'string',
449
-							'context'     => array( 'view', 'edit' ),
449
+							'context'     => array('view', 'edit'),
450 450
 							'readonly'    => true,
451 451
 						),
452 452
 					),
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 			),
455 455
 		);
456 456
 
457
-		return $this->add_additional_fields_schema( $schema );
457
+		return $this->add_additional_fields_schema($schema);
458 458
 	}
459 459
 
460 460
 	/**
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 	 */
465 465
 	public function get_collection_params() {
466 466
 		return array(
467
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
467
+			'context' => $this->get_context_param(array('default' => 'view')),
468 468
 		);
469 469
 	}
470 470
 
Please login to merge, or discard this patch.
src/Controllers/Version4/ProductVariations.php 1 patch
Spacing   +358 added lines, -358 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API variations controller class.
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 * Initialize product actions (parent).
35 35
 	 */
36 36
 	public function __construct() {
37
-		add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'add_product_id' ), 9, 2 );
37
+		add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'add_product_id'), 9, 2);
38 38
 		parent::__construct();
39 39
 	}
40 40
 
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
 			array(
49 49
 				'args'   => array(
50 50
 					'product_id' => array(
51
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
51
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
52 52
 						'type'        => 'integer',
53 53
 					),
54 54
 				),
55 55
 				array(
56 56
 					'methods'             => \WP_REST_Server::READABLE,
57
-					'callback'            => array( $this, 'get_items' ),
58
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
57
+					'callback'            => array($this, 'get_items'),
58
+					'permission_callback' => array($this, 'get_items_permissions_check'),
59 59
 					'args'                => $this->get_collection_params(),
60 60
 				),
61 61
 				array(
62 62
 					'methods'             => \WP_REST_Server::CREATABLE,
63
-					'callback'            => array( $this, 'create_item' ),
64
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
65
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
63
+					'callback'            => array($this, 'create_item'),
64
+					'permission_callback' => array($this, 'create_item_permissions_check'),
65
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
66 66
 				),
67
-				'schema' => array( $this, 'get_public_item_schema' ),
67
+				'schema' => array($this, 'get_public_item_schema'),
68 68
 			),
69 69
 			true
70 70
 		);
@@ -74,18 +74,18 @@  discard block
 block discarded – undo
74 74
 			array(
75 75
 				'args'   => array(
76 76
 					'product_id' => array(
77
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
77
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
78 78
 						'type'        => 'integer',
79 79
 					),
80 80
 					'id'         => array(
81
-						'description' => __( 'Unique identifier for the variation.', 'woocommerce' ),
81
+						'description' => __('Unique identifier for the variation.', 'woocommerce'),
82 82
 						'type'        => 'integer',
83 83
 					),
84 84
 				),
85 85
 				array(
86 86
 					'methods'             => \WP_REST_Server::READABLE,
87
-					'callback'            => array( $this, 'get_item' ),
88
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
87
+					'callback'            => array($this, 'get_item'),
88
+					'permission_callback' => array($this, 'get_item_permissions_check'),
89 89
 					'args'                => array(
90 90
 						'context' => $this->get_context_param(
91 91
 							array(
@@ -96,23 +96,23 @@  discard block
 block discarded – undo
96 96
 				),
97 97
 				array(
98 98
 					'methods'             => \WP_REST_Server::EDITABLE,
99
-					'callback'            => array( $this, 'update_item' ),
100
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
101
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
99
+					'callback'            => array($this, 'update_item'),
100
+					'permission_callback' => array($this, 'update_item_permissions_check'),
101
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
102 102
 				),
103 103
 				array(
104 104
 					'methods'             => \WP_REST_Server::DELETABLE,
105
-					'callback'            => array( $this, 'delete_item' ),
106
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
105
+					'callback'            => array($this, 'delete_item'),
106
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
107 107
 					'args'                => array(
108 108
 						'force' => array(
109 109
 							'default'     => false,
110 110
 							'type'        => 'boolean',
111
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
111
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
112 112
 						),
113 113
 					),
114 114
 				),
115
-				'schema' => array( $this, 'get_public_item_schema' ),
115
+				'schema' => array($this, 'get_public_item_schema'),
116 116
 			),
117 117
 			true
118 118
 		);
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
 			array(
122 122
 				'args'   => array(
123 123
 					'product_id' => array(
124
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
124
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
125 125
 						'type'        => 'integer',
126 126
 					),
127 127
 				),
128 128
 				array(
129 129
 					'methods'             => \WP_REST_Server::EDITABLE,
130
-					'callback'            => array( $this, 'batch_items' ),
131
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
132
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
130
+					'callback'            => array($this, 'batch_items'),
131
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
132
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
133 133
 				),
134
-				'schema' => array( $this, 'get_public_batch_schema' ),
134
+				'schema' => array($this, 'get_public_batch_schema'),
135 135
 			),
136 136
 			true
137 137
 		);
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	 * @param  int $id Object ID.
145 145
 	 * @return WC_Data
146 146
 	 */
147
-	protected function get_object( $id ) {
148
-		return wc_get_product( $id );
147
+	protected function get_object($id) {
148
+		return wc_get_product($id);
149 149
 	}
150 150
 
151 151
 	/**
@@ -154,16 +154,16 @@  discard block
 block discarded – undo
154 154
 	 * @param  \WP_REST_Request $request Full details about the request.
155 155
 	 * @return \WP_Error|boolean
156 156
 	 */
157
-	public function update_item_permissions_check( $request ) {
158
-		$object = $this->get_object( (int) $request['id'] );
157
+	public function update_item_permissions_check($request) {
158
+		$object = $this->get_object((int) $request['id']);
159 159
 
160
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
161
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
160
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'edit', $object->get_id())) {
161
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
162 162
 		}
163 163
 
164 164
 		// Check if variation belongs to the correct parent product.
165
-		if ( $object && 0 !== $object->get_parent_id() && absint( $request['product_id'] ) !== $object->get_parent_id() ) {
166
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Parent product does not match current variation.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
165
+		if ($object && 0 !== $object->get_parent_id() && absint($request['product_id']) !== $object->get_parent_id()) {
166
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Parent product does not match current variation.', 'woocommerce'), array('status' => rest_authorization_required_code()));
167 167
 		}
168 168
 
169 169
 		return true;
@@ -176,33 +176,33 @@  discard block
 block discarded – undo
176 176
 	 * @param  \WP_REST_Request $request Request object.
177 177
 	 * @return \WP_REST_Response
178 178
 	 */
179
-	public function prepare_object_for_response( $object, $request ) {
180
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
179
+	public function prepare_object_for_response($object, $request) {
180
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
181 181
 		$data    = array(
182 182
 			'id'                    => $object->get_id(),
183
-			'name'                  => $object->get_name( $context ),
183
+			'name'                  => $object->get_name($context),
184 184
 			'type'                  => $object->get_type(),
185
-			'parent_id'             => $object->get_parent_id( $context ),
186
-			'date_created'          => wc_rest_prepare_date_response( $object->get_date_created(), false ),
187
-			'date_created_gmt'      => wc_rest_prepare_date_response( $object->get_date_created() ),
188
-			'date_modified'         => wc_rest_prepare_date_response( $object->get_date_modified(), false ),
189
-			'date_modified_gmt'     => wc_rest_prepare_date_response( $object->get_date_modified() ),
190
-			'description'           => wc_format_content( $object->get_description() ),
185
+			'parent_id'             => $object->get_parent_id($context),
186
+			'date_created'          => wc_rest_prepare_date_response($object->get_date_created(), false),
187
+			'date_created_gmt'      => wc_rest_prepare_date_response($object->get_date_created()),
188
+			'date_modified'         => wc_rest_prepare_date_response($object->get_date_modified(), false),
189
+			'date_modified_gmt'     => wc_rest_prepare_date_response($object->get_date_modified()),
190
+			'description'           => wc_format_content($object->get_description()),
191 191
 			'permalink'             => $object->get_permalink(),
192 192
 			'sku'                   => $object->get_sku(),
193 193
 			'price'                 => $object->get_price(),
194 194
 			'regular_price'         => $object->get_regular_price(),
195 195
 			'sale_price'            => $object->get_sale_price(),
196
-			'date_on_sale_from'     => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ),
197
-			'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ),
198
-			'date_on_sale_to'       => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ),
199
-			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ),
196
+			'date_on_sale_from'     => wc_rest_prepare_date_response($object->get_date_on_sale_from(), false),
197
+			'date_on_sale_from_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_from()),
198
+			'date_on_sale_to'       => wc_rest_prepare_date_response($object->get_date_on_sale_to(), false),
199
+			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response($object->get_date_on_sale_to()),
200 200
 			'on_sale'               => $object->is_on_sale(),
201 201
 			'status'                => $object->get_status(),
202 202
 			'purchasable'           => $object->is_purchasable(),
203 203
 			'virtual'               => $object->is_virtual(),
204 204
 			'downloadable'          => $object->is_downloadable(),
205
-			'downloads'             => $this->get_downloads( $object ),
205
+			'downloads'             => $this->get_downloads($object),
206 206
 			'download_limit'        => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1,
207 207
 			'download_expiry'       => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1,
208 208
 			'tax_status'            => $object->get_tax_status(),
@@ -221,17 +221,17 @@  discard block
 block discarded – undo
221 221
 			),
222 222
 			'shipping_class'        => $object->get_shipping_class(),
223 223
 			'shipping_class_id'     => $object->get_shipping_class_id(),
224
-			'image'                 => $this->get_image( $object ),
225
-			'attributes'            => $this->get_attributes( $object ),
224
+			'image'                 => $this->get_image($object),
225
+			'attributes'            => $this->get_attributes($object),
226 226
 			'menu_order'            => $object->get_menu_order(),
227 227
 			'meta_data'             => $object->get_meta_data(),
228 228
 		);
229 229
 
230
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
231
-		$data     = $this->add_additional_fields_to_object( $data, $request );
232
-		$data     = $this->filter_response_by_context( $data, $context );
233
-		$response = rest_ensure_response( $data );
234
-		$response->add_links( $this->prepare_links( $object, $request ) );
230
+		$context  = ! empty($request['context']) ? $request['context'] : 'view';
231
+		$data     = $this->add_additional_fields_to_object($data, $request);
232
+		$data     = $this->filter_response_by_context($data, $context);
233
+		$response = rest_ensure_response($data);
234
+		$response->add_links($this->prepare_links($object, $request));
235 235
 
236 236
 		/**
237 237
 		 * Filter the data for a response.
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 		 * @param WC_Data          $object   Object data.
244 244
 		 * @param \WP_REST_Request  $request  Request object.
245 245
 		 */
246
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
246
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
247 247
 	}
248 248
 
249 249
 	/**
@@ -252,32 +252,32 @@  discard block
 block discarded – undo
252 252
 	 * @param WC_Product_Variation $variation Variation data.
253 253
 	 * @return array
254 254
 	 */
255
-	protected function get_image( $variation ) {
256
-		if ( ! $variation->get_image_id() ) {
255
+	protected function get_image($variation) {
256
+		if ( ! $variation->get_image_id()) {
257 257
 			return;
258 258
 		}
259 259
 
260 260
 		$attachment_id   = $variation->get_image_id();
261
-		$attachment_post = get_post( $attachment_id );
262
-		if ( is_null( $attachment_post ) ) {
261
+		$attachment_post = get_post($attachment_id);
262
+		if (is_null($attachment_post)) {
263 263
 			return;
264 264
 		}
265 265
 
266
-		$attachment = wp_get_attachment_image_src( $attachment_id, 'full' );
267
-		if ( ! is_array( $attachment ) ) {
266
+		$attachment = wp_get_attachment_image_src($attachment_id, 'full');
267
+		if ( ! is_array($attachment)) {
268 268
 			return;
269 269
 		}
270 270
 
271
-		if ( ! isset( $image ) ) {
271
+		if ( ! isset($image)) {
272 272
 			return array(
273 273
 				'id'                => (int) $attachment_id,
274
-				'date_created'      => wc_rest_prepare_date_response( $attachment_post->post_date, false ),
275
-				'date_created_gmt'  => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ),
276
-				'date_modified'     => wc_rest_prepare_date_response( $attachment_post->post_modified, false ),
277
-				'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ),
278
-				'src'               => current( $attachment ),
279
-				'name'              => get_the_title( $attachment_id ),
280
-				'alt'               => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
274
+				'date_created'      => wc_rest_prepare_date_response($attachment_post->post_date, false),
275
+				'date_created_gmt'  => wc_rest_prepare_date_response(strtotime($attachment_post->post_date_gmt)),
276
+				'date_modified'     => wc_rest_prepare_date_response($attachment_post->post_modified, false),
277
+				'date_modified_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_modified_gmt)),
278
+				'src'               => current($attachment),
279
+				'name'              => get_the_title($attachment_id),
280
+				'alt'               => get_post_meta($attachment_id, '_wp_attachment_image_alt', true),
281 281
 			);
282 282
 		}
283 283
 	}
@@ -291,35 +291,35 @@  discard block
 block discarded – undo
291 291
 	 * @param  array                 $image     Image data.
292 292
 	 * @return WC_Product_Variation
293 293
 	 */
294
-	protected function set_variation_image( $variation, $image ) {
295
-		$attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
294
+	protected function set_variation_image($variation, $image) {
295
+		$attachment_id = isset($image['id']) ? absint($image['id']) : 0;
296 296
 
297
-		if ( 0 === $attachment_id && isset( $image['src'] ) ) {
298
-			$upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) );
297
+		if (0 === $attachment_id && isset($image['src'])) {
298
+			$upload = wc_rest_upload_image_from_url(esc_url_raw($image['src']));
299 299
 
300
-			if ( is_wp_error( $upload ) ) {
301
-				if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array( $image ) ) ) {
302
-					throw new \WC_REST_Exception( 'woocommerce_variation_image_upload_error', $upload->get_error_message(), 400 );
300
+			if (is_wp_error($upload)) {
301
+				if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array($image))) {
302
+					throw new \WC_REST_Exception('woocommerce_variation_image_upload_error', $upload->get_error_message(), 400);
303 303
 				}
304 304
 			}
305 305
 
306
-			$attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $variation->get_id() );
306
+			$attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $variation->get_id());
307 307
 		}
308 308
 
309
-		if ( ! wp_attachment_is_image( $attachment_id ) ) {
309
+		if ( ! wp_attachment_is_image($attachment_id)) {
310 310
 			/* translators: %s: attachment ID */
311
-			throw new \WC_REST_Exception( 'woocommerce_variation_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 );
311
+			throw new \WC_REST_Exception('woocommerce_variation_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400);
312 312
 		}
313 313
 
314
-		$variation->set_image_id( $attachment_id );
314
+		$variation->set_image_id($attachment_id);
315 315
 
316 316
 		// Set the image alt if present.
317
-		if ( ! empty( $image['alt'] ) ) {
318
-			update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) );
317
+		if ( ! empty($image['alt'])) {
318
+			update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt']));
319 319
 		}
320 320
 
321 321
 		// Set the image name if present.
322
-		if ( ! empty( $image['name'] ) ) {
322
+		if ( ! empty($image['name'])) {
323 323
 			wp_update_post(
324 324
 				array(
325 325
 					'ID'         => $attachment_id,
@@ -338,17 +338,17 @@  discard block
 block discarded – undo
338 338
 	 * @param  \WP_REST_Request $request Full details about the request.
339 339
 	 * @return array
340 340
 	 */
341
-	protected function prepare_objects_query( $request ) {
342
-		$args = parent::prepare_objects_query( $request );
341
+	protected function prepare_objects_query($request) {
342
+		$args = parent::prepare_objects_query($request);
343 343
 
344 344
 		// Set post_status.
345 345
 		$args['post_status'] = $request['status'];
346 346
 
347 347
 		// Filter by sku.
348
-		if ( ! empty( $request['sku'] ) ) {
349
-			$skus = explode( ',', $request['sku'] );
348
+		if ( ! empty($request['sku'])) {
349
+			$skus = explode(',', $request['sku']);
350 350
 			// Include the current string as a SKU too.
351
-			if ( 1 < count( $skus ) ) {
351
+			if (1 < count($skus)) {
352 352
 				$skus[] = $request['sku'];
353 353
 			}
354 354
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 		}
364 364
 
365 365
 		// Filter by tax class.
366
-		if ( ! empty( $request['tax_class'] ) ) {
366
+		if ( ! empty($request['tax_class'])) {
367 367
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
368 368
 				$args,
369 369
 				array(
@@ -374,12 +374,12 @@  discard block
 block discarded – undo
374 374
 		}
375 375
 
376 376
 		// Price filter.
377
-		if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) {
378
-			$args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) );  // WPCS: slow query ok.
377
+		if ( ! empty($request['min_price']) || ! empty($request['max_price'])) {
378
+			$args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); // WPCS: slow query ok.
379 379
 		}
380 380
 
381 381
 		// Filter product based on stock_status.
382
-		if ( ! empty( $request['stock_status'] ) ) {
382
+		if ( ! empty($request['stock_status'])) {
383 383
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
384 384
 				$args,
385 385
 				array(
@@ -390,28 +390,28 @@  discard block
 block discarded – undo
390 390
 		}
391 391
 
392 392
 		// Filter by on sale products.
393
-		if ( is_bool( $request['on_sale'] ) ) {
393
+		if (is_bool($request['on_sale'])) {
394 394
 			$on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in';
395 395
 			$on_sale_ids = wc_get_product_ids_on_sale();
396 396
 
397 397
 			// Use 0 when there's no on sale products to avoid return all products.
398
-			$on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids;
398
+			$on_sale_ids = empty($on_sale_ids) ? array(0) : $on_sale_ids;
399 399
 
400
-			$args[ $on_sale_key ] += $on_sale_ids;
400
+			$args[$on_sale_key] += $on_sale_ids;
401 401
 		}
402 402
 
403 403
 		// Force the post_type argument, since it's not a user input variable.
404
-		if ( ! empty( $request['sku'] ) ) {
405
-			$args['post_type'] = array( 'product', 'product_variation' );
404
+		if ( ! empty($request['sku'])) {
405
+			$args['post_type'] = array('product', 'product_variation');
406 406
 		} else {
407 407
 			$args['post_type'] = $this->post_type;
408 408
 		}
409 409
 
410 410
 		$args['post_parent'] = $request['product_id'];
411 411
 
412
-		if ( ! empty( $request['search'] ) ) {
412
+		if ( ! empty($request['search'])) {
413 413
 			$args['search'] = $request['search'];
414
-			unset( $args['s'] );
414
+			unset($args['s']);
415 415
 		}
416 416
 
417 417
 		return $args;
@@ -424,136 +424,136 @@  discard block
 block discarded – undo
424 424
 	 * @param  bool            $creating If is creating a new object.
425 425
 	 * @return \WP_Error|WC_Data
426 426
 	 */
427
-	protected function prepare_object_for_database( $request, $creating = false ) {
428
-		if ( isset( $request['id'] ) ) {
429
-			$variation = wc_get_product( absint( $request['id'] ) );
427
+	protected function prepare_object_for_database($request, $creating = false) {
428
+		if (isset($request['id'])) {
429
+			$variation = wc_get_product(absint($request['id']));
430 430
 		} else {
431 431
 			$variation = new \WC_Product_Variation();
432 432
 		}
433 433
 
434
-		$variation->set_parent_id( absint( $request['product_id'] ) );
434
+		$variation->set_parent_id(absint($request['product_id']));
435 435
 
436 436
 		// Status.
437
-		if ( isset( $request['status'] ) ) {
438
-			$variation->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' );
437
+		if (isset($request['status'])) {
438
+			$variation->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft');
439 439
 		}
440 440
 
441 441
 		// SKU.
442
-		if ( isset( $request['sku'] ) ) {
443
-			$variation->set_sku( wc_clean( $request['sku'] ) );
442
+		if (isset($request['sku'])) {
443
+			$variation->set_sku(wc_clean($request['sku']));
444 444
 		}
445 445
 
446 446
 		// Thumbnail.
447
-		if ( isset( $request['image'] ) ) {
448
-			if ( is_array( $request['image'] ) ) {
449
-				$variation = $this->set_variation_image( $variation, $request['image'] );
447
+		if (isset($request['image'])) {
448
+			if (is_array($request['image'])) {
449
+				$variation = $this->set_variation_image($variation, $request['image']);
450 450
 			} else {
451
-				$variation->set_image_id( '' );
451
+				$variation->set_image_id('');
452 452
 			}
453 453
 		}
454 454
 
455 455
 		// Virtual variation.
456
-		if ( isset( $request['virtual'] ) ) {
457
-			$variation->set_virtual( $request['virtual'] );
456
+		if (isset($request['virtual'])) {
457
+			$variation->set_virtual($request['virtual']);
458 458
 		}
459 459
 
460 460
 		// Downloadable variation.
461
-		if ( isset( $request['downloadable'] ) ) {
462
-			$variation->set_downloadable( $request['downloadable'] );
461
+		if (isset($request['downloadable'])) {
462
+			$variation->set_downloadable($request['downloadable']);
463 463
 		}
464 464
 
465 465
 		// Downloads.
466
-		if ( $variation->get_downloadable() ) {
466
+		if ($variation->get_downloadable()) {
467 467
 			// Downloadable files.
468
-			if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) {
469
-				$variation = $this->save_downloadable_files( $variation, $request['downloads'] );
468
+			if (isset($request['downloads']) && is_array($request['downloads'])) {
469
+				$variation = $this->save_downloadable_files($variation, $request['downloads']);
470 470
 			}
471 471
 
472 472
 			// Download limit.
473
-			if ( isset( $request['download_limit'] ) ) {
474
-				$variation->set_download_limit( $request['download_limit'] );
473
+			if (isset($request['download_limit'])) {
474
+				$variation->set_download_limit($request['download_limit']);
475 475
 			}
476 476
 
477 477
 			// Download expiry.
478
-			if ( isset( $request['download_expiry'] ) ) {
479
-				$variation->set_download_expiry( $request['download_expiry'] );
478
+			if (isset($request['download_expiry'])) {
479
+				$variation->set_download_expiry($request['download_expiry']);
480 480
 			}
481 481
 		}
482 482
 
483 483
 		// Shipping data.
484
-		$variation = $this->save_product_shipping_data( $variation, $request );
484
+		$variation = $this->save_product_shipping_data($variation, $request);
485 485
 
486 486
 		// Stock handling.
487
-		if ( isset( $request['manage_stock'] ) ) {
488
-			$variation->set_manage_stock( $request['manage_stock'] );
487
+		if (isset($request['manage_stock'])) {
488
+			$variation->set_manage_stock($request['manage_stock']);
489 489
 		}
490 490
 
491
-		if ( isset( $request['stock_status'] ) ) {
492
-			$variation->set_stock_status( $request['stock_status'] );
491
+		if (isset($request['stock_status'])) {
492
+			$variation->set_stock_status($request['stock_status']);
493 493
 		}
494 494
 
495
-		if ( isset( $request['backorders'] ) ) {
496
-			$variation->set_backorders( $request['backorders'] );
495
+		if (isset($request['backorders'])) {
496
+			$variation->set_backorders($request['backorders']);
497 497
 		}
498 498
 
499
-		if ( $variation->get_manage_stock() ) {
500
-			if ( isset( $request['stock_quantity'] ) ) {
501
-				$variation->set_stock_quantity( $request['stock_quantity'] );
502
-			} elseif ( isset( $request['inventory_delta'] ) ) {
503
-				$stock_quantity  = wc_stock_amount( $variation->get_stock_quantity() );
504
-				$stock_quantity += wc_stock_amount( $request['inventory_delta'] );
505
-				$variation->set_stock_quantity( $stock_quantity );
499
+		if ($variation->get_manage_stock()) {
500
+			if (isset($request['stock_quantity'])) {
501
+				$variation->set_stock_quantity($request['stock_quantity']);
502
+			} elseif (isset($request['inventory_delta'])) {
503
+				$stock_quantity  = wc_stock_amount($variation->get_stock_quantity());
504
+				$stock_quantity += wc_stock_amount($request['inventory_delta']);
505
+				$variation->set_stock_quantity($stock_quantity);
506 506
 			}
507 507
 		} else {
508
-			$variation->set_backorders( 'no' );
509
-			$variation->set_stock_quantity( '' );
508
+			$variation->set_backorders('no');
509
+			$variation->set_stock_quantity('');
510 510
 		}
511 511
 
512 512
 		// Regular Price.
513
-		if ( isset( $request['regular_price'] ) ) {
514
-			$variation->set_regular_price( $request['regular_price'] );
513
+		if (isset($request['regular_price'])) {
514
+			$variation->set_regular_price($request['regular_price']);
515 515
 		}
516 516
 
517 517
 		// Sale Price.
518
-		if ( isset( $request['sale_price'] ) ) {
519
-			$variation->set_sale_price( $request['sale_price'] );
518
+		if (isset($request['sale_price'])) {
519
+			$variation->set_sale_price($request['sale_price']);
520 520
 		}
521 521
 
522
-		if ( isset( $request['date_on_sale_from'] ) ) {
523
-			$variation->set_date_on_sale_from( $request['date_on_sale_from'] );
522
+		if (isset($request['date_on_sale_from'])) {
523
+			$variation->set_date_on_sale_from($request['date_on_sale_from']);
524 524
 		}
525 525
 
526
-		if ( isset( $request['date_on_sale_from_gmt'] ) ) {
527
-			$variation->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null );
526
+		if (isset($request['date_on_sale_from_gmt'])) {
527
+			$variation->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null);
528 528
 		}
529 529
 
530
-		if ( isset( $request['date_on_sale_to'] ) ) {
531
-			$variation->set_date_on_sale_to( $request['date_on_sale_to'] );
530
+		if (isset($request['date_on_sale_to'])) {
531
+			$variation->set_date_on_sale_to($request['date_on_sale_to']);
532 532
 		}
533 533
 
534
-		if ( isset( $request['date_on_sale_to_gmt'] ) ) {
535
-			$variation->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null );
534
+		if (isset($request['date_on_sale_to_gmt'])) {
535
+			$variation->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null);
536 536
 		}
537 537
 
538 538
 		// Tax class.
539
-		if ( isset( $request['tax_class'] ) ) {
540
-			$variation->set_tax_class( $request['tax_class'] );
539
+		if (isset($request['tax_class'])) {
540
+			$variation->set_tax_class($request['tax_class']);
541 541
 		}
542 542
 
543 543
 		// Description.
544
-		if ( isset( $request['description'] ) ) {
545
-			$variation->set_description( wp_kses_post( $request['description'] ) );
544
+		if (isset($request['description'])) {
545
+			$variation->set_description(wp_kses_post($request['description']));
546 546
 		}
547 547
 
548 548
 		// Update taxonomies.
549
-		if ( isset( $request['attributes'] ) ) {
549
+		if (isset($request['attributes'])) {
550 550
 			$attributes = array();
551
-			$parent     = wc_get_product( $variation->get_parent_id() );
551
+			$parent     = wc_get_product($variation->get_parent_id());
552 552
 
553
-			if ( ! $parent ) {
553
+			if ( ! $parent) {
554 554
 				return new \WP_Error(
555 555
 					// Translators: %d parent ID.
556
-					"woocommerce_rest_{$this->post_type}_invalid_parent", sprintf( __( 'Cannot set attributes due to invalid parent product.', 'woocommerce' ), $variation->get_parent_id() ), array(
556
+					"woocommerce_rest_{$this->post_type}_invalid_parent", sprintf(__('Cannot set attributes due to invalid parent product.', 'woocommerce'), $variation->get_parent_id()), array(
557 557
 						'status' => 404,
558 558
 					)
559 559
 				);
@@ -561,55 +561,55 @@  discard block
 block discarded – undo
561 561
 
562 562
 			$parent_attributes = $parent->get_attributes();
563 563
 
564
-			foreach ( $request['attributes'] as $attribute ) {
564
+			foreach ($request['attributes'] as $attribute) {
565 565
 				$attribute_id   = 0;
566 566
 				$attribute_name = '';
567 567
 
568 568
 				// Check ID for global attributes or name for product attributes.
569
-				if ( ! empty( $attribute['id'] ) ) {
570
-					$attribute_id   = absint( $attribute['id'] );
571
-					$attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id );
572
-				} elseif ( ! empty( $attribute['name'] ) ) {
573
-					$attribute_name = sanitize_title( $attribute['name'] );
569
+				if ( ! empty($attribute['id'])) {
570
+					$attribute_id   = absint($attribute['id']);
571
+					$attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
572
+				} elseif ( ! empty($attribute['name'])) {
573
+					$attribute_name = sanitize_title($attribute['name']);
574 574
 				}
575 575
 
576
-				if ( ! $attribute_id && ! $attribute_name ) {
576
+				if ( ! $attribute_id && ! $attribute_name) {
577 577
 					continue;
578 578
 				}
579 579
 
580
-				if ( ! isset( $parent_attributes[ $attribute_name ] ) || ! $parent_attributes[ $attribute_name ]->get_variation() ) {
580
+				if ( ! isset($parent_attributes[$attribute_name]) || ! $parent_attributes[$attribute_name]->get_variation()) {
581 581
 					continue;
582 582
 				}
583 583
 
584
-				$attribute_key   = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() );
585
-				$attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : '';
584
+				$attribute_key   = sanitize_title($parent_attributes[$attribute_name]->get_name());
585
+				$attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
586 586
 
587
-				if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) {
587
+				if ($parent_attributes[$attribute_name]->is_taxonomy()) {
588 588
 					// If dealing with a taxonomy, we need to get the slug from the name posted to the API.
589
-					$term = get_term_by( 'name', $attribute_value, $attribute_name );
589
+					$term = get_term_by('name', $attribute_value, $attribute_name);
590 590
 
591
-					if ( $term && ! is_wp_error( $term ) ) {
591
+					if ($term && ! is_wp_error($term)) {
592 592
 						$attribute_value = $term->slug;
593 593
 					} else {
594
-						$attribute_value = sanitize_title( $attribute_value );
594
+						$attribute_value = sanitize_title($attribute_value);
595 595
 					}
596 596
 				}
597 597
 
598
-				$attributes[ $attribute_key ] = $attribute_value;
598
+				$attributes[$attribute_key] = $attribute_value;
599 599
 			}
600 600
 
601
-			$variation->set_attributes( $attributes );
601
+			$variation->set_attributes($attributes);
602 602
 		}
603 603
 
604 604
 		// Menu order.
605
-		if ( $request['menu_order'] ) {
606
-			$variation->set_menu_order( $request['menu_order'] );
605
+		if ($request['menu_order']) {
606
+			$variation->set_menu_order($request['menu_order']);
607 607
 		}
608 608
 
609 609
 		// Meta data.
610
-		if ( is_array( $request['meta_data'] ) ) {
611
-			foreach ( $request['meta_data'] as $meta ) {
612
-				$variation->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
610
+		if (is_array($request['meta_data'])) {
611
+			foreach ($request['meta_data'] as $meta) {
612
+				$variation->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
613 613
 			}
614 614
 		}
615 615
 
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 		 * @param \WP_REST_Request $request   Request object.
624 624
 		 * @param bool            $creating  If is creating a new object.
625 625
 		 */
626
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating );
626
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating);
627 627
 	}
628 628
 
629 629
 	/**
@@ -631,9 +631,9 @@  discard block
 block discarded – undo
631 631
 	 *
632 632
 	 * @param WC_Data $object Object data.
633 633
 	 */
634
-	public function clear_transients( $object ) {
635
-		wc_delete_product_transients( $object->get_parent_id() );
636
-		wp_cache_delete( 'product-' . $object->get_parent_id(), 'products' );
634
+	public function clear_transients($object) {
635
+		wc_delete_product_transients($object->get_parent_id());
636
+		wp_cache_delete('product-' . $object->get_parent_id(), 'products');
637 637
 	}
638 638
 
639 639
 	/**
@@ -643,20 +643,20 @@  discard block
 block discarded – undo
643 643
 	 *
644 644
 	 * @return bool|\WP_Error\WP_REST_Response
645 645
 	 */
646
-	public function delete_item( $request ) {
646
+	public function delete_item($request) {
647 647
 		$force  = (bool) $request['force'];
648
-		$object = $this->get_object( (int) $request['id'] );
648
+		$object = $this->get_object((int) $request['id']);
649 649
 		$result = false;
650 650
 
651
-		if ( ! $object || 0 === $object->get_id() ) {
651
+		if ( ! $object || 0 === $object->get_id()) {
652 652
 			return new \WP_Error(
653
-				"woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array(
653
+				"woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array(
654 654
 					'status' => 404,
655 655
 				)
656 656
 			);
657 657
 		}
658 658
 
659
-		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) );
659
+		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable(array($object, 'get_status'));
660 660
 
661 661
 		/**
662 662
 		 * Filter whether an object is trashable.
@@ -666,24 +666,24 @@  discard block
 block discarded – undo
666 666
 		 * @param boolean $supports_trash Whether the object type support trashing.
667 667
 		 * @param WC_Data $object         The object being considered for trashing support.
668 668
 		 */
669
-		$supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object );
669
+		$supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object);
670 670
 
671
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
671
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
672 672
 			return new \WP_Error(
673 673
 				/* translators: %s: post type */
674
-				"woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array(
674
+				"woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array(
675 675
 					'status' => rest_authorization_required_code(),
676 676
 				)
677 677
 			);
678 678
 		}
679 679
 
680
-		$request->set_param( 'context', 'edit' );
680
+		$request->set_param('context', 'edit');
681 681
 
682 682
 		// If we're forcing, then delete permanently.
683
-		if ( $force ) {
684
-			$previous = $this->prepare_object_for_response( $object, $request );
683
+		if ($force) {
684
+			$previous = $this->prepare_object_for_response($object, $request);
685 685
 
686
-			$object->delete( true );
686
+			$object->delete(true);
687 687
 
688 688
 			$result   = 0 === $object->get_id();
689 689
 			$response = new \WP_REST_Response();
@@ -695,21 +695,21 @@  discard block
 block discarded – undo
695 695
 			);
696 696
 		} else {
697 697
 			// If we don't support trashing for this type, error out.
698
-			if ( ! $supports_trash ) {
698
+			if ( ! $supports_trash) {
699 699
 				return new \WP_Error(
700 700
 					/* translators: %s: post type */
701
-					'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array(
701
+					'woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array(
702 702
 						'status' => 501,
703 703
 					)
704 704
 				);
705 705
 			}
706 706
 
707 707
 			// Otherwise, only trash if we haven't already.
708
-			if ( is_callable( array( $object, 'get_status' ) ) ) {
709
-				if ( 'trash' === $object->get_status() ) {
708
+			if (is_callable(array($object, 'get_status'))) {
709
+				if ('trash' === $object->get_status()) {
710 710
 					return new \WP_Error(
711 711
 						/* translators: %s: post type */
712
-						'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array(
712
+						'woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array(
713 713
 							'status' => 410,
714 714
 						)
715 715
 					);
@@ -719,13 +719,13 @@  discard block
 block discarded – undo
719 719
 				$result = 'trash' === $object->get_status();
720 720
 			}
721 721
 
722
-			$response = $this->prepare_object_for_response( $object, $request );
722
+			$response = $this->prepare_object_for_response($object, $request);
723 723
 		}
724 724
 
725
-		if ( ! $result ) {
725
+		if ( ! $result) {
726 726
 			return new \WP_Error(
727 727
 				/* translators: %s: post type */
728
-				'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array(
728
+				'woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array(
729 729
 					'status' => 500,
730 730
 				)
731 731
 			);
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 		 * @param \WP_REST_Response $response The response data.
739 739
 		 * @param \WP_REST_Request  $request  The request sent to the API.
740 740
 		 */
741
-		do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );
741
+		do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request);
742 742
 
743 743
 		return $response;
744 744
 	}
@@ -750,30 +750,30 @@  discard block
 block discarded – undo
750 750
 	 * @param \WP_REST_Request $request Full details about the request.
751 751
 	 * @return array Of \WP_Error or \WP_REST_Response.
752 752
 	 */
753
-	public function batch_items( $request ) {
754
-		$items       = array_filter( $request->get_params() );
753
+	public function batch_items($request) {
754
+		$items       = array_filter($request->get_params());
755 755
 		$params      = $request->get_url_params();
756 756
 		$product_id  = $params['product_id'];
757 757
 		$body_params = array();
758 758
 
759
-		foreach ( array( 'update', 'create', 'delete' ) as $batch_type ) {
760
-			if ( ! empty( $items[ $batch_type ] ) ) {
759
+		foreach (array('update', 'create', 'delete') as $batch_type) {
760
+			if ( ! empty($items[$batch_type])) {
761 761
 				$injected_items = array();
762
-				foreach ( $items[ $batch_type ] as $item ) {
763
-					$injected_items[] = is_array( $item ) ? array_merge(
762
+				foreach ($items[$batch_type] as $item) {
763
+					$injected_items[] = is_array($item) ? array_merge(
764 764
 						array(
765 765
 							'product_id' => $product_id,
766 766
 						), $item
767 767
 					) : $item;
768 768
 				}
769
-				$body_params[ $batch_type ] = $injected_items;
769
+				$body_params[$batch_type] = $injected_items;
770 770
 			}
771 771
 		}
772 772
 
773
-		$request = new \WP_REST_Request( $request->get_method() );
774
-		$request->set_body_params( $body_params );
773
+		$request = new \WP_REST_Request($request->get_method());
774
+		$request->set_body_params($body_params);
775 775
 
776
-		return parent::batch_items( $request );
776
+		return parent::batch_items($request);
777 777
 	}
778 778
 
779 779
 	/**
@@ -783,18 +783,18 @@  discard block
 block discarded – undo
783 783
 	 * @param \WP_REST_Request $request Request object.
784 784
 	 * @return array                   Links for the given post.
785 785
 	 */
786
-	protected function prepare_links( $object, $request ) {
786
+	protected function prepare_links($object, $request) {
787 787
 		$product_id = (int) $request['product_id'];
788
-		$base       = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base );
788
+		$base       = str_replace('(?P<product_id>[\d]+)', $product_id, $this->rest_base);
789 789
 		$links      = array(
790 790
 			'self'       => array(
791
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $object->get_id() ) ),
791
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $object->get_id())),
792 792
 			),
793 793
 			'collection' => array(
794
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
794
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)),
795 795
 			),
796 796
 			'up'         => array(
797
-				'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product_id ) ),
797
+				'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product_id)),
798 798
 			),
799 799
 		);
800 800
 		return $links;
@@ -806,371 +806,371 @@  discard block
 block discarded – undo
806 806
 	 * @return array
807 807
 	 */
808 808
 	public function get_item_schema() {
809
-		$weight_unit    = get_option( 'woocommerce_weight_unit' );
810
-		$dimension_unit = get_option( 'woocommerce_dimension_unit' );
809
+		$weight_unit    = get_option('woocommerce_weight_unit');
810
+		$dimension_unit = get_option('woocommerce_dimension_unit');
811 811
 		$schema         = array(
812 812
 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
813 813
 			'title'      => $this->post_type,
814 814
 			'type'       => 'object',
815 815
 			'properties' => array(
816 816
 				'id'                    => array(
817
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
817
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
818 818
 					'type'        => 'integer',
819
-					'context'     => array( 'view', 'edit' ),
819
+					'context'     => array('view', 'edit'),
820 820
 					'readonly'    => true,
821 821
 				),
822 822
 				'name'                  => array(
823
-					'description' => __( 'Product parent name.', 'woocommerce' ),
823
+					'description' => __('Product parent name.', 'woocommerce'),
824 824
 					'type'        => 'string',
825
-					'context'     => array( 'view', 'edit' ),
825
+					'context'     => array('view', 'edit'),
826 826
 				),
827 827
 				'type'                  => array(
828
-					'description' => __( 'Product type.', 'woocommerce' ),
828
+					'description' => __('Product type.', 'woocommerce'),
829 829
 					'type'        => 'string',
830 830
 					'default'     => 'variation',
831
-					'enum'        => array( 'variation' ),
832
-					'context'     => array( 'view', 'edit' ),
831
+					'enum'        => array('variation'),
832
+					'context'     => array('view', 'edit'),
833 833
 				),
834 834
 				'parent_id'             => array(
835
-					'description' => __( 'Product parent ID.', 'woocommerce' ),
835
+					'description' => __('Product parent ID.', 'woocommerce'),
836 836
 					'type'        => 'integer',
837
-					'context'     => array( 'view', 'edit' ),
837
+					'context'     => array('view', 'edit'),
838 838
 				),
839 839
 				'date_created'          => array(
840
-					'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ),
840
+					'description' => __("The date the variation was created, in the site's timezone.", 'woocommerce'),
841 841
 					'type'        => 'date-time',
842
-					'context'     => array( 'view', 'edit' ),
842
+					'context'     => array('view', 'edit'),
843 843
 					'readonly'    => true,
844 844
 				),
845 845
 				'date_modified'         => array(
846
-					'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ),
846
+					'description' => __("The date the variation was last modified, in the site's timezone.", 'woocommerce'),
847 847
 					'type'        => 'date-time',
848
-					'context'     => array( 'view', 'edit' ),
848
+					'context'     => array('view', 'edit'),
849 849
 					'readonly'    => true,
850 850
 				),
851 851
 				'description'           => array(
852
-					'description' => __( 'Variation description.', 'woocommerce' ),
852
+					'description' => __('Variation description.', 'woocommerce'),
853 853
 					'type'        => 'string',
854
-					'context'     => array( 'view', 'edit' ),
854
+					'context'     => array('view', 'edit'),
855 855
 				),
856 856
 				'permalink'             => array(
857
-					'description' => __( 'Variation URL.', 'woocommerce' ),
857
+					'description' => __('Variation URL.', 'woocommerce'),
858 858
 					'type'        => 'string',
859 859
 					'format'      => 'uri',
860
-					'context'     => array( 'view', 'edit' ),
860
+					'context'     => array('view', 'edit'),
861 861
 					'readonly'    => true,
862 862
 				),
863 863
 				'sku'                   => array(
864
-					'description' => __( 'Unique identifier.', 'woocommerce' ),
864
+					'description' => __('Unique identifier.', 'woocommerce'),
865 865
 					'type'        => 'string',
866
-					'context'     => array( 'view', 'edit' ),
866
+					'context'     => array('view', 'edit'),
867 867
 				),
868 868
 				'price'                 => array(
869
-					'description' => __( 'Current variation price.', 'woocommerce' ),
869
+					'description' => __('Current variation price.', 'woocommerce'),
870 870
 					'type'        => 'string',
871
-					'context'     => array( 'view', 'edit' ),
871
+					'context'     => array('view', 'edit'),
872 872
 					'readonly'    => true,
873 873
 				),
874 874
 				'regular_price'         => array(
875
-					'description' => __( 'Variation regular price.', 'woocommerce' ),
875
+					'description' => __('Variation regular price.', 'woocommerce'),
876 876
 					'type'        => 'string',
877
-					'context'     => array( 'view', 'edit' ),
877
+					'context'     => array('view', 'edit'),
878 878
 				),
879 879
 				'sale_price'            => array(
880
-					'description' => __( 'Variation sale price.', 'woocommerce' ),
880
+					'description' => __('Variation sale price.', 'woocommerce'),
881 881
 					'type'        => 'string',
882
-					'context'     => array( 'view', 'edit' ),
882
+					'context'     => array('view', 'edit'),
883 883
 				),
884 884
 				'date_on_sale_from'     => array(
885
-					'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ),
885
+					'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'),
886 886
 					'type'        => 'date-time',
887
-					'context'     => array( 'view', 'edit' ),
887
+					'context'     => array('view', 'edit'),
888 888
 				),
889 889
 				'date_on_sale_from_gmt' => array(
890
-					'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ),
890
+					'description' => __('Start date of sale price, as GMT.', 'woocommerce'),
891 891
 					'type'        => 'date-time',
892
-					'context'     => array( 'view', 'edit' ),
892
+					'context'     => array('view', 'edit'),
893 893
 				),
894 894
 				'date_on_sale_to'       => array(
895
-					'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
895
+					'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'),
896 896
 					'type'        => 'date-time',
897
-					'context'     => array( 'view', 'edit' ),
897
+					'context'     => array('view', 'edit'),
898 898
 				),
899 899
 				'date_on_sale_to_gmt'   => array(
900
-					'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
900
+					'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'),
901 901
 					'type'        => 'date-time',
902
-					'context'     => array( 'view', 'edit' ),
902
+					'context'     => array('view', 'edit'),
903 903
 				),
904 904
 				'on_sale'               => array(
905
-					'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ),
905
+					'description' => __('Shows if the variation is on sale.', 'woocommerce'),
906 906
 					'type'        => 'boolean',
907
-					'context'     => array( 'view', 'edit' ),
907
+					'context'     => array('view', 'edit'),
908 908
 					'readonly'    => true,
909 909
 				),
910 910
 				'status'                => array(
911
-					'description' => __( 'Variation status.', 'woocommerce' ),
911
+					'description' => __('Variation status.', 'woocommerce'),
912 912
 					'type'        => 'string',
913 913
 					'default'     => 'publish',
914
-					'enum'        => array_keys( get_post_statuses() ),
915
-					'context'     => array( 'view', 'edit' ),
914
+					'enum'        => array_keys(get_post_statuses()),
915
+					'context'     => array('view', 'edit'),
916 916
 				),
917 917
 				'purchasable'           => array(
918
-					'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ),
918
+					'description' => __('Shows if the variation can be bought.', 'woocommerce'),
919 919
 					'type'        => 'boolean',
920
-					'context'     => array( 'view', 'edit' ),
920
+					'context'     => array('view', 'edit'),
921 921
 					'readonly'    => true,
922 922
 				),
923 923
 				'virtual'               => array(
924
-					'description' => __( 'If the variation is virtual.', 'woocommerce' ),
924
+					'description' => __('If the variation is virtual.', 'woocommerce'),
925 925
 					'type'        => 'boolean',
926 926
 					'default'     => false,
927
-					'context'     => array( 'view', 'edit' ),
927
+					'context'     => array('view', 'edit'),
928 928
 				),
929 929
 				'downloadable'          => array(
930
-					'description' => __( 'If the variation is downloadable.', 'woocommerce' ),
930
+					'description' => __('If the variation is downloadable.', 'woocommerce'),
931 931
 					'type'        => 'boolean',
932 932
 					'default'     => false,
933
-					'context'     => array( 'view', 'edit' ),
933
+					'context'     => array('view', 'edit'),
934 934
 				),
935 935
 				'downloads'             => array(
936
-					'description' => __( 'List of downloadable files.', 'woocommerce' ),
936
+					'description' => __('List of downloadable files.', 'woocommerce'),
937 937
 					'type'        => 'array',
938
-					'context'     => array( 'view', 'edit' ),
938
+					'context'     => array('view', 'edit'),
939 939
 					'items'       => array(
940 940
 						'type'       => 'object',
941 941
 						'properties' => array(
942 942
 							'id'   => array(
943
-								'description' => __( 'File ID.', 'woocommerce' ),
943
+								'description' => __('File ID.', 'woocommerce'),
944 944
 								'type'        => 'string',
945
-								'context'     => array( 'view', 'edit' ),
945
+								'context'     => array('view', 'edit'),
946 946
 							),
947 947
 							'name' => array(
948
-								'description' => __( 'File name.', 'woocommerce' ),
948
+								'description' => __('File name.', 'woocommerce'),
949 949
 								'type'        => 'string',
950
-								'context'     => array( 'view', 'edit' ),
950
+								'context'     => array('view', 'edit'),
951 951
 							),
952 952
 							'file' => array(
953
-								'description' => __( 'File URL.', 'woocommerce' ),
953
+								'description' => __('File URL.', 'woocommerce'),
954 954
 								'type'        => 'string',
955
-								'context'     => array( 'view', 'edit' ),
955
+								'context'     => array('view', 'edit'),
956 956
 							),
957 957
 						),
958 958
 					),
959 959
 				),
960 960
 				'download_limit'        => array(
961
-					'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ),
961
+					'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'),
962 962
 					'type'        => 'integer',
963 963
 					'default'     => -1,
964
-					'context'     => array( 'view', 'edit' ),
964
+					'context'     => array('view', 'edit'),
965 965
 				),
966 966
 				'download_expiry'       => array(
967
-					'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ),
967
+					'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'),
968 968
 					'type'        => 'integer',
969 969
 					'default'     => -1,
970
-					'context'     => array( 'view', 'edit' ),
970
+					'context'     => array('view', 'edit'),
971 971
 				),
972 972
 				'tax_status'            => array(
973
-					'description' => __( 'Tax status.', 'woocommerce' ),
973
+					'description' => __('Tax status.', 'woocommerce'),
974 974
 					'type'        => 'string',
975 975
 					'default'     => 'taxable',
976
-					'enum'        => array( 'taxable', 'shipping', 'none' ),
977
-					'context'     => array( 'view', 'edit' ),
976
+					'enum'        => array('taxable', 'shipping', 'none'),
977
+					'context'     => array('view', 'edit'),
978 978
 				),
979 979
 				'tax_class'             => array(
980
-					'description' => __( 'Tax class.', 'woocommerce' ),
980
+					'description' => __('Tax class.', 'woocommerce'),
981 981
 					'type'        => 'string',
982
-					'context'     => array( 'view', 'edit' ),
982
+					'context'     => array('view', 'edit'),
983 983
 				),
984 984
 				'manage_stock'          => array(
985
-					'description' => __( 'Stock management at variation level.', 'woocommerce' ),
985
+					'description' => __('Stock management at variation level.', 'woocommerce'),
986 986
 					'type'        => 'boolean',
987 987
 					'default'     => false,
988
-					'context'     => array( 'view', 'edit' ),
988
+					'context'     => array('view', 'edit'),
989 989
 				),
990 990
 				'stock_quantity'        => array(
991
-					'description' => __( 'Stock quantity.', 'woocommerce' ),
991
+					'description' => __('Stock quantity.', 'woocommerce'),
992 992
 					'type'        => 'integer',
993
-					'context'     => array( 'view', 'edit' ),
993
+					'context'     => array('view', 'edit'),
994 994
 				),
995 995
 				'stock_status'          => array(
996
-					'description' => __( 'Controls the stock status of the product.', 'woocommerce' ),
996
+					'description' => __('Controls the stock status of the product.', 'woocommerce'),
997 997
 					'type'        => 'string',
998 998
 					'default'     => 'instock',
999
-					'enum'        => array_keys( wc_get_product_stock_status_options() ),
1000
-					'context'     => array( 'view', 'edit' ),
999
+					'enum'        => array_keys(wc_get_product_stock_status_options()),
1000
+					'context'     => array('view', 'edit'),
1001 1001
 				),
1002 1002
 				'backorders'            => array(
1003
-					'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ),
1003
+					'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'),
1004 1004
 					'type'        => 'string',
1005 1005
 					'default'     => 'no',
1006
-					'enum'        => array( 'no', 'notify', 'yes' ),
1007
-					'context'     => array( 'view', 'edit' ),
1006
+					'enum'        => array('no', 'notify', 'yes'),
1007
+					'context'     => array('view', 'edit'),
1008 1008
 				),
1009 1009
 				'backorders_allowed'    => array(
1010
-					'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ),
1010
+					'description' => __('Shows if backorders are allowed.', 'woocommerce'),
1011 1011
 					'type'        => 'boolean',
1012
-					'context'     => array( 'view', 'edit' ),
1012
+					'context'     => array('view', 'edit'),
1013 1013
 					'readonly'    => true,
1014 1014
 				),
1015 1015
 				'backordered'           => array(
1016
-					'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ),
1016
+					'description' => __('Shows if the variation is on backordered.', 'woocommerce'),
1017 1017
 					'type'        => 'boolean',
1018
-					'context'     => array( 'view', 'edit' ),
1018
+					'context'     => array('view', 'edit'),
1019 1019
 					'readonly'    => true,
1020 1020
 				),
1021 1021
 				'weight'                => array(
1022 1022
 					/* translators: %s: weight unit */
1023
-					'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ),
1023
+					'description' => sprintf(__('Variation weight (%s).', 'woocommerce'), $weight_unit),
1024 1024
 					'type'        => 'string',
1025
-					'context'     => array( 'view', 'edit' ),
1025
+					'context'     => array('view', 'edit'),
1026 1026
 				),
1027 1027
 				'dimensions'            => array(
1028
-					'description' => __( 'Variation dimensions.', 'woocommerce' ),
1028
+					'description' => __('Variation dimensions.', 'woocommerce'),
1029 1029
 					'type'        => 'object',
1030
-					'context'     => array( 'view', 'edit' ),
1030
+					'context'     => array('view', 'edit'),
1031 1031
 					'properties'  => array(
1032 1032
 						'length' => array(
1033 1033
 							/* translators: %s: dimension unit */
1034
-							'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ),
1034
+							'description' => sprintf(__('Variation length (%s).', 'woocommerce'), $dimension_unit),
1035 1035
 							'type'        => 'string',
1036
-							'context'     => array( 'view', 'edit' ),
1036
+							'context'     => array('view', 'edit'),
1037 1037
 						),
1038 1038
 						'width'  => array(
1039 1039
 							/* translators: %s: dimension unit */
1040
-							'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ),
1040
+							'description' => sprintf(__('Variation width (%s).', 'woocommerce'), $dimension_unit),
1041 1041
 							'type'        => 'string',
1042
-							'context'     => array( 'view', 'edit' ),
1042
+							'context'     => array('view', 'edit'),
1043 1043
 						),
1044 1044
 						'height' => array(
1045 1045
 							/* translators: %s: dimension unit */
1046
-							'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ),
1046
+							'description' => sprintf(__('Variation height (%s).', 'woocommerce'), $dimension_unit),
1047 1047
 							'type'        => 'string',
1048
-							'context'     => array( 'view', 'edit' ),
1048
+							'context'     => array('view', 'edit'),
1049 1049
 						),
1050 1050
 					),
1051 1051
 				),
1052 1052
 				'shipping_class'        => array(
1053
-					'description' => __( 'Shipping class slug.', 'woocommerce' ),
1053
+					'description' => __('Shipping class slug.', 'woocommerce'),
1054 1054
 					'type'        => 'string',
1055
-					'context'     => array( 'view', 'edit' ),
1055
+					'context'     => array('view', 'edit'),
1056 1056
 				),
1057 1057
 				'shipping_class_id'     => array(
1058
-					'description' => __( 'Shipping class ID.', 'woocommerce' ),
1058
+					'description' => __('Shipping class ID.', 'woocommerce'),
1059 1059
 					'type'        => 'string',
1060
-					'context'     => array( 'view', 'edit' ),
1060
+					'context'     => array('view', 'edit'),
1061 1061
 					'readonly'    => true,
1062 1062
 				),
1063 1063
 				'image'                 => array(
1064
-					'description' => __( 'Variation image data.', 'woocommerce' ),
1064
+					'description' => __('Variation image data.', 'woocommerce'),
1065 1065
 					'type'        => 'object',
1066
-					'context'     => array( 'view', 'edit' ),
1066
+					'context'     => array('view', 'edit'),
1067 1067
 					'properties'  => array(
1068 1068
 						'id'                => array(
1069
-							'description' => __( 'Image ID.', 'woocommerce' ),
1069
+							'description' => __('Image ID.', 'woocommerce'),
1070 1070
 							'type'        => 'integer',
1071
-							'context'     => array( 'view', 'edit' ),
1071
+							'context'     => array('view', 'edit'),
1072 1072
 						),
1073 1073
 						'date_created'      => array(
1074
-							'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
1074
+							'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'),
1075 1075
 							'type'        => 'date-time',
1076
-							'context'     => array( 'view', 'edit' ),
1076
+							'context'     => array('view', 'edit'),
1077 1077
 							'readonly'    => true,
1078 1078
 						),
1079 1079
 						'date_created_gmt'  => array(
1080
-							'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
1080
+							'description' => __('The date the image was created, as GMT.', 'woocommerce'),
1081 1081
 							'type'        => 'date-time',
1082
-							'context'     => array( 'view', 'edit' ),
1082
+							'context'     => array('view', 'edit'),
1083 1083
 							'readonly'    => true,
1084 1084
 						),
1085 1085
 						'date_modified'     => array(
1086
-							'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
1086
+							'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'),
1087 1087
 							'type'        => 'date-time',
1088
-							'context'     => array( 'view', 'edit' ),
1088
+							'context'     => array('view', 'edit'),
1089 1089
 							'readonly'    => true,
1090 1090
 						),
1091 1091
 						'date_modified_gmt' => array(
1092
-							'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
1092
+							'description' => __('The date the image was last modified, as GMT.', 'woocommerce'),
1093 1093
 							'type'        => 'date-time',
1094
-							'context'     => array( 'view', 'edit' ),
1094
+							'context'     => array('view', 'edit'),
1095 1095
 							'readonly'    => true,
1096 1096
 						),
1097 1097
 						'src'               => array(
1098
-							'description' => __( 'Image URL.', 'woocommerce' ),
1098
+							'description' => __('Image URL.', 'woocommerce'),
1099 1099
 							'type'        => 'string',
1100 1100
 							'format'      => 'uri',
1101
-							'context'     => array( 'view', 'edit' ),
1101
+							'context'     => array('view', 'edit'),
1102 1102
 						),
1103 1103
 						'name'              => array(
1104
-							'description' => __( 'Image name.', 'woocommerce' ),
1104
+							'description' => __('Image name.', 'woocommerce'),
1105 1105
 							'type'        => 'string',
1106
-							'context'     => array( 'view', 'edit' ),
1106
+							'context'     => array('view', 'edit'),
1107 1107
 						),
1108 1108
 						'alt'               => array(
1109
-							'description' => __( 'Image alternative text.', 'woocommerce' ),
1109
+							'description' => __('Image alternative text.', 'woocommerce'),
1110 1110
 							'type'        => 'string',
1111
-							'context'     => array( 'view', 'edit' ),
1111
+							'context'     => array('view', 'edit'),
1112 1112
 						),
1113 1113
 					),
1114 1114
 				),
1115 1115
 				'attributes'            => array(
1116
-					'description' => __( 'List of attributes.', 'woocommerce' ),
1116
+					'description' => __('List of attributes.', 'woocommerce'),
1117 1117
 					'type'        => 'array',
1118
-					'context'     => array( 'view', 'edit' ),
1118
+					'context'     => array('view', 'edit'),
1119 1119
 					'items'       => array(
1120 1120
 						'type'       => 'object',
1121 1121
 						'properties' => array(
1122 1122
 							'id'     => array(
1123
-								'description' => __( 'Attribute ID.', 'woocommerce' ),
1123
+								'description' => __('Attribute ID.', 'woocommerce'),
1124 1124
 								'type'        => 'integer',
1125
-								'context'     => array( 'view', 'edit' ),
1125
+								'context'     => array('view', 'edit'),
1126 1126
 							),
1127 1127
 							'name'   => array(
1128
-								'description' => __( 'Attribute name.', 'woocommerce' ),
1128
+								'description' => __('Attribute name.', 'woocommerce'),
1129 1129
 								'type'        => 'string',
1130
-								'context'     => array( 'view', 'edit' ),
1130
+								'context'     => array('view', 'edit'),
1131 1131
 							),
1132 1132
 							'option' => array(
1133
-								'description' => __( 'Selected attribute term name.', 'woocommerce' ),
1133
+								'description' => __('Selected attribute term name.', 'woocommerce'),
1134 1134
 								'type'        => 'string',
1135
-								'context'     => array( 'view', 'edit' ),
1135
+								'context'     => array('view', 'edit'),
1136 1136
 							),
1137 1137
 						),
1138 1138
 					),
1139 1139
 				),
1140 1140
 				'menu_order'            => array(
1141
-					'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ),
1141
+					'description' => __('Menu order, used to custom sort products.', 'woocommerce'),
1142 1142
 					'type'        => 'integer',
1143
-					'context'     => array( 'view', 'edit' ),
1143
+					'context'     => array('view', 'edit'),
1144 1144
 				),
1145 1145
 				'meta_data'             => array(
1146
-					'description' => __( 'Meta data.', 'woocommerce' ),
1146
+					'description' => __('Meta data.', 'woocommerce'),
1147 1147
 					'type'        => 'array',
1148
-					'context'     => array( 'view', 'edit' ),
1148
+					'context'     => array('view', 'edit'),
1149 1149
 					'items'       => array(
1150 1150
 						'type'       => 'object',
1151 1151
 						'properties' => array(
1152 1152
 							'id'    => array(
1153
-								'description' => __( 'Meta ID.', 'woocommerce' ),
1153
+								'description' => __('Meta ID.', 'woocommerce'),
1154 1154
 								'type'        => 'integer',
1155
-								'context'     => array( 'view', 'edit' ),
1155
+								'context'     => array('view', 'edit'),
1156 1156
 								'readonly'    => true,
1157 1157
 							),
1158 1158
 							'key'   => array(
1159
-								'description' => __( 'Meta key.', 'woocommerce' ),
1159
+								'description' => __('Meta key.', 'woocommerce'),
1160 1160
 								'type'        => 'string',
1161
-								'context'     => array( 'view', 'edit' ),
1161
+								'context'     => array('view', 'edit'),
1162 1162
 							),
1163 1163
 							'value' => array(
1164
-								'description' => __( 'Meta value.', 'woocommerce' ),
1164
+								'description' => __('Meta value.', 'woocommerce'),
1165 1165
 								'type'        => 'mixed',
1166
-								'context'     => array( 'view', 'edit' ),
1166
+								'context'     => array('view', 'edit'),
1167 1167
 							),
1168 1168
 						),
1169 1169
 					),
1170 1170
 				),
1171 1171
 			),
1172 1172
 		);
1173
-		return $this->add_additional_fields_schema( $schema );
1173
+		return $this->add_additional_fields_schema($schema);
1174 1174
 	}
1175 1175
 
1176 1176
 	/**
@@ -1193,15 +1193,15 @@  discard block
 block discarded – undo
1193 1193
 		);
1194 1194
 
1195 1195
 		$params['stock_status'] = array(
1196
-			'description'       => __( 'Limit result set to products with specified stock status.', 'woocommerce' ),
1196
+			'description'       => __('Limit result set to products with specified stock status.', 'woocommerce'),
1197 1197
 			'type'              => 'string',
1198
-			'enum'              => array_keys( wc_get_product_stock_status_options() ),
1198
+			'enum'              => array_keys(wc_get_product_stock_status_options()),
1199 1199
 			'sanitize_callback' => 'sanitize_text_field',
1200 1200
 			'validate_callback' => 'rest_validate_request_arg',
1201 1201
 		);
1202 1202
 
1203 1203
 		$params['search'] = array(
1204
-			'description'       => __( 'Search by similar product name or sku.', 'woocommerce' ),
1204
+			'description'       => __('Search by similar product name or sku.', 'woocommerce'),
1205 1205
 			'type'              => 'string',
1206 1206
 			'validate_callback' => 'rest_validate_request_arg',
1207 1207
 		);
@@ -1215,14 +1215,14 @@  discard block
 block discarded – undo
1215 1215
 	 * @param \WP_REST_Request $request Full details about the request.
1216 1216
 	 * @return \WP_Error\WP_REST_Response
1217 1217
 	 */
1218
-	public function get_items( $request ) {
1219
-		add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 );
1220
-		add_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10, 2 );
1221
-		add_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10, 2 );
1222
-		$response = parent::get_items( $request );
1223
-		remove_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10 );
1224
-		remove_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10 );
1225
-		remove_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10 );
1218
+	public function get_items($request) {
1219
+		add_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10, 2);
1220
+		add_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10, 2);
1221
+		add_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10, 2);
1222
+		$response = parent::get_items($request);
1223
+		remove_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10);
1224
+		remove_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10);
1225
+		remove_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10);
1226 1226
 		return $response;
1227 1227
 	}
1228 1228
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/Data/Currencies.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Controllers\Version4\Data as DataController;
15 15
 
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 			array(
36 36
 				array(
37 37
 					'methods'             => \WP_REST_Server::READABLE,
38
-					'callback'            => array( $this, 'get_items' ),
39
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
38
+					'callback'            => array($this, 'get_items'),
39
+					'permission_callback' => array($this, 'get_items_permissions_check'),
40 40
 				),
41
-				'schema' => array( $this, 'get_public_item_schema' ),
41
+				'schema' => array($this, 'get_public_item_schema'),
42 42
 			)
43 43
 		);
44 44
 		register_rest_route(
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 			array(
48 48
 				array(
49 49
 					'methods'             => \WP_REST_Server::READABLE,
50
-					'callback'            => array( $this, 'get_current_item' ),
51
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
50
+					'callback'            => array($this, 'get_current_item'),
51
+					'permission_callback' => array($this, 'get_item_permissions_check'),
52 52
 				),
53
-				'schema' => array( $this, 'get_public_item_schema' ),
53
+				'schema' => array($this, 'get_public_item_schema'),
54 54
 			)
55 55
 		);
56 56
 		register_rest_route(
@@ -59,16 +59,16 @@  discard block
 block discarded – undo
59 59
 			array(
60 60
 				array(
61 61
 					'methods'             => \WP_REST_Server::READABLE,
62
-					'callback'            => array( $this, 'get_item' ),
63
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
62
+					'callback'            => array($this, 'get_item'),
63
+					'permission_callback' => array($this, 'get_item_permissions_check'),
64 64
 					'args'                => array(
65 65
 						'location' => array(
66
-							'description' => __( 'ISO4217 currency code.', 'woocommerce' ),
66
+							'description' => __('ISO4217 currency code.', 'woocommerce'),
67 67
 							'type'        => 'string',
68 68
 						),
69 69
 					),
70 70
 				),
71
-				'schema' => array( $this, 'get_public_item_schema' ),
71
+				'schema' => array($this, 'get_public_item_schema'),
72 72
 			)
73 73
 		);
74 74
 	}
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
 	 * @param  \WP_REST_Request $request Request data.
81 81
 	 * @return array|mixed Response data, ready for insertion into collection data.
82 82
 	 */
83
-	public function get_currency( $code = false, $request ) {
83
+	public function get_currency($code = false, $request) {
84 84
 		$currencies = get_woocommerce_currencies();
85 85
 		$data       = array();
86 86
 
87
-		if ( ! array_key_exists( $code, $currencies ) ) {
87
+		if ( ! array_key_exists($code, $currencies)) {
88 88
 			return false;
89 89
 		}
90 90
 
91 91
 		$currency = array(
92 92
 			'code'   => $code,
93
-			'name'   => $currencies[ $code ],
94
-			'symbol' => get_woocommerce_currency_symbol( $code ),
93
+			'name'   => $currencies[$code],
94
+			'symbol' => get_woocommerce_currency_symbol($code),
95 95
 		);
96 96
 
97 97
 		return $currency;
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 	 * @param  \WP_REST_Request $request Request data.
104 104
 	 * @return \WP_Error\WP_REST_Response
105 105
 	 */
106
-	public function get_items( $request ) {
106
+	public function get_items($request) {
107 107
 		$currencies = get_woocommerce_currencies();
108
-		foreach ( array_keys( $currencies ) as $code ) {
109
-			$currency = $this->get_currency( $code, $request );
110
-			$response = $this->prepare_item_for_response( $currency, $request );
111
-			$data[]   = $this->prepare_response_for_collection( $response );
108
+		foreach (array_keys($currencies) as $code) {
109
+			$currency = $this->get_currency($code, $request);
110
+			$response = $this->prepare_item_for_response($currency, $request);
111
+			$data[]   = $this->prepare_response_for_collection($response);
112 112
 		}
113 113
 
114
-		return rest_ensure_response( $data );
114
+		return rest_ensure_response($data);
115 115
 	}
116 116
 
117 117
 	/**
@@ -120,12 +120,12 @@  discard block
 block discarded – undo
120 120
 	 * @param  \WP_REST_Request $request Request data.
121 121
 	 * @return \WP_Error\WP_REST_Response
122 122
 	 */
123
-	public function get_item( $request ) {
124
-		$data = $this->get_currency( strtoupper( $request['currency'] ), $request );
125
-		if ( empty( $data ) ) {
126
-			return new \WP_Error( 'woocommerce_rest_data_invalid_currency', __( 'There are no currencies matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
123
+	public function get_item($request) {
124
+		$data = $this->get_currency(strtoupper($request['currency']), $request);
125
+		if (empty($data)) {
126
+			return new \WP_Error('woocommerce_rest_data_invalid_currency', __('There are no currencies matching these parameters.', 'woocommerce'), array('status' => 404));
127 127
 		}
128
-		return $this->prepare_item_for_response( $data, $request );
128
+		return $this->prepare_item_for_response($data, $request);
129 129
 	}
130 130
 
131 131
 	/**
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 	 * @param  \WP_REST_Request $request Request data.
135 135
 	 * @return \WP_Error\WP_REST_Response
136 136
 	 */
137
-	public function get_current_item( $request ) {
138
-		$currency = get_option( 'woocommerce_currency' );
139
-		return $this->prepare_item_for_response( $this->get_currency( $currency, $request ), $request );
137
+	public function get_current_item($request) {
138
+		$currency = get_option('woocommerce_currency');
139
+		return $this->prepare_item_for_response($this->get_currency($currency, $request), $request);
140 140
 	}
141 141
 
142 142
 	/**
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
 	 * @param \WP_REST_Request $request Request object.
147 147
 	 * @return \WP_REST_Response $response Response data.
148 148
 	 */
149
-	public function prepare_item_for_response( $item, $request ) {
150
-		$data     = $this->add_additional_fields_to_object( $item, $request );
151
-		$data     = $this->filter_response_by_context( $data, 'view' );
152
-		$response = rest_ensure_response( $data );
149
+	public function prepare_item_for_response($item, $request) {
150
+		$data     = $this->add_additional_fields_to_object($item, $request);
151
+		$data     = $this->filter_response_by_context($data, 'view');
152
+		$response = rest_ensure_response($data);
153 153
 
154
-		$response->add_links( $this->prepare_links( $item ) );
154
+		$response->add_links($this->prepare_links($item));
155 155
 
156 156
 		/**
157 157
 		 * Filter currency returned from the API.
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		 * @param array            $item     Currency data.
161 161
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
162 162
 		 */
163
-		return apply_filters( 'woocommerce_rest_prepare_data_currency', $response, $item, $request );
163
+		return apply_filters('woocommerce_rest_prepare_data_currency', $response, $item, $request);
164 164
 	}
165 165
 
166 166
 	/**
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 	 * @param object $item Data object.
170 170
 	 * @return array Links for the given currency.
171 171
 	 */
172
-	protected function prepare_links( $item ) {
173
-		$code  = strtoupper( $item['code'] );
172
+	protected function prepare_links($item) {
173
+		$code  = strtoupper($item['code']);
174 174
 		$links = array(
175 175
 			'self'       => array(
176
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $code ) ),
176
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $code)),
177 177
 			),
178 178
 			'collection' => array(
179
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
179
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
180 180
 			),
181 181
 		);
182 182
 
@@ -197,25 +197,25 @@  discard block
 block discarded – undo
197 197
 			'properties' => array(
198 198
 				'code'   => array(
199 199
 					'type'        => 'string',
200
-					'description' => __( 'ISO4217 currency code.', 'woocommerce' ),
201
-					'context'     => array( 'view' ),
200
+					'description' => __('ISO4217 currency code.', 'woocommerce'),
201
+					'context'     => array('view'),
202 202
 					'readonly'    => true,
203 203
 				),
204 204
 				'name'   => array(
205 205
 					'type'        => 'string',
206
-					'description' => __( 'Full name of currency.', 'woocommerce' ),
207
-					'context'     => array( 'view' ),
206
+					'description' => __('Full name of currency.', 'woocommerce'),
207
+					'context'     => array('view'),
208 208
 					'readonly'    => true,
209 209
 				),
210 210
 				'symbol' => array(
211 211
 					'type'        => 'string',
212
-					'description' => __( 'Currency symbol.', 'woocommerce' ),
213
-					'context'     => array( 'view' ),
212
+					'description' => __('Currency symbol.', 'woocommerce'),
213
+					'context'     => array('view'),
214 214
 					'readonly'    => true,
215 215
 				),
216 216
 			),
217 217
 		);
218 218
 
219
-		return $this->add_additional_fields_schema( $schema );
219
+		return $this->add_additional_fields_schema($schema);
220 220
 	}
221 221
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/Data/DownloadIPs.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Controllers\Version4\Data as DataController;
15 15
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 			array(
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::READABLE,
40
-					'callback'            => array( $this, 'get_items' ),
41
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
+					'callback'            => array($this, 'get_items'),
41
+					'permission_callback' => array($this, 'get_items_permissions_check'),
42 42
 				),
43
-				'schema' => array( $this, 'get_public_item_schema' ),
43
+				'schema' => array($this, 'get_public_item_schema'),
44 44
 			)
45 45
 		);
46 46
 	}
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
 	 * @param  \WP_REST_Request $request Request data.
53 53
 	 * @return \WP_Error\WP_REST_Response
54 54
 	 */
55
-	public function get_items( $request ) {
55
+	public function get_items($request) {
56 56
 		global $wpdb;
57 57
 
58
-		if ( isset( $request['match'] ) ) {
58
+		if (isset($request['match'])) {
59 59
 			$downloads = $wpdb->get_results(
60 60
 				$wpdb->prepare(
61 61
 					"SELECT DISTINCT( user_ip_address ) FROM {$wpdb->prefix}wc_download_log
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
 				)
66 66
 			);
67 67
 		} else {
68
-			return new \WP_Error( 'woocommerce_rest_data_download_ips_invalid_request', __( 'Invalid request. Please pass the match parameter.', 'woocommerce' ), array( 'status' => 400 ) );
68
+			return new \WP_Error('woocommerce_rest_data_download_ips_invalid_request', __('Invalid request. Please pass the match parameter.', 'woocommerce'), array('status' => 400));
69 69
 		}
70 70
 
71 71
 		$data = array();
72 72
 
73
-		if ( ! empty( $downloads ) ) {
74
-			foreach ( $downloads as $download ) {
75
-				$response = $this->prepare_item_for_response( $download, $request );
76
-				$data[]   = $this->prepare_response_for_collection( $response );
73
+		if ( ! empty($downloads)) {
74
+			foreach ($downloads as $download) {
75
+				$response = $this->prepare_item_for_response($download, $request);
76
+				$data[]   = $this->prepare_response_for_collection($response);
77 77
 			}
78 78
 		}
79 79
 
80
-		return rest_ensure_response( $data );
80
+		return rest_ensure_response($data);
81 81
 	}
82 82
 
83 83
 	/**
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
 	 * @param \WP_REST_Request $request Request object.
89 89
 	 * @return \WP_REST_Response $response Response data.
90 90
 	 */
91
-	public function prepare_item_for_response( $item, $request ) {
92
-		$data     = $this->add_additional_fields_to_object( $item, $request );
93
-		$data     = $this->filter_response_by_context( $data, 'view' );
94
-		$response = rest_ensure_response( $data );
91
+	public function prepare_item_for_response($item, $request) {
92
+		$data     = $this->add_additional_fields_to_object($item, $request);
93
+		$data     = $this->filter_response_by_context($data, 'view');
94
+		$response = rest_ensure_response($data);
95 95
 
96
-		$response->add_links( $this->prepare_links( $item ) );
96
+		$response->add_links($this->prepare_links($item));
97 97
 
98 98
 		/**
99 99
 		 * Filter the list returned from the API.
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		 * @param array            $item     The original item.
103 103
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
104 104
 		 */
105
-		return apply_filters( 'woocommerce_rest_prepare_data_download_ip', $response, $item, $request );
105
+		return apply_filters('woocommerce_rest_prepare_data_download_ip', $response, $item, $request);
106 106
 	}
107 107
 
108 108
 	/**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
 	 * @param object $item Data object.
112 112
 	 * @return array Links for the given object.
113 113
 	 */
114
-	protected function prepare_links( $item ) {
114
+	protected function prepare_links($item) {
115 115
 		$links = array(
116 116
 			'collection' => array(
117
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
117
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
118 118
 			),
119 119
 		);
120 120
 		return $links;
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 	 */
128 128
 	public function get_collection_params() {
129 129
 		$params            = array();
130
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
130
+		$params['context'] = $this->get_context_param(array('default' => 'view'));
131 131
 		$params['match']   = array(
132
-			'description'       => __( 'A partial IP address can be passed and matching results will be returned.', 'woocommerce' ),
132
+			'description'       => __('A partial IP address can be passed and matching results will be returned.', 'woocommerce'),
133 133
 			'type'              => 'string',
134 134
 			'validate_callback' => 'rest_validate_request_arg',
135 135
 		);
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 			'properties' => array(
151 151
 				'user_ip_address' => array(
152 152
 					'type'        => 'string',
153
-					'description' => __( 'IP address.', 'woocommerce' ),
154
-					'context'     => array( 'view' ),
153
+					'description' => __('IP address.', 'woocommerce'),
154
+					'context'     => array('view'),
155 155
 					'readonly'    => true,
156 156
 				),
157 157
 			),
158 158
 		);
159 159
 
160
-		return $this->add_additional_fields_schema( $schema );
160
+		return $this->add_additional_fields_schema($schema);
161 161
 	}
162 162
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/Data/Countries.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Controllers\Version4\Data as DataController;
15 15
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 			array(
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::READABLE,
40
-					'callback'            => array( $this, 'get_items' ),
41
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
+					'callback'            => array($this, 'get_items'),
41
+					'permission_callback' => array($this, 'get_items_permissions_check'),
42 42
 				),
43
-				'schema' => array( $this, 'get_public_item_schema' ),
43
+				'schema' => array($this, 'get_public_item_schema'),
44 44
 			)
45 45
 		);
46 46
 		register_rest_route(
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
 			array(
50 50
 				array(
51 51
 					'methods'             => \WP_REST_Server::READABLE,
52
-					'callback'            => array( $this, 'get_item' ),
53
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
52
+					'callback'            => array($this, 'get_item'),
53
+					'permission_callback' => array($this, 'get_items_permissions_check'),
54 54
 					'args'                => array(
55 55
 						'location' => array(
56
-							'description' => __( 'ISO3166 alpha-2 country code.', 'woocommerce' ),
56
+							'description' => __('ISO3166 alpha-2 country code.', 'woocommerce'),
57 57
 							'type'        => 'string',
58 58
 						),
59 59
 					),
60 60
 				),
61
-				'schema' => array( $this, 'get_public_item_schema' ),
61
+				'schema' => array($this, 'get_public_item_schema'),
62 62
 			)
63 63
 		);
64 64
 	}
@@ -70,23 +70,23 @@  discard block
 block discarded – undo
70 70
 	 * @param  \WP_REST_Request $request      Request data.
71 71
 	 * @return array|mixed Response data, ready for insertion into collection data.
72 72
 	 */
73
-	public function get_country( $country_code = false, $request ) {
73
+	public function get_country($country_code = false, $request) {
74 74
 		$countries = WC()->countries->get_countries();
75 75
 		$states    = WC()->countries->get_states();
76 76
 		$data      = array();
77 77
 
78
-		if ( ! array_key_exists( $country_code, $countries ) ) {
78
+		if ( ! array_key_exists($country_code, $countries)) {
79 79
 			return false;
80 80
 		}
81 81
 
82 82
 		$country = array(
83 83
 			'code' => $country_code,
84
-			'name' => $countries[ $country_code ],
84
+			'name' => $countries[$country_code],
85 85
 		);
86 86
 
87 87
 		$local_states = array();
88
-		if ( isset( $states[ $country_code ] ) ) {
89
-			foreach ( $states[ $country_code ] as $state_code => $state_name ) {
88
+		if (isset($states[$country_code])) {
89
+			foreach ($states[$country_code] as $state_code => $state_name) {
90 90
 				$local_states[] = array(
91 91
 					'code' => $state_code,
92 92
 					'name' => $state_name,
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
 	 * @param  \WP_REST_Request $request Request data.
105 105
 	 * @return \WP_Error\WP_REST_Response
106 106
 	 */
107
-	public function get_items( $request ) {
107
+	public function get_items($request) {
108 108
 		$countries = WC()->countries->get_countries();
109 109
 		$data      = array();
110 110
 
111
-		foreach ( array_keys( $countries ) as $country_code ) {
112
-			$country  = $this->get_country( $country_code, $request );
113
-			$response = $this->prepare_item_for_response( $country, $request );
114
-			$data[]   = $this->prepare_response_for_collection( $response );
111
+		foreach (array_keys($countries) as $country_code) {
112
+			$country  = $this->get_country($country_code, $request);
113
+			$response = $this->prepare_item_for_response($country, $request);
114
+			$data[]   = $this->prepare_response_for_collection($response);
115 115
 		}
116 116
 
117
-		return rest_ensure_response( $data );
117
+		return rest_ensure_response($data);
118 118
 	}
119 119
 
120 120
 	/**
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 	 * @param  \WP_REST_Request $request Request data.
125 125
 	 * @return \WP_Error\WP_REST_Response
126 126
 	 */
127
-	public function get_item( $request ) {
128
-		$data = $this->get_country( strtoupper( $request['location'] ), $request );
129
-		if ( empty( $data ) ) {
130
-			return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
127
+	public function get_item($request) {
128
+		$data = $this->get_country(strtoupper($request['location']), $request);
129
+		if (empty($data)) {
130
+			return new \WP_Error('woocommerce_rest_data_invalid_location', __('There are no locations matching these parameters.', 'woocommerce'), array('status' => 404));
131 131
 		}
132
-		return $this->prepare_item_for_response( $data, $request );
132
+		return $this->prepare_item_for_response($data, $request);
133 133
 	}
134 134
 
135 135
 	/**
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 * @param \WP_REST_Request $request Request object.
141 141
 	 * @return \WP_REST_Response $response Response data.
142 142
 	 */
143
-	public function prepare_item_for_response( $item, $request ) {
144
-		$data     = $this->add_additional_fields_to_object( $item, $request );
145
-		$data     = $this->filter_response_by_context( $data, 'view' );
146
-		$response = rest_ensure_response( $data );
143
+	public function prepare_item_for_response($item, $request) {
144
+		$data     = $this->add_additional_fields_to_object($item, $request);
145
+		$data     = $this->filter_response_by_context($data, 'view');
146
+		$response = rest_ensure_response($data);
147 147
 
148
-		$response->add_links( $this->prepare_links( $item ) );
148
+		$response->add_links($this->prepare_links($item));
149 149
 
150 150
 		/**
151 151
 		 * Filter the states list for a country returned from the API.
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		 * @param array            $data     The original country's states list.
157 157
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
158 158
 		 */
159
-		return apply_filters( 'woocommerce_rest_prepare_data_country', $response, $item, $request );
159
+		return apply_filters('woocommerce_rest_prepare_data_country', $response, $item, $request);
160 160
 	}
161 161
 
162 162
 	/**
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
 	 * @param object $item Data object.
166 166
 	 * @return array Links for the given country.
167 167
 	 */
168
-	protected function prepare_links( $item ) {
169
-		$country_code = strtolower( $item['code'] );
168
+	protected function prepare_links($item) {
169
+		$country_code = strtolower($item['code']);
170 170
 		$links        = array(
171 171
 			'self'       => array(
172
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $country_code ) ),
172
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $country_code)),
173 173
 			),
174 174
 			'collection' => array(
175
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
175
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
176 176
 			),
177 177
 		);
178 178
 
@@ -194,36 +194,36 @@  discard block
 block discarded – undo
194 194
 			'properties' => array(
195 195
 				'code'   => array(
196 196
 					'type'        => 'string',
197
-					'description' => __( 'ISO3166 alpha-2 country code.', 'woocommerce' ),
198
-					'context'     => array( 'view' ),
197
+					'description' => __('ISO3166 alpha-2 country code.', 'woocommerce'),
198
+					'context'     => array('view'),
199 199
 					'readonly'    => true,
200 200
 				),
201 201
 				'name'   => array(
202 202
 					'type'        => 'string',
203
-					'description' => __( 'Full name of country.', 'woocommerce' ),
204
-					'context'     => array( 'view' ),
203
+					'description' => __('Full name of country.', 'woocommerce'),
204
+					'context'     => array('view'),
205 205
 					'readonly'    => true,
206 206
 				),
207 207
 				'states' => array(
208 208
 					'type'        => 'array',
209
-					'description' => __( 'List of states in this country.', 'woocommerce' ),
210
-					'context'     => array( 'view' ),
209
+					'description' => __('List of states in this country.', 'woocommerce'),
210
+					'context'     => array('view'),
211 211
 					'readonly'    => true,
212 212
 					'items'       => array(
213 213
 						'type'       => 'object',
214
-						'context'    => array( 'view' ),
214
+						'context'    => array('view'),
215 215
 						'readonly'   => true,
216 216
 						'properties' => array(
217 217
 							'code' => array(
218 218
 								'type'        => 'string',
219
-								'description' => __( 'State code.', 'woocommerce' ),
220
-								'context'     => array( 'view' ),
219
+								'description' => __('State code.', 'woocommerce'),
220
+								'context'     => array('view'),
221 221
 								'readonly'    => true,
222 222
 							),
223 223
 							'name' => array(
224 224
 								'type'        => 'string',
225
-								'description' => __( 'Full name of state.', 'woocommerce' ),
226
-								'context'     => array( 'view' ),
225
+								'description' => __('Full name of state.', 'woocommerce'),
226
+								'context'     => array('view'),
227 227
 								'readonly'    => true,
228 228
 							),
229 229
 						),
@@ -232,6 +232,6 @@  discard block
 block discarded – undo
232 232
 			),
233 233
 		);
234 234
 
235
-		return $this->add_additional_fields_schema( $schema );
235
+		return $this->add_additional_fields_schema($schema);
236 236
 	}
237 237
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/NetworkOrders.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Controllers\Version4;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Network Orders controller class.
@@ -20,18 +20,18 @@  discard block
 block discarded – undo
20 20
 	 * Register the routes for network orders.
21 21
 	 */
22 22
 	public function register_routes() {
23
-		if ( is_multisite() ) {
23
+		if (is_multisite()) {
24 24
 			register_rest_route(
25 25
 				$this->namespace,
26 26
 				'/' . $this->rest_base . '/network',
27 27
 				array(
28 28
 					array(
29 29
 						'methods'             => \WP_REST_Server::READABLE,
30
-						'callback'            => array( $this, 'network_orders' ),
31
-						'permission_callback' => array( $this, 'network_orders_permissions_check' ),
30
+						'callback'            => array($this, 'network_orders'),
31
+						'permission_callback' => array($this, 'network_orders_permissions_check'),
32 32
 						'args'                => $this->get_collection_params(),
33 33
 					),
34
-					'schema' => array( $this, 'get_public_item_schema' ),
34
+					'schema' => array($this, 'get_public_item_schema'),
35 35
 				),
36 36
 				true
37 37
 			);
@@ -46,34 +46,34 @@  discard block
 block discarded – undo
46 46
 	public function get_public_item_schema() {
47 47
 		$schema = parent::get_public_item_schema();
48 48
 
49
-		$schema['properties']['blog']              = array(
50
-			'description' => __( 'Blog id of the record on the multisite.', 'woocommerce' ),
49
+		$schema['properties']['blog'] = array(
50
+			'description' => __('Blog id of the record on the multisite.', 'woocommerce'),
51 51
 			'type'        => 'integer',
52
-			'context'     => array( 'view' ),
52
+			'context'     => array('view'),
53 53
 			'readonly'    => true,
54 54
 		);
55
-		$schema['properties']['edit_url']          = array(
56
-			'description' => __( 'URL to edit the order', 'woocommerce' ),
55
+		$schema['properties']['edit_url'] = array(
56
+			'description' => __('URL to edit the order', 'woocommerce'),
57 57
 			'type'        => 'string',
58
-			'context'     => array( 'view' ),
58
+			'context'     => array('view'),
59 59
 			'readonly'    => true,
60 60
 		);
61
-		$schema['properties']['customer'][]        = array(
62
-			'description' => __( 'Name of the customer for the order', 'woocommerce' ),
61
+		$schema['properties']['customer'][] = array(
62
+			'description' => __('Name of the customer for the order', 'woocommerce'),
63 63
 			'type'        => 'string',
64
-			'context'     => array( 'view' ),
64
+			'context'     => array('view'),
65 65
 			'readonly'    => true,
66 66
 		);
67
-		$schema['properties']['status_name'][]     = array(
68
-			'description' => __( 'Order Status', 'woocommerce' ),
67
+		$schema['properties']['status_name'][] = array(
68
+			'description' => __('Order Status', 'woocommerce'),
69 69
 			'type'        => 'string',
70
-			'context'     => array( 'view' ),
70
+			'context'     => array('view'),
71 71
 			'readonly'    => true,
72 72
 		);
73 73
 		$schema['properties']['formatted_total'][] = array(
74
-			'description' => __( 'Order total formatted for locale', 'woocommerce' ),
74
+			'description' => __('Order total formatted for locale', 'woocommerce'),
75 75
 			'type'        => 'string',
76
-			'context'     => array( 'view' ),
76
+			'context'     => array('view'),
77 77
 			'readonly'    => true,
78 78
 		);
79 79
 
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
 	 *
88 88
 	 * @return bool $permission
89 89
 	 */
90
-	public function network_orders_permissions_check( $request ) {
91
-		$blog_id = $request->get_param( 'blog_id' );
92
-		$blog_id = ! empty( $blog_id ) ? $blog_id : get_current_blog_id();
90
+	public function network_orders_permissions_check($request) {
91
+		$blog_id = $request->get_param('blog_id');
92
+		$blog_id = ! empty($blog_id) ? $blog_id : get_current_blog_id();
93 93
 
94
-		switch_to_blog( $blog_id );
94
+		switch_to_blog($blog_id);
95 95
 
96
-		$permission = $this->get_items_permissions_check( $request );
96
+		$permission = $this->get_items_permissions_check($request);
97 97
 
98 98
 		restore_current_blog();
99 99
 
@@ -107,39 +107,39 @@  discard block
 block discarded – undo
107 107
 	 *
108 108
 	 * @return \WP_REST_Response
109 109
 	 */
110
-	public function network_orders( $request ) {
111
-		$blog_id = $request->get_param( 'blog_id' );
112
-		$blog_id = ! empty( $blog_id ) ? $blog_id : get_current_blog_id();
113
-		$active_plugins = get_blog_option( $blog_id, 'active_plugins', array() );
114
-		$network_active_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
110
+	public function network_orders($request) {
111
+		$blog_id = $request->get_param('blog_id');
112
+		$blog_id = ! empty($blog_id) ? $blog_id : get_current_blog_id();
113
+		$active_plugins = get_blog_option($blog_id, 'active_plugins', array());
114
+		$network_active_plugins = array_keys(get_site_option('active_sitewide_plugins', array()));
115 115
 
116
-		$plugins = array_merge( $active_plugins, $network_active_plugins );
116
+		$plugins = array_merge($active_plugins, $network_active_plugins);
117 117
 		$wc_active = false;
118
-		foreach ( $plugins as $plugin ) {
119
-			if ( substr_compare( $plugin, '/woocommerce.php', strlen( $plugin ) - strlen( '/woocommerce.php' ), strlen( '/woocommerce.php' ) ) === 0 ) {
118
+		foreach ($plugins as $plugin) {
119
+			if (substr_compare($plugin, '/woocommerce.php', strlen($plugin) - strlen('/woocommerce.php'), strlen('/woocommerce.php')) === 0) {
120 120
 				$wc_active = true;
121 121
 			}
122 122
 		}
123 123
 
124 124
 		// If WooCommerce not active for site, return an empty response.
125
-		if ( ! $wc_active ) {
126
-			$response = rest_ensure_response( array() );
125
+		if ( ! $wc_active) {
126
+			$response = rest_ensure_response(array());
127 127
 			return $response;
128 128
 		}
129 129
 
130
-		switch_to_blog( $blog_id );
131
-		add_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) );
132
-		$items = $this->get_items( $request );
133
-		remove_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) );
130
+		switch_to_blog($blog_id);
131
+		add_filter('woocommerce_rest_orders_prepare_object_query', array($this, 'network_orders_filter_args'));
132
+		$items = $this->get_items($request);
133
+		remove_filter('woocommerce_rest_orders_prepare_object_query', array($this, 'network_orders_filter_args'));
134 134
 
135
-		foreach ( $items->data as &$current_order ) {
136
-			$order = wc_get_order( $current_order['id'] );
135
+		foreach ($items->data as &$current_order) {
136
+			$order = wc_get_order($current_order['id']);
137 137
 
138
-			$current_order['blog']     = get_blog_details( get_current_blog_id() );
139
-			$current_order['edit_url'] = get_admin_url( $blog_id, 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' );
138
+			$current_order['blog']     = get_blog_details(get_current_blog_id());
139
+			$current_order['edit_url'] = get_admin_url($blog_id, 'post.php?post=' . absint($order->get_id()) . '&action=edit');
140 140
 			/* translators: 1: first name 2: last name */
141
-			$current_order['customer']        = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) );
142
-			$current_order['status_name']     = wc_get_order_status_name( $order->get_status() );
141
+			$current_order['customer']        = trim(sprintf(_x('%1$s %2$s', 'full name', 'woocommerce'), $order->get_billing_first_name(), $order->get_billing_last_name()));
142
+			$current_order['status_name']     = wc_get_order_status_name($order->get_status());
143 143
 			$current_order['formatted_total'] = $order->get_formatted_order_total();
144 144
 		}
145 145
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 *
156 156
 	 * @return array
157 157
 	 */
158
-	public function network_orders_filter_args( $args ) {
158
+	public function network_orders_filter_args($args) {
159 159
 		$args['post_status'] = array(
160 160
 			'wc-on-hold',
161 161
 			'wc-processing',
Please login to merge, or discard this patch.
src/Controllers/Version4/AbstractObjectsController.php 1 patch
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\Controllers\Version4;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * CRUD Object Controller.
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 	 * @param  int $id Object ID.
28 28
 	 * @return object WC_Data object or \WP_Error object.
29 29
 	 */
30
-	protected function get_object( $id ) {
30
+	protected function get_object($id) {
31 31
 		// translators: %s: Class method name.
32
-		return new \WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
32
+		return new \WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce'), __METHOD__), array('status' => 405));
33 33
 	}
34 34
 
35 35
 	/**
@@ -38,11 +38,11 @@  discard block
 block discarded – undo
38 38
 	 * @param  \WP_REST_Request $request Full details about the request.
39 39
 	 * @return \WP_Error|boolean
40 40
 	 */
41
-	public function get_item_permissions_check( $request ) {
42
-		$object = $this->get_object( (int) $request['id'] );
41
+	public function get_item_permissions_check($request) {
42
+		$object = $this->get_object((int) $request['id']);
43 43
 
44
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) {
45
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
44
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'read', $object->get_id())) {
45
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
46 46
 		}
47 47
 
48 48
 		return true;
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 	 * @param  \WP_REST_Request $request Full details about the request.
55 55
 	 * @return \WP_Error|boolean
56 56
 	 */
57
-	public function update_item_permissions_check( $request ) {
58
-		$object = $this->get_object( (int) $request['id'] );
57
+	public function update_item_permissions_check($request) {
58
+		$object = $this->get_object((int) $request['id']);
59 59
 
60
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
61
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
60
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'edit', $object->get_id())) {
61
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
62 62
 		}
63 63
 
64 64
 		return true;
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
 	 * @param  \WP_REST_Request $request Full details about the request.
71 71
 	 * @return bool|\WP_Error
72 72
 	 */
73
-	public function delete_item_permissions_check( $request ) {
74
-		$object = $this->get_object( (int) $request['id'] );
73
+	public function delete_item_permissions_check($request) {
74
+		$object = $this->get_object((int) $request['id']);
75 75
 
76
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
77
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
76
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
77
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
78 78
 		}
79 79
 
80 80
 		return true;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 * @param  object $object Object.
87 87
 	 * @return string
88 88
 	 */
89
-	protected function get_permalink( $object ) {
89
+	protected function get_permalink($object) {
90 90
 		return '';
91 91
 	}
92 92
 
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 	 * @param  \WP_REST_Request $request Request object.
99 99
 	 * @return \WP_Error|\WP_REST_Response Response object on success, or \WP_Error object on failure.
100 100
 	 */
101
-	protected function prepare_object_for_response( $object, $request ) {
101
+	protected function prepare_object_for_response($object, $request) {
102 102
 		// translators: %s: Class method name.
103
-		return new \WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
103
+		return new \WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce'), __METHOD__), array('status' => 405));
104 104
 	}
105 105
 
106 106
 	/**
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 	 * @param  bool            $creating If is creating a new object.
112 112
 	 * @return \WP_Error|WC_Data The prepared item, or \WP_Error object on failure.
113 113
 	 */
114
-	protected function prepare_object_for_database( $request, $creating = false ) {
114
+	protected function prepare_object_for_database($request, $creating = false) {
115 115
 		// translators: %s: Class method name.
116
-		return new \WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
116
+		return new \WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce'), __METHOD__), array('status' => 405));
117 117
 	}
118 118
 
119 119
 	/**
@@ -122,18 +122,18 @@  discard block
 block discarded – undo
122 122
 	 * @param \WP_REST_Request $request Full details about the request.
123 123
 	 * @return \WP_Error|\WP_REST_Response
124 124
 	 */
125
-	public function get_item( $request ) {
126
-		$object = $this->get_object( (int) $request['id'] );
125
+	public function get_item($request) {
126
+		$object = $this->get_object((int) $request['id']);
127 127
 
128
-		if ( ! $object || 0 === $object->get_id() ) {
129
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
128
+		if ( ! $object || 0 === $object->get_id()) {
129
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
130 130
 		}
131 131
 
132
-		$data     = $this->prepare_object_for_response( $object, $request );
133
-		$response = rest_ensure_response( $data );
132
+		$data     = $this->prepare_object_for_response($object, $request);
133
+		$response = rest_ensure_response($data);
134 134
 
135
-		if ( $this->public ) {
136
-			$response->link_header( 'alternate', $this->get_permalink( $object ), array( 'type' => 'text/html' ) );
135
+		if ($this->public) {
136
+			$response->link_header('alternate', $this->get_permalink($object), array('type' => 'text/html'));
137 137
 		}
138 138
 
139 139
 		return $response;
@@ -147,21 +147,21 @@  discard block
 block discarded – undo
147 147
 	 * @param  bool            $creating If is creating a new object.
148 148
 	 * @return WC_Data|\WP_Error
149 149
 	 */
150
-	protected function save_object( $request, $creating = false ) {
150
+	protected function save_object($request, $creating = false) {
151 151
 		try {
152
-			$object = $this->prepare_object_for_database( $request, $creating );
152
+			$object = $this->prepare_object_for_database($request, $creating);
153 153
 
154
-			if ( is_wp_error( $object ) ) {
154
+			if (is_wp_error($object)) {
155 155
 				return $object;
156 156
 			}
157 157
 
158 158
 			$object->save();
159 159
 
160
-			return $this->get_object( $object->get_id() );
161
-		} catch ( \WC_Data_Exception $e ) {
162
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
163
-		} catch ( \WC_REST_Exception $e ) {
164
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
160
+			return $this->get_object($object->get_id());
161
+		} catch (\WC_Data_Exception $e) {
162
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
163
+		} catch (\WC_REST_Exception $e) {
164
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
165 165
 		}
166 166
 	}
167 167
 
@@ -171,26 +171,26 @@  discard block
 block discarded – undo
171 171
 	 * @param \WP_REST_Request $request Full details about the request.
172 172
 	 * @return \WP_Error\WP_REST_Response
173 173
 	 */
174
-	public function create_item( $request ) {
175
-		if ( ! empty( $request['id'] ) ) {
174
+	public function create_item($request) {
175
+		if ( ! empty($request['id'])) {
176 176
 			/* translators: %s: post type */
177
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
177
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
178 178
 		}
179 179
 
180
-		$object = $this->save_object( $request, true );
180
+		$object = $this->save_object($request, true);
181 181
 
182
-		if ( is_wp_error( $object ) ) {
182
+		if (is_wp_error($object)) {
183 183
 			return $object;
184 184
 		}
185 185
 
186 186
 		try {
187
-			$this->update_additional_fields_for_object( $object, $request );
188
-		} catch ( \WC_Data_Exception $e ) {
187
+			$this->update_additional_fields_for_object($object, $request);
188
+		} catch (\WC_Data_Exception $e) {
189 189
 			$object->delete();
190
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
191
-		} catch ( \WC_REST_Exception $e ) {
190
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
191
+		} catch (\WC_REST_Exception $e) {
192 192
 			$object->delete();
193
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
193
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
194 194
 		}
195 195
 
196 196
 		/**
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
 		 * @param \WP_REST_Request $request   Request object.
201 201
 		 * @param boolean         $creating  True when creating object, false when updating.
202 202
 		 */
203
-		do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, true );
203
+		do_action("woocommerce_rest_insert_{$this->post_type}_object", $object, $request, true);
204 204
 
205
-		$request->set_param( 'context', 'edit' );
206
-		$response = $this->prepare_object_for_response( $object, $request );
207
-		$response = rest_ensure_response( $response );
208
-		$response->set_status( 201 );
209
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ) );
205
+		$request->set_param('context', 'edit');
206
+		$response = $this->prepare_object_for_response($object, $request);
207
+		$response = rest_ensure_response($response);
208
+		$response->set_status(201);
209
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())));
210 210
 
211 211
 		return $response;
212 212
 	}
@@ -217,25 +217,25 @@  discard block
 block discarded – undo
217 217
 	 * @param \WP_REST_Request $request Full details about the request.
218 218
 	 * @return \WP_Error\WP_REST_Response
219 219
 	 */
220
-	public function update_item( $request ) {
221
-		$object = $this->get_object( (int) $request['id'] );
220
+	public function update_item($request) {
221
+		$object = $this->get_object((int) $request['id']);
222 222
 
223
-		if ( ! $object || 0 === $object->get_id() ) {
224
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
223
+		if ( ! $object || 0 === $object->get_id()) {
224
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
225 225
 		}
226 226
 
227
-		$object = $this->save_object( $request, false );
227
+		$object = $this->save_object($request, false);
228 228
 
229
-		if ( is_wp_error( $object ) ) {
229
+		if (is_wp_error($object)) {
230 230
 			return $object;
231 231
 		}
232 232
 
233 233
 		try {
234
-			$this->update_additional_fields_for_object( $object, $request );
235
-		} catch ( \WC_Data_Exception $e ) {
236
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
237
-		} catch ( \WC_REST_Exception $e ) {
238
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
234
+			$this->update_additional_fields_for_object($object, $request);
235
+		} catch (\WC_Data_Exception $e) {
236
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
237
+		} catch (\WC_REST_Exception $e) {
238
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
239 239
 		}
240 240
 
241 241
 		/**
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
 		 * @param \WP_REST_Request $request   Request object.
246 246
 		 * @param boolean         $creating  True when creating object, false when updating.
247 247
 		 */
248
-		do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, false );
248
+		do_action("woocommerce_rest_insert_{$this->post_type}_object", $object, $request, false);
249 249
 
250
-		$request->set_param( 'context', 'edit' );
251
-		$response = $this->prepare_object_for_response( $object, $request );
252
-		return rest_ensure_response( $response );
250
+		$request->set_param('context', 'edit');
251
+		$response = $this->prepare_object_for_response($object, $request);
252
+		return rest_ensure_response($response);
253 253
 	}
254 254
 
255 255
 	/**
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 * @param  \WP_REST_Request $request Full details about the request.
260 260
 	 * @return array
261 261
 	 */
262
-	protected function prepare_objects_query( $request ) {
262
+	protected function prepare_objects_query($request) {
263 263
 		$args                        = array();
264 264
 		$args['offset']              = $request['offset'];
265 265
 		$args['order']               = $request['order'];
@@ -274,18 +274,18 @@  discard block
 block discarded – undo
274 274
 		$args['s']                   = $request['search'];
275 275
 		$args['fields']              = 'ids';
276 276
 
277
-		if ( 'date' === $args['orderby'] ) {
277
+		if ('date' === $args['orderby']) {
278 278
 			$args['orderby'] = 'date ID';
279 279
 		}
280 280
 
281 281
 		$args['date_query'] = array();
282 282
 		// Set before into date query. Date query must be specified as an array of an array.
283
-		if ( isset( $request['before'] ) ) {
283
+		if (isset($request['before'])) {
284 284
 			$args['date_query'][0]['before'] = $request['before'];
285 285
 		}
286 286
 
287 287
 		// Set after into date query. Date query must be specified as an array of an array.
288
-		if ( isset( $request['after'] ) ) {
288
+		if (isset($request['after'])) {
289 289
 			$args['date_query'][0]['after'] = $request['after'];
290 290
 		}
291 291
 
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
 		 * @param array           $args    Key value array of query var to query value.
302 302
 		 * @param \WP_REST_Request $request The request used.
303 303
 		 */
304
-		$args = apply_filters( "woocommerce_rest_{$this->post_type}_object_query", $args, $request );
304
+		$args = apply_filters("woocommerce_rest_{$this->post_type}_object_query", $args, $request);
305 305
 
306
-		return $this->prepare_items_query( $args, $request );
306
+		return $this->prepare_items_query($args, $request);
307 307
 	}
308 308
 
309 309
 	/**
@@ -313,23 +313,23 @@  discard block
 block discarded – undo
313 313
 	 * @param  array $query_args Query args.
314 314
 	 * @return array
315 315
 	 */
316
-	protected function get_objects( $query_args ) {
316
+	protected function get_objects($query_args) {
317 317
 		$query  = new \WP_Query();
318
-		$result = $query->query( $query_args );
318
+		$result = $query->query($query_args);
319 319
 
320 320
 		$total_posts = $query->found_posts;
321
-		if ( $total_posts < 1 ) {
321
+		if ($total_posts < 1) {
322 322
 			// Out-of-bounds, run the query again without LIMIT for total count.
323
-			unset( $query_args['paged'] );
323
+			unset($query_args['paged']);
324 324
 			$count_query = new \WP_Query();
325
-			$count_query->query( $query_args );
325
+			$count_query->query($query_args);
326 326
 			$total_posts = $count_query->found_posts;
327 327
 		}
328 328
 
329 329
 		return array(
330
-			'objects' => array_map( array( $this, 'get_object' ), $result ),
330
+			'objects' => array_map(array($this, 'get_object'), $result),
331 331
 			'total'   => (int) $total_posts,
332
-			'pages'   => (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ),
332
+			'pages'   => (int) ceil($total_posts / (int) $query->query_vars['posts_per_page']),
333 333
 		);
334 334
 	}
335 335
 
@@ -339,55 +339,55 @@  discard block
 block discarded – undo
339 339
 	 * @param \WP_REST_Request $request Full details about the request.
340 340
 	 * @return \WP_Error\WP_REST_Response
341 341
 	 */
342
-	public function get_items( $request ) {
343
-		$query_args    = $this->prepare_objects_query( $request );
344
-		$query_results = $this->get_objects( $query_args );
342
+	public function get_items($request) {
343
+		$query_args    = $this->prepare_objects_query($request);
344
+		$query_results = $this->get_objects($query_args);
345 345
 
346 346
 		$objects = array();
347
-		foreach ( $query_results['objects'] as $object ) {
348
-			if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) {
347
+		foreach ($query_results['objects'] as $object) {
348
+			if ( ! wc_rest_check_post_permissions($this->post_type, 'read', $object->get_id())) {
349 349
 				continue;
350 350
 			}
351 351
 
352
-			$data      = $this->prepare_object_for_response( $object, $request );
353
-			$objects[] = $this->prepare_response_for_collection( $data );
352
+			$data      = $this->prepare_object_for_response($object, $request);
353
+			$objects[] = $this->prepare_response_for_collection($data);
354 354
 		}
355 355
 
356 356
 		$page      = (int) $query_args['paged'];
357 357
 		$max_pages = $query_results['pages'];
358 358
 
359
-		$response = rest_ensure_response( $objects );
360
-		$response->header( 'X-WP-Total', $query_results['total'] );
361
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
359
+		$response = rest_ensure_response($objects);
360
+		$response->header('X-WP-Total', $query_results['total']);
361
+		$response->header('X-WP-TotalPages', (int) $max_pages);
362 362
 
363 363
 		$base          = $this->rest_base;
364 364
 		$attrib_prefix = '(?P<';
365
-		if ( strpos( $base, $attrib_prefix ) !== false ) {
365
+		if (strpos($base, $attrib_prefix) !== false) {
366 366
 			$attrib_names = array();
367
-			preg_match( '/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE );
368
-			foreach ( $attrib_names as $attrib_name_match ) {
369
-				$beginning_offset = strlen( $attrib_prefix );
370
-				$attrib_name_end  = strpos( $attrib_name_match[0], '>', $attrib_name_match[1] );
371
-				$attrib_name      = substr( $attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset );
372
-				if ( isset( $request[ $attrib_name ] ) ) {
373
-					$base  = str_replace( "(?P<$attrib_name>[\d]+)", $request[ $attrib_name ], $base );
367
+			preg_match('/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE);
368
+			foreach ($attrib_names as $attrib_name_match) {
369
+				$beginning_offset = strlen($attrib_prefix);
370
+				$attrib_name_end  = strpos($attrib_name_match[0], '>', $attrib_name_match[1]);
371
+				$attrib_name      = substr($attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset);
372
+				if (isset($request[$attrib_name])) {
373
+					$base = str_replace("(?P<$attrib_name>[\d]+)", $request[$attrib_name], $base);
374 374
 				}
375 375
 			}
376 376
 		}
377
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ) );
377
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $base)));
378 378
 
379
-		if ( $page > 1 ) {
379
+		if ($page > 1) {
380 380
 			$prev_page = $page - 1;
381
-			if ( $prev_page > $max_pages ) {
381
+			if ($prev_page > $max_pages) {
382 382
 				$prev_page = $max_pages;
383 383
 			}
384
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
385
-			$response->link_header( 'prev', $prev_link );
384
+			$prev_link = add_query_arg('page', $prev_page, $base);
385
+			$response->link_header('prev', $prev_link);
386 386
 		}
387
-		if ( $max_pages > $page ) {
387
+		if ($max_pages > $page) {
388 388
 			$next_page = $page + 1;
389
-			$next_link = add_query_arg( 'page', $next_page, $base );
390
-			$response->link_header( 'next', $next_link );
389
+			$next_link = add_query_arg('page', $next_page, $base);
390
+			$response->link_header('next', $next_link);
391 391
 		}
392 392
 
393 393
 		return $response;
@@ -399,49 +399,49 @@  discard block
 block discarded – undo
399 399
 	 * @param \WP_REST_Request $request Full details about the request.
400 400
 	 * @return \WP_REST_Response|\WP_Error
401 401
 	 */
402
-	public function delete_item( $request ) {
402
+	public function delete_item($request) {
403 403
 		$force  = (bool) $request['force'];
404
-		$object = $this->get_object( (int) $request['id'] );
404
+		$object = $this->get_object((int) $request['id']);
405 405
 		$result = false;
406 406
 
407
-		if ( ! $object || 0 === $object->get_id() ) {
408
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
407
+		if ( ! $object || 0 === $object->get_id()) {
408
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
409 409
 		}
410 410
 
411
-		$supports_trash = $this->supports_trash( $object );
411
+		$supports_trash = $this->supports_trash($object);
412 412
 
413
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
413
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
414 414
 			/* translators: %s: post type */
415
-			return new \WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( 'status' => rest_authorization_required_code() ) );
415
+			return new \WP_Error("woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array('status' => rest_authorization_required_code()));
416 416
 		}
417 417
 
418
-		$request->set_param( 'context', 'edit' );
419
-		$previous = $this->prepare_object_for_response( $object, $request );
418
+		$request->set_param('context', 'edit');
419
+		$previous = $this->prepare_object_for_response($object, $request);
420 420
 
421 421
 		// If we're forcing, then delete permanently.
422
-		if ( $force ) {
423
-			$object->delete( true );
422
+		if ($force) {
423
+			$object->delete(true);
424 424
 			$result = 0 === $object->get_id();
425 425
 		} else {
426 426
 			// If we don't support trashing for this type, error out.
427
-			if ( ! $supports_trash ) {
427
+			if ( ! $supports_trash) {
428 428
 				/* translators: %s: post type */
429
-				return new \WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) );
429
+				return new \WP_Error('woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array('status' => 501));
430 430
 			}
431 431
 
432 432
 			// Otherwise, only trash if we haven't already.
433
-			if ( is_callable( array( $object, 'get_status' ) ) && 'trash' === $object->get_status() ) {
433
+			if (is_callable(array($object, 'get_status')) && 'trash' === $object->get_status()) {
434 434
 				/* translators: %s: post type */
435
-				return new \WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) );
435
+				return new \WP_Error('woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array('status' => 410));
436 436
 			} else {
437 437
 				$object->delete();
438
-				$result = is_callable( array( $object, 'get_status' ) ) ? 'trash' === $object->get_status() : true;
438
+				$result = is_callable(array($object, 'get_status')) ? 'trash' === $object->get_status() : true;
439 439
 			}
440 440
 		}
441 441
 
442
-		if ( ! $result ) {
442
+		if ( ! $result) {
443 443
 			/* translators: %s: post type */
444
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
444
+			return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500));
445 445
 		}
446 446
 
447 447
 		$response = new \WP_REST_Response();
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 		 * @param \WP_REST_Response $response The response data.
460 460
 		 * @param \WP_REST_Request  $request  The request sent to the API.
461 461
 		 */
462
-		do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );
462
+		do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request);
463 463
 
464 464
 		return $response;
465 465
 	}
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 	 * @oaram  object $object Object to check.
471 471
 	 * @return boolean
472 472
 	 */
473
-	protected function supports_trash( $object ) {
473
+	protected function supports_trash($object) {
474 474
 		$supports_trash = EMPTY_TRASH_DAYS > 0;
475 475
 
476 476
 		/**
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 		 * @param boolean $supports_trash Whether the object type support trashing.
482 482
 		 * @param WC_Data $object         The object being considered for trashing support.
483 483
 		 */
484
-		return apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object );
484
+		return apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object);
485 485
 	}
486 486
 
487 487
 	/**
@@ -491,13 +491,13 @@  discard block
 block discarded – undo
491 491
 	 * @param \WP_REST_Request $request Request object.
492 492
 	 * @return array                   Links for the given post.
493 493
 	 */
494
-	protected function prepare_links( $object, $request ) {
494
+	protected function prepare_links($object, $request) {
495 495
 		$links = array(
496 496
 			'self' => array(
497
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),
497
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())),
498 498
 			),
499 499
 			'collection' => array(
500
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
500
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
501 501
 			),
502 502
 		);
503 503
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 		$params['context']['default'] = 'view';
516 516
 
517 517
 		$params['page'] = array(
518
-			'description'        => __( 'Current page of the collection.', 'woocommerce' ),
518
+			'description'        => __('Current page of the collection.', 'woocommerce'),
519 519
 			'type'               => 'integer',
520 520
 			'default'            => 1,
521 521
 			'sanitize_callback'  => 'absint',
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
 			'minimum'            => 1,
524 524
 		);
525 525
 		$params['per_page'] = array(
526
-			'description'        => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
526
+			'description'        => __('Maximum number of items to be returned in result set.', 'woocommerce'),
527 527
 			'type'               => 'integer',
528 528
 			'default'            => 10,
529 529
 			'minimum'            => 1,
@@ -532,25 +532,25 @@  discard block
 block discarded – undo
532 532
 			'validate_callback'  => 'rest_validate_request_arg',
533 533
 		);
534 534
 		$params['search'] = array(
535
-			'description'        => __( 'Limit results to those matching a string.', 'woocommerce' ),
535
+			'description'        => __('Limit results to those matching a string.', 'woocommerce'),
536 536
 			'type'               => 'string',
537 537
 			'sanitize_callback'  => 'sanitize_text_field',
538 538
 			'validate_callback'  => 'rest_validate_request_arg',
539 539
 		);
540 540
 		$params['after'] = array(
541
-			'description'        => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
541
+			'description'        => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
542 542
 			'type'               => 'string',
543 543
 			'format'             => 'date-time',
544 544
 			'validate_callback'  => 'rest_validate_request_arg',
545 545
 		);
546 546
 		$params['before'] = array(
547
-			'description'        => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
547
+			'description'        => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
548 548
 			'type'               => 'string',
549 549
 			'format'             => 'date-time',
550 550
 			'validate_callback'  => 'rest_validate_request_arg',
551 551
 		);
552 552
 		$params['exclude'] = array(
553
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
553
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
554 554
 			'type'              => 'array',
555 555
 			'items'             => array(
556 556
 				'type'          => 'integer',
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 			'sanitize_callback' => 'wp_parse_id_list',
560 560
 		);
561 561
 		$params['include'] = array(
562
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
562
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
563 563
 			'type'              => 'array',
564 564
 			'items'             => array(
565 565
 				'type'          => 'integer',
@@ -568,20 +568,20 @@  discard block
 block discarded – undo
568 568
 			'sanitize_callback' => 'wp_parse_id_list',
569 569
 		);
570 570
 		$params['offset'] = array(
571
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
571
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
572 572
 			'type'               => 'integer',
573 573
 			'sanitize_callback'  => 'absint',
574 574
 			'validate_callback'  => 'rest_validate_request_arg',
575 575
 		);
576 576
 		$params['order'] = array(
577
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
577
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
578 578
 			'type'               => 'string',
579 579
 			'default'            => 'desc',
580
-			'enum'               => array( 'asc', 'desc' ),
580
+			'enum'               => array('asc', 'desc'),
581 581
 			'validate_callback'  => 'rest_validate_request_arg',
582 582
 		);
583 583
 		$params['orderby'] = array(
584
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
584
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
585 585
 			'type'               => 'string',
586 586
 			'default'            => 'date',
587 587
 			'enum'               => array(
@@ -594,9 +594,9 @@  discard block
 block discarded – undo
594 594
 			'validate_callback'  => 'rest_validate_request_arg',
595 595
 		);
596 596
 
597
-		if ( $this->hierarchical ) {
597
+		if ($this->hierarchical) {
598 598
 			$params['parent'] = array(
599
-				'description'       => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
599
+				'description'       => __('Limit result set to those of particular parent IDs.', 'woocommerce'),
600 600
 				'type'              => 'array',
601 601
 				'items'             => array(
602 602
 					'type'          => 'integer',
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 				'default'           => array(),
606 606
 			);
607 607
 			$params['parent_exclude'] = array(
608
-				'description'       => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
608
+				'description'       => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'),
609 609
 				'type'              => 'array',
610 610
 				'items'             => array(
611 611
 					'type'          => 'integer',
@@ -628,6 +628,6 @@  discard block
 block discarded – undo
628 628
 		 * @param array        $query_params JSON Schema-formatted collection parameters.
629 629
 		 * @param WP_Post_Type $post_type    Post type object.
630 630
 		 */
631
-		return apply_filters( "rest_{$this->post_type}_collection_params", $params, $this->post_type );
631
+		return apply_filters("rest_{$this->post_type}_collection_params", $params, $this->post_type);
632 632
 	}
633 633
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/AbstractTermsContoller.php 1 patch
Spacing   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\Controllers\Version4;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * Terms controller class.
@@ -38,26 +38,26 @@  discard block
 block discarded – undo
38 38
 			array(
39 39
 				array(
40 40
 					'methods'             => \WP_REST_Server::READABLE,
41
-					'callback'            => array( $this, 'get_items' ),
42
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
41
+					'callback'            => array($this, 'get_items'),
42
+					'permission_callback' => array($this, 'get_items_permissions_check'),
43 43
 					'args'                => $this->get_collection_params(),
44 44
 				),
45 45
 				array(
46 46
 					'methods'             => \WP_REST_Server::CREATABLE,
47
-					'callback'            => array( $this, 'create_item' ),
48
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
47
+					'callback'            => array($this, 'create_item'),
48
+					'permission_callback' => array($this, 'create_item_permissions_check'),
49 49
 					'args'                => array_merge(
50
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
50
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
51 51
 						array(
52 52
 							'name' => array(
53 53
 								'type'        => 'string',
54
-								'description' => __( 'Name for the resource.', 'woocommerce' ),
54
+								'description' => __('Name for the resource.', 'woocommerce'),
55 55
 								'required'    => true,
56 56
 							),
57 57
 						)
58 58
 					),
59 59
 				),
60
-				'schema' => array( $this, 'get_public_item_schema' ),
60
+				'schema' => array($this, 'get_public_item_schema'),
61 61
 			),
62 62
 			true
63 63
 		);
@@ -68,37 +68,37 @@  discard block
 block discarded – undo
68 68
 			array(
69 69
 				'args'   => array(
70 70
 					'id' => array(
71
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
71
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
72 72
 						'type'        => 'integer',
73 73
 					),
74 74
 				),
75 75
 				array(
76 76
 					'methods'             => \WP_REST_Server::READABLE,
77
-					'callback'            => array( $this, 'get_item' ),
78
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
77
+					'callback'            => array($this, 'get_item'),
78
+					'permission_callback' => array($this, 'get_item_permissions_check'),
79 79
 					'args'                => array(
80
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
80
+						'context' => $this->get_context_param(array('default' => 'view')),
81 81
 					),
82 82
 				),
83 83
 				array(
84 84
 					'methods'             => \WP_REST_Server::EDITABLE,
85
-					'callback'            => array( $this, 'update_item' ),
86
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
87
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
85
+					'callback'            => array($this, 'update_item'),
86
+					'permission_callback' => array($this, 'update_item_permissions_check'),
87
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
88 88
 				),
89 89
 				array(
90 90
 					'methods'             => \WP_REST_Server::DELETABLE,
91
-					'callback'            => array( $this, 'delete_item' ),
92
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
91
+					'callback'            => array($this, 'delete_item'),
92
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
93 93
 					'args'                => array(
94 94
 						'force' => array(
95 95
 							'default'     => false,
96 96
 							'type'        => 'boolean',
97
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
97
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
98 98
 						),
99 99
 					),
100 100
 				),
101
-				'schema' => array( $this, 'get_public_item_schema' ),
101
+				'schema' => array($this, 'get_public_item_schema'),
102 102
 			),
103 103
 			true
104 104
 		);
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 			array(
110 110
 				array(
111 111
 					'methods'             => \WP_REST_Server::EDITABLE,
112
-					'callback'            => array( $this, 'batch_items' ),
113
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
114
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
112
+					'callback'            => array($this, 'batch_items'),
113
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
114
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
115 115
 				),
116
-				'schema' => array( $this, 'get_public_batch_schema' ),
116
+				'schema' => array($this, 'get_public_batch_schema'),
117 117
 			),
118 118
 			true
119 119
 		);
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
 	 * @param  \WP_REST_Request $request Full details about the request.
126 126
 	 * @return \WP_Error|boolean
127 127
 	 */
128
-	public function get_items_permissions_check( $request ) {
129
-		$permissions = $this->check_permissions( $request, 'read' );
130
-		if ( is_wp_error( $permissions ) ) {
128
+	public function get_items_permissions_check($request) {
129
+		$permissions = $this->check_permissions($request, 'read');
130
+		if (is_wp_error($permissions)) {
131 131
 			return $permissions;
132 132
 		}
133 133
 
134
-		if ( ! $permissions ) {
135
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
134
+		if ( ! $permissions) {
135
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
136 136
 		}
137 137
 
138 138
 		return true;
@@ -144,14 +144,14 @@  discard block
 block discarded – undo
144 144
 	 * @param  \WP_REST_Request $request Full details about the request.
145 145
 	 * @return \WP_Error|boolean
146 146
 	 */
147
-	public function create_item_permissions_check( $request ) {
148
-		$permissions = $this->check_permissions( $request, 'create' );
149
-		if ( is_wp_error( $permissions ) ) {
147
+	public function create_item_permissions_check($request) {
148
+		$permissions = $this->check_permissions($request, 'create');
149
+		if (is_wp_error($permissions)) {
150 150
 			return $permissions;
151 151
 		}
152 152
 
153
-		if ( ! $permissions ) {
154
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
153
+		if ( ! $permissions) {
154
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
155 155
 		}
156 156
 
157 157
 		return true;
@@ -163,14 +163,14 @@  discard block
 block discarded – undo
163 163
 	 * @param  \WP_REST_Request $request Full details about the request.
164 164
 	 * @return \WP_Error|boolean
165 165
 	 */
166
-	public function get_item_permissions_check( $request ) {
167
-		$permissions = $this->check_permissions( $request, 'read' );
168
-		if ( is_wp_error( $permissions ) ) {
166
+	public function get_item_permissions_check($request) {
167
+		$permissions = $this->check_permissions($request, 'read');
168
+		if (is_wp_error($permissions)) {
169 169
 			return $permissions;
170 170
 		}
171 171
 
172
-		if ( ! $permissions ) {
173
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
172
+		if ( ! $permissions) {
173
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
174 174
 		}
175 175
 
176 176
 		return true;
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 	 * @param  \WP_REST_Request $request Full details about the request.
183 183
 	 * @return \WP_Error|boolean
184 184
 	 */
185
-	public function update_item_permissions_check( $request ) {
186
-		$permissions = $this->check_permissions( $request, 'edit' );
187
-		if ( is_wp_error( $permissions ) ) {
185
+	public function update_item_permissions_check($request) {
186
+		$permissions = $this->check_permissions($request, 'edit');
187
+		if (is_wp_error($permissions)) {
188 188
 			return $permissions;
189 189
 		}
190 190
 
191
-		if ( ! $permissions ) {
192
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
191
+		if ( ! $permissions) {
192
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
193 193
 		}
194 194
 
195 195
 		return true;
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
 	 * @param  \WP_REST_Request $request Full details about the request.
202 202
 	 * @return \WP_Error|boolean
203 203
 	 */
204
-	public function delete_item_permissions_check( $request ) {
205
-		$permissions = $this->check_permissions( $request, 'delete' );
206
-		if ( is_wp_error( $permissions ) ) {
204
+	public function delete_item_permissions_check($request) {
205
+		$permissions = $this->check_permissions($request, 'delete');
206
+		if (is_wp_error($permissions)) {
207 207
 			return $permissions;
208 208
 		}
209 209
 
210
-		if ( ! $permissions ) {
211
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
210
+		if ( ! $permissions) {
211
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
212 212
 		}
213 213
 
214 214
 		return true;
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
 	 * @param  \WP_REST_Request $request Full details about the request.
221 221
 	 * @return boolean|\WP_Error
222 222
 	 */
223
-	public function batch_items_permissions_check( $request ) {
224
-		$permissions = $this->check_permissions( $request, 'batch' );
225
-		if ( is_wp_error( $permissions ) ) {
223
+	public function batch_items_permissions_check($request) {
224
+		$permissions = $this->check_permissions($request, 'batch');
225
+		if (is_wp_error($permissions)) {
226 226
 			return $permissions;
227 227
 		}
228 228
 
229
-		if ( ! $permissions ) {
230
-			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() ) );
229
+		if ( ! $permissions) {
230
+			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()));
231 231
 		}
232 232
 
233 233
 		return true;
@@ -240,26 +240,26 @@  discard block
 block discarded – undo
240 240
 	 * @param string          $context Request context.
241 241
 	 * @return bool|\WP_Error
242 242
 	 */
243
-	protected function check_permissions( $request, $context = 'read' ) {
243
+	protected function check_permissions($request, $context = 'read') {
244 244
 		// Get taxonomy.
245
-		$taxonomy = $this->get_taxonomy( $request );
246
-		if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) {
247
-			return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
245
+		$taxonomy = $this->get_taxonomy($request);
246
+		if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) {
247
+			return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Taxonomy does not exist.', 'woocommerce'), array('status' => 404));
248 248
 		}
249 249
 
250 250
 		// Check permissions for a single term.
251
-		$id = intval( $request['id'] );
252
-		if ( $id ) {
253
-			$term = get_term( $id, $taxonomy );
251
+		$id = intval($request['id']);
252
+		if ($id) {
253
+			$term = get_term($id, $taxonomy);
254 254
 
255
-			if ( is_wp_error( $term ) || ! $term || $term->taxonomy !== $taxonomy ) {
256
-				return new \WP_Error( 'woocommerce_rest_term_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
255
+			if (is_wp_error($term) || ! $term || $term->taxonomy !== $taxonomy) {
256
+				return new \WP_Error('woocommerce_rest_term_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
257 257
 			}
258 258
 
259
-			return wc_rest_check_product_term_permissions( $taxonomy, $context, $term->term_id );
259
+			return wc_rest_check_product_term_permissions($taxonomy, $context, $term->term_id);
260 260
 		}
261 261
 
262
-		return wc_rest_check_product_term_permissions( $taxonomy, $context );
262
+		return wc_rest_check_product_term_permissions($taxonomy, $context);
263 263
 	}
264 264
 
265 265
 	/**
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 	 * @param \WP_REST_Request $request Full details about the request.
269 269
 	 * @return \WP_REST_Response|\WP_Error
270 270
 	 */
271
-	public function get_items( $request ) {
272
-		$taxonomy      = $this->get_taxonomy( $request );
271
+	public function get_items($request) {
272
+		$taxonomy      = $this->get_taxonomy($request);
273 273
 		$prepared_args = array(
274 274
 			'exclude'    => $request['exclude'],
275 275
 			'include'    => $request['include'],
@@ -282,20 +282,20 @@  discard block
 block discarded – undo
282 282
 			'slug'       => $request['slug'],
283 283
 		);
284 284
 
285
-		if ( ! empty( $request['offset'] ) ) {
285
+		if ( ! empty($request['offset'])) {
286 286
 			$prepared_args['offset'] = $request['offset'];
287 287
 		} else {
288
-			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
288
+			$prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number'];
289 289
 		}
290 290
 
291
-		$taxonomy_obj = get_taxonomy( $taxonomy );
291
+		$taxonomy_obj = get_taxonomy($taxonomy);
292 292
 
293
-		if ( $taxonomy_obj->hierarchical && isset( $request['parent'] ) ) {
294
-			if ( 0 === $request['parent'] ) {
293
+		if ($taxonomy_obj->hierarchical && isset($request['parent'])) {
294
+			if (0 === $request['parent']) {
295 295
 				// Only query top-level terms.
296 296
 				$prepared_args['parent'] = 0;
297 297
 			} else {
298
-				if ( $request['parent'] ) {
298
+				if ($request['parent']) {
299 299
 					$prepared_args['parent'] = $request['parent'];
300 300
 				}
301 301
 			}
@@ -313,60 +313,60 @@  discard block
 block discarded – undo
313 313
 		 *                                       passed to get_terms.
314 314
 		 * @param \WP_REST_Request $request       The current request.
315 315
 		 */
316
-		$prepared_args = apply_filters( "woocommerce_rest_{$taxonomy}_query", $prepared_args, $request );
316
+		$prepared_args = apply_filters("woocommerce_rest_{$taxonomy}_query", $prepared_args, $request);
317 317
 
318
-		if ( ! empty( $prepared_args['product'] ) ) {
319
-			$query_result = $this->get_terms_for_product( $prepared_args, $request );
318
+		if ( ! empty($prepared_args['product'])) {
319
+			$query_result = $this->get_terms_for_product($prepared_args, $request);
320 320
 			$total_terms  = $this->total_terms;
321 321
 		} else {
322
-			$query_result = get_terms( $taxonomy, $prepared_args );
322
+			$query_result = get_terms($taxonomy, $prepared_args);
323 323
 
324 324
 			$count_args = $prepared_args;
325
-			unset( $count_args['number'] );
326
-			unset( $count_args['offset'] );
327
-			$total_terms = wp_count_terms( $taxonomy, $count_args );
325
+			unset($count_args['number']);
326
+			unset($count_args['offset']);
327
+			$total_terms = wp_count_terms($taxonomy, $count_args);
328 328
 
329 329
 			// Ensure we don't return results when offset is out of bounds.
330 330
 			// See https://core.trac.wordpress.org/ticket/35935.
331
-			if ( $prepared_args['offset'] && $prepared_args['offset'] >= $total_terms ) {
331
+			if ($prepared_args['offset'] && $prepared_args['offset'] >= $total_terms) {
332 332
 				$query_result = array();
333 333
 			}
334 334
 
335 335
 			// wp_count_terms can return a falsy value when the term has no children.
336
-			if ( ! $total_terms ) {
336
+			if ( ! $total_terms) {
337 337
 				$total_terms = 0;
338 338
 			}
339 339
 		}
340 340
 		$response = array();
341
-		foreach ( $query_result as $term ) {
342
-			$data       = $this->prepare_item_for_response( $term, $request );
343
-			$response[] = $this->prepare_response_for_collection( $data );
341
+		foreach ($query_result as $term) {
342
+			$data       = $this->prepare_item_for_response($term, $request);
343
+			$response[] = $this->prepare_response_for_collection($data);
344 344
 		}
345 345
 
346
-		$response = rest_ensure_response( $response );
346
+		$response = rest_ensure_response($response);
347 347
 
348 348
 		// Store pagination values for headers then unset for count query.
349 349
 		$per_page = (int) $prepared_args['number'];
350
-		$page     = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
350
+		$page     = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
351 351
 
352
-		$response->header( 'X-WP-Total', (int) $total_terms );
353
-		$max_pages = ceil( $total_terms / $per_page );
354
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
352
+		$response->header('X-WP-Total', (int) $total_terms);
353
+		$max_pages = ceil($total_terms / $per_page);
354
+		$response->header('X-WP-TotalPages', (int) $max_pages);
355 355
 
356
-		$base  = str_replace( '(?P<attribute_id>[\d]+)', $request['attribute_id'], $this->rest_base );
357
-		$base = add_query_arg( $request->get_query_params(), rest_url( '/' . $this->namespace . '/' . $base ) );
358
-		if ( $page > 1 ) {
356
+		$base = str_replace('(?P<attribute_id>[\d]+)', $request['attribute_id'], $this->rest_base);
357
+		$base = add_query_arg($request->get_query_params(), rest_url('/' . $this->namespace . '/' . $base));
358
+		if ($page > 1) {
359 359
 			$prev_page = $page - 1;
360
-			if ( $prev_page > $max_pages ) {
360
+			if ($prev_page > $max_pages) {
361 361
 				$prev_page = $max_pages;
362 362
 			}
363
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
364
-			$response->link_header( 'prev', $prev_link );
363
+			$prev_link = add_query_arg('page', $prev_page, $base);
364
+			$response->link_header('prev', $prev_link);
365 365
 		}
366
-		if ( $max_pages > $page ) {
366
+		if ($max_pages > $page) {
367 367
 			$next_page = $page + 1;
368
-			$next_link = add_query_arg( 'page', $next_page, $base );
369
-			$response->link_header( 'next', $next_link );
368
+			$next_link = add_query_arg('page', $next_page, $base);
369
+			$response->link_header('next', $next_link);
370 370
 		}
371 371
 
372 372
 		return $response;
@@ -378,47 +378,47 @@  discard block
 block discarded – undo
378 378
 	 * @param \WP_REST_Request $request Full details about the request.
379 379
 	 * @return \WP_REST_Request|\WP_Error
380 380
 	 */
381
-	public function create_item( $request ) {
382
-		$taxonomy = $this->get_taxonomy( $request );
381
+	public function create_item($request) {
382
+		$taxonomy = $this->get_taxonomy($request);
383 383
 		$name     = $request['name'];
384 384
 		$args     = array();
385 385
 		$schema   = $this->get_item_schema();
386 386
 
387
-		if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) {
387
+		if ( ! empty($schema['properties']['description']) && isset($request['description'])) {
388 388
 			$args['description'] = $request['description'];
389 389
 		}
390
-		if ( isset( $request['slug'] ) ) {
390
+		if (isset($request['slug'])) {
391 391
 			$args['slug'] = $request['slug'];
392 392
 		}
393
-		if ( isset( $request['parent'] ) ) {
394
-			if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
395
-				return new \WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) );
393
+		if (isset($request['parent'])) {
394
+			if ( ! is_taxonomy_hierarchical($taxonomy)) {
395
+				return new \WP_Error('woocommerce_rest_taxonomy_not_hierarchical', __('Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce'), array('status' => 400));
396 396
 			}
397 397
 			$args['parent'] = $request['parent'];
398 398
 		}
399 399
 
400
-		$term = wp_insert_term( $name, $taxonomy, $args );
401
-		if ( is_wp_error( $term ) ) {
402
-			$error_data = array( 'status' => 400 );
400
+		$term = wp_insert_term($name, $taxonomy, $args);
401
+		if (is_wp_error($term)) {
402
+			$error_data = array('status' => 400);
403 403
 
404 404
 			// If we're going to inform the client that the term exists,
405 405
 			// give them the identifier they can actually use.
406
-			$term_id = $term->get_error_data( 'term_exists' );
407
-			if ( $term_id ) {
406
+			$term_id = $term->get_error_data('term_exists');
407
+			if ($term_id) {
408 408
 				$error_data['resource_id'] = $term_id;
409 409
 			}
410 410
 
411
-			return new \WP_Error( $term->get_error_code(), $term->get_error_message(), $error_data );
411
+			return new \WP_Error($term->get_error_code(), $term->get_error_message(), $error_data);
412 412
 		}
413 413
 
414
-		$term = get_term( $term['term_id'], $taxonomy );
414
+		$term = get_term($term['term_id'], $taxonomy);
415 415
 
416
-		$this->update_additional_fields_for_object( $term, $request );
416
+		$this->update_additional_fields_for_object($term, $request);
417 417
 
418 418
 		// Add term data.
419
-		$meta_fields = $this->update_term_meta_fields( $term, $request );
420
-		if ( is_wp_error( $meta_fields ) ) {
421
-			wp_delete_term( $term->term_id, $taxonomy );
419
+		$meta_fields = $this->update_term_meta_fields($term, $request);
420
+		if (is_wp_error($meta_fields)) {
421
+			wp_delete_term($term->term_id, $taxonomy);
422 422
 
423 423
 			return $meta_fields;
424 424
 		}
@@ -430,19 +430,19 @@  discard block
 block discarded – undo
430 430
 		 * @param \WP_REST_Request $request   Request object.
431 431
 		 * @param boolean         $creating  True when creating term, false when updating.
432 432
 		 */
433
-		do_action( "woocommerce_rest_insert_{$taxonomy}", $term, $request, true );
433
+		do_action("woocommerce_rest_insert_{$taxonomy}", $term, $request, true);
434 434
 
435
-		$request->set_param( 'context', 'edit' );
436
-		$response = $this->prepare_item_for_response( $term, $request );
437
-		$response = rest_ensure_response( $response );
438
-		$response->set_status( 201 );
435
+		$request->set_param('context', 'edit');
436
+		$response = $this->prepare_item_for_response($term, $request);
437
+		$response = rest_ensure_response($response);
438
+		$response->set_status(201);
439 439
 
440 440
 		$base = '/' . $this->namespace . '/' . $this->rest_base;
441
-		if ( ! empty( $request['attribute_id'] ) ) {
442
-			$base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base );
441
+		if ( ! empty($request['attribute_id'])) {
442
+			$base = str_replace('(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base);
443 443
 		}
444 444
 
445
-		$response->header( 'Location', rest_url( $base . '/' . $term->term_id ) );
445
+		$response->header('Location', rest_url($base . '/' . $term->term_id));
446 446
 
447 447
 		return $response;
448 448
 	}
@@ -453,17 +453,17 @@  discard block
 block discarded – undo
453 453
 	 * @param \WP_REST_Request $request Full details about the request.
454 454
 	 * @return \WP_REST_Request|\WP_Error
455 455
 	 */
456
-	public function get_item( $request ) {
457
-		$taxonomy = $this->get_taxonomy( $request );
458
-		$term     = get_term( (int) $request['id'], $taxonomy );
456
+	public function get_item($request) {
457
+		$taxonomy = $this->get_taxonomy($request);
458
+		$term     = get_term((int) $request['id'], $taxonomy);
459 459
 
460
-		if ( is_wp_error( $term ) ) {
460
+		if (is_wp_error($term)) {
461 461
 			return $term;
462 462
 		}
463 463
 
464
-		$response = $this->prepare_item_for_response( $term, $request );
464
+		$response = $this->prepare_item_for_response($term, $request);
465 465
 
466
-		return rest_ensure_response( $response );
466
+		return rest_ensure_response($response);
467 467
 	}
468 468
 
469 469
 	/**
@@ -472,43 +472,43 @@  discard block
 block discarded – undo
472 472
 	 * @param \WP_REST_Request $request Full details about the request.
473 473
 	 * @return \WP_REST_Request|\WP_Error
474 474
 	 */
475
-	public function update_item( $request ) {
476
-		$taxonomy      = $this->get_taxonomy( $request );
477
-		$term          = get_term( (int) $request['id'], $taxonomy );
475
+	public function update_item($request) {
476
+		$taxonomy      = $this->get_taxonomy($request);
477
+		$term          = get_term((int) $request['id'], $taxonomy);
478 478
 		$schema        = $this->get_item_schema();
479 479
 		$prepared_args = array();
480 480
 
481
-		if ( isset( $request['name'] ) ) {
481
+		if (isset($request['name'])) {
482 482
 			$prepared_args['name'] = $request['name'];
483 483
 		}
484
-		if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) {
484
+		if ( ! empty($schema['properties']['description']) && isset($request['description'])) {
485 485
 			$prepared_args['description'] = $request['description'];
486 486
 		}
487
-		if ( isset( $request['slug'] ) ) {
487
+		if (isset($request['slug'])) {
488 488
 			$prepared_args['slug'] = $request['slug'];
489 489
 		}
490
-		if ( isset( $request['parent'] ) ) {
491
-			if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
492
-				return new \WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) );
490
+		if (isset($request['parent'])) {
491
+			if ( ! is_taxonomy_hierarchical($taxonomy)) {
492
+				return new \WP_Error('woocommerce_rest_taxonomy_not_hierarchical', __('Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce'), array('status' => 400));
493 493
 			}
494 494
 			$prepared_args['parent'] = $request['parent'];
495 495
 		}
496 496
 
497 497
 		// Only update the term if we haz something to update.
498
-		if ( ! empty( $prepared_args ) ) {
499
-			$update = wp_update_term( $term->term_id, $term->taxonomy, $prepared_args );
500
-			if ( is_wp_error( $update ) ) {
498
+		if ( ! empty($prepared_args)) {
499
+			$update = wp_update_term($term->term_id, $term->taxonomy, $prepared_args);
500
+			if (is_wp_error($update)) {
501 501
 				return $update;
502 502
 			}
503 503
 		}
504 504
 
505
-		$term = get_term( (int) $request['id'], $taxonomy );
505
+		$term = get_term((int) $request['id'], $taxonomy);
506 506
 
507
-		$this->update_additional_fields_for_object( $term, $request );
507
+		$this->update_additional_fields_for_object($term, $request);
508 508
 
509 509
 		// Update term data.
510
-		$meta_fields = $this->update_term_meta_fields( $term, $request );
511
-		if ( is_wp_error( $meta_fields ) ) {
510
+		$meta_fields = $this->update_term_meta_fields($term, $request);
511
+		if (is_wp_error($meta_fields)) {
512 512
 			return $meta_fields;
513 513
 		}
514 514
 
@@ -519,11 +519,11 @@  discard block
 block discarded – undo
519 519
 		 * @param \WP_REST_Request $request   Request object.
520 520
 		 * @param boolean         $creating  True when creating term, false when updating.
521 521
 		 */
522
-		do_action( "woocommerce_rest_insert_{$taxonomy}", $term, $request, false );
522
+		do_action("woocommerce_rest_insert_{$taxonomy}", $term, $request, false);
523 523
 
524
-		$request->set_param( 'context', 'edit' );
525
-		$response = $this->prepare_item_for_response( $term, $request );
526
-		return rest_ensure_response( $response );
524
+		$request->set_param('context', 'edit');
525
+		$response = $this->prepare_item_for_response($term, $request);
526
+		return rest_ensure_response($response);
527 527
 	}
528 528
 
529 529
 	/**
@@ -532,30 +532,30 @@  discard block
 block discarded – undo
532 532
 	 * @param \WP_REST_Request $request Full details about the request.
533 533
 	 * @return \WP_REST_Response|\WP_Error
534 534
 	 */
535
-	public function delete_item( $request ) {
536
-		$taxonomy = $this->get_taxonomy( $request );
537
-		$force    = isset( $request['force'] ) ? (bool) $request['force'] : false;
535
+	public function delete_item($request) {
536
+		$taxonomy = $this->get_taxonomy($request);
537
+		$force    = isset($request['force']) ? (bool) $request['force'] : false;
538 538
 
539 539
 		// We don't support trashing for this type, error out.
540
-		if ( ! $force ) {
541
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
540
+		if ( ! $force) {
541
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Resource does not support trashing.', 'woocommerce'), array('status' => 501));
542 542
 		}
543 543
 
544
-		$term = get_term( (int) $request['id'], $taxonomy );
544
+		$term = get_term((int) $request['id'], $taxonomy);
545 545
 		// Get default category id.
546
-		$default_category_id = absint( get_option( 'default_product_cat', 0 ) );
546
+		$default_category_id = absint(get_option('default_product_cat', 0));
547 547
 
548 548
 		// Prevent deleting the default product category.
549
-		if ( $default_category_id === (int) $request['id'] ) {
550
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Default product category cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
549
+		if ($default_category_id === (int) $request['id']) {
550
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Default product category cannot be deleted.', 'woocommerce'), array('status' => 500));
551 551
 		}
552 552
 
553
-		$request->set_param( 'context', 'edit' );
554
-		$response = $this->prepare_item_for_response( $term, $request );
553
+		$request->set_param('context', 'edit');
554
+		$response = $this->prepare_item_for_response($term, $request);
555 555
 
556
-		$retval = wp_delete_term( $term->term_id, $term->taxonomy );
557
-		if ( ! $retval ) {
558
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
556
+		$retval = wp_delete_term($term->term_id, $term->taxonomy);
557
+		if ( ! $retval) {
558
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
559 559
 		}
560 560
 
561 561
 		/**
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 		 * @param \WP_REST_Response $response The response data.
566 566
 		 * @param \WP_REST_Request  $request  The request sent to the API.
567 567
 		 */
568
-		do_action( "woocommerce_rest_delete_{$taxonomy}", $term, $response, $request );
568
+		do_action("woocommerce_rest_delete_{$taxonomy}", $term, $response, $request);
569 569
 
570 570
 		return $response;
571 571
 	}
@@ -577,27 +577,27 @@  discard block
 block discarded – undo
577 577
 	 * @param \WP_REST_Request $request Full details about the request.
578 578
 	 * @return array Links for the given term.
579 579
 	 */
580
-	protected function prepare_links( $term, $request ) {
580
+	protected function prepare_links($term, $request) {
581 581
 		$base = '/' . $this->namespace . '/' . $this->rest_base;
582 582
 
583
-		if ( ! empty( $request['attribute_id'] ) ) {
584
-			$base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base );
583
+		if ( ! empty($request['attribute_id'])) {
584
+			$base = str_replace('(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base);
585 585
 		}
586 586
 
587 587
 		$links = array(
588 588
 			'self'       => array(
589
-				'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
589
+				'href' => rest_url(trailingslashit($base) . $term->term_id),
590 590
 			),
591 591
 			'collection' => array(
592
-				'href' => rest_url( $base ),
592
+				'href' => rest_url($base),
593 593
 			),
594 594
 		);
595 595
 
596
-		if ( $term->parent ) {
597
-			$parent_term = get_term( (int) $term->parent, $term->taxonomy );
598
-			if ( $parent_term ) {
596
+		if ($term->parent) {
597
+			$parent_term = get_term((int) $term->parent, $term->taxonomy);
598
+			if ($parent_term) {
599 599
 				$links['up'] = array(
600
-					'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
600
+					'href' => rest_url(trailingslashit($base) . $parent_term->term_id),
601 601
 				);
602 602
 			}
603 603
 		}
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 	 * @param \WP_REST_Request $request Full details about the request.
613 613
 	 * @return bool|\WP_Error
614 614
 	 */
615
-	protected function update_term_meta_fields( $term, $request ) {
615
+	protected function update_term_meta_fields($term, $request) {
616 616
 		return true;
617 617
 	}
618 618
 
@@ -628,19 +628,19 @@  discard block
 block discarded – undo
628 628
 	 * @param \WP_REST_Request $request       Full details about the request.
629 629
 	 * @return array List of term objects. (Total count in `$this->total_terms`).
630 630
 	 */
631
-	protected function get_terms_for_product( $prepared_args, $request ) {
632
-		$taxonomy = $this->get_taxonomy( $request );
631
+	protected function get_terms_for_product($prepared_args, $request) {
632
+		$taxonomy = $this->get_taxonomy($request);
633 633
 
634
-		$query_result = get_the_terms( $prepared_args['product'], $taxonomy );
635
-		if ( empty( $query_result ) ) {
634
+		$query_result = get_the_terms($prepared_args['product'], $taxonomy);
635
+		if (empty($query_result)) {
636 636
 			$this->total_terms = 0;
637 637
 			return array();
638 638
 		}
639 639
 
640 640
 		// get_items() verifies that we don't have `include` set, and default.
641 641
 		// ordering is by `name`.
642
-		if ( ! in_array( $prepared_args['orderby'], array( 'name', 'none', 'include' ), true ) ) {
643
-			switch ( $prepared_args['orderby'] ) {
642
+		if ( ! in_array($prepared_args['orderby'], array('name', 'none', 'include'), true)) {
643
+			switch ($prepared_args['orderby']) {
644 644
 				case 'id':
645 645
 					$this->sort_column = 'term_id';
646 646
 					break;
@@ -651,15 +651,15 @@  discard block
 block discarded – undo
651 651
 					$this->sort_column = $prepared_args['orderby'];
652 652
 					break;
653 653
 			}
654
-			usort( $query_result, array( $this, 'compare_terms' ) );
654
+			usort($query_result, array($this, 'compare_terms'));
655 655
 		}
656
-		if ( strtolower( $prepared_args['order'] ) !== 'asc' ) {
657
-			$query_result = array_reverse( $query_result );
656
+		if (strtolower($prepared_args['order']) !== 'asc') {
657
+			$query_result = array_reverse($query_result);
658 658
 		}
659 659
 
660 660
 		// Pagination.
661
-		$this->total_terms = count( $query_result );
662
-		$query_result      = array_slice( $query_result, $prepared_args['offset'], $prepared_args['number'] );
661
+		$this->total_terms = count($query_result);
662
+		$query_result      = array_slice($query_result, $prepared_args['offset'], $prepared_args['number']);
663 663
 
664 664
 		return $query_result;
665 665
 	}
@@ -673,16 +673,16 @@  discard block
 block discarded – undo
673 673
 	 * @param stdClass $right Term object.
674 674
 	 * @return int <0 if left is higher "priority" than right, 0 if equal, >0 if right is higher "priority" than left.
675 675
 	 */
676
-	protected function compare_terms( $left, $right ) {
676
+	protected function compare_terms($left, $right) {
677 677
 		$col       = $this->sort_column;
678 678
 		$left_val  = $left->$col;
679 679
 		$right_val = $right->$col;
680 680
 
681
-		if ( is_int( $left_val ) && is_int( $right_val ) ) {
681
+		if (is_int($left_val) && is_int($right_val)) {
682 682
 			return $left_val - $right_val;
683 683
 		}
684 684
 
685
-		return strcmp( $left_val, $right_val );
685
+		return strcmp($left_val, $right_val);
686 686
 	}
687 687
 
688 688
 	/**
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 	public function get_collection_params() {
694 694
 		$params = parent::get_collection_params();
695 695
 
696
-		if ( '' !== $this->taxonomy && taxonomy_exists( $this->taxonomy ) ) {
697
-			$taxonomy = get_taxonomy( $this->taxonomy );
696
+		if ('' !== $this->taxonomy && taxonomy_exists($this->taxonomy)) {
697
+			$taxonomy = get_taxonomy($this->taxonomy);
698 698
 		} else {
699 699
 			$taxonomy               = new \stdClass();
700 700
 			$taxonomy->hierarchical = true;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 		$params['context']['default'] = 'view';
704 704
 
705 705
 		$params['exclude'] = array(
706
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
706
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
707 707
 			'type'              => 'array',
708 708
 			'items'             => array(
709 709
 				'type' => 'integer',
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 			'sanitize_callback' => 'wp_parse_id_list',
713 713
 		);
714 714
 		$params['include'] = array(
715
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
715
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
716 716
 			'type'              => 'array',
717 717
 			'items'             => array(
718 718
 				'type' => 'integer',
@@ -720,16 +720,16 @@  discard block
 block discarded – undo
720 720
 			'default'           => array(),
721 721
 			'sanitize_callback' => 'wp_parse_id_list',
722 722
 		);
723
-		if ( ! $taxonomy->hierarchical ) {
723
+		if ( ! $taxonomy->hierarchical) {
724 724
 			$params['offset'] = array(
725
-				'description'       => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
725
+				'description'       => __('Offset the result set by a specific number of items.', 'woocommerce'),
726 726
 				'type'              => 'integer',
727 727
 				'sanitize_callback' => 'absint',
728 728
 				'validate_callback' => 'rest_validate_request_arg',
729 729
 			);
730 730
 		}
731
-		$params['order']      = array(
732
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
731
+		$params['order'] = array(
732
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
733 733
 			'type'              => 'string',
734 734
 			'sanitize_callback' => 'sanitize_key',
735 735
 			'default'           => 'asc',
@@ -739,8 +739,8 @@  discard block
 block discarded – undo
739 739
 			),
740 740
 			'validate_callback' => 'rest_validate_request_arg',
741 741
 		);
742
-		$params['orderby']    = array(
743
-			'description'       => __( 'Sort collection by resource attribute.', 'woocommerce' ),
742
+		$params['orderby'] = array(
743
+			'description'       => __('Sort collection by resource attribute.', 'woocommerce'),
744 744
 			'type'              => 'string',
745 745
 			'sanitize_callback' => 'sanitize_key',
746 746
 			'default'           => 'name',
@@ -756,27 +756,27 @@  discard block
 block discarded – undo
756 756
 			'validate_callback' => 'rest_validate_request_arg',
757 757
 		);
758 758
 		$params['hide_empty'] = array(
759
-			'description'       => __( 'Whether to hide resources not assigned to any products.', 'woocommerce' ),
759
+			'description'       => __('Whether to hide resources not assigned to any products.', 'woocommerce'),
760 760
 			'type'              => 'boolean',
761 761
 			'default'           => false,
762 762
 			'validate_callback' => 'rest_validate_request_arg',
763 763
 		);
764
-		if ( $taxonomy->hierarchical ) {
764
+		if ($taxonomy->hierarchical) {
765 765
 			$params['parent'] = array(
766
-				'description'       => __( 'Limit result set to resources assigned to a specific parent.', 'woocommerce' ),
766
+				'description'       => __('Limit result set to resources assigned to a specific parent.', 'woocommerce'),
767 767
 				'type'              => 'integer',
768 768
 				'sanitize_callback' => 'absint',
769 769
 				'validate_callback' => 'rest_validate_request_arg',
770 770
 			);
771 771
 		}
772 772
 		$params['product'] = array(
773
-			'description'       => __( 'Limit result set to resources assigned to a specific product.', 'woocommerce' ),
773
+			'description'       => __('Limit result set to resources assigned to a specific product.', 'woocommerce'),
774 774
 			'type'              => 'integer',
775 775
 			'default'           => null,
776 776
 			'validate_callback' => 'rest_validate_request_arg',
777 777
 		);
778
-		$params['slug']    = array(
779
-			'description'       => __( 'Limit result set to resources with a specific slug.', 'woocommerce' ),
778
+		$params['slug'] = array(
779
+			'description'       => __('Limit result set to resources with a specific slug.', 'woocommerce'),
780 780
 			'type'              => 'string',
781 781
 			'validate_callback' => 'rest_validate_request_arg',
782 782
 		);
@@ -790,15 +790,15 @@  discard block
 block discarded – undo
790 790
 	 * @param \WP_REST_Request $request Full details about the request.
791 791
 	 * @return int|\WP_Error
792 792
 	 */
793
-	protected function get_taxonomy( $request ) {
793
+	protected function get_taxonomy($request) {
794 794
 		// Check if taxonomy is defined.
795 795
 		// Prevents check for attribute taxonomy more than one time for each query.
796
-		if ( '' !== $this->taxonomy ) {
796
+		if ('' !== $this->taxonomy) {
797 797
 			return $this->taxonomy;
798 798
 		}
799 799
 
800
-		if ( ! empty( $request['attribute_id'] ) ) {
801
-			$taxonomy = wc_attribute_taxonomy_name_by_id( (int) $request['attribute_id'] );
800
+		if ( ! empty($request['attribute_id'])) {
801
+			$taxonomy = wc_attribute_taxonomy_name_by_id((int) $request['attribute_id']);
802 802
 
803 803
 			$this->taxonomy = $taxonomy;
804 804
 		}
Please login to merge, or discard this patch.