Test Failed
Push — master ( 44764d...6dc399 )
by Mike
04:21
created
src/RestApi/Version4/Controllers/ProductCategories.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Product Categories controller class.
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 	 * @param \WP_REST_Request $request Request instance.
38 38
 	 * @return \WP_REST_Response
39 39
 	 */
40
-	public function prepare_item_for_response( $item, $request ) {
40
+	public function prepare_item_for_response($item, $request) {
41 41
 		// Get category display type.
42
-		$display_type = get_term_meta( $item->term_id, 'display_type', true );
42
+		$display_type = get_term_meta($item->term_id, 'display_type', true);
43 43
 
44 44
 		// Get category order.
45
-		$menu_order = get_term_meta( $item->term_id, 'order', true );
45
+		$menu_order = get_term_meta($item->term_id, 'order', true);
46 46
 
47 47
 		$data = array(
48 48
 			'id'          => (int) $item->term_id,
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 		);
58 58
 
59 59
 		// Get category image.
60
-		$image_id = get_term_meta( $item->term_id, 'thumbnail_id', true );
61
-		if ( $image_id ) {
62
-			$attachment = get_post( $image_id );
60
+		$image_id = get_term_meta($item->term_id, 'thumbnail_id', true);
61
+		if ($image_id) {
62
+			$attachment = get_post($image_id);
63 63
 
64 64
 			$data['image'] = array(
65 65
 				'id'                => (int) $image_id,
66
-				'date_created'      => wc_rest_prepare_date_response( $attachment->post_date ),
67
-				'date_created_gmt'  => wc_rest_prepare_date_response( $attachment->post_date_gmt ),
68
-				'date_modified'     => wc_rest_prepare_date_response( $attachment->post_modified ),
69
-				'date_modified_gmt' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ),
70
-				'src'               => wp_get_attachment_url( $image_id ),
71
-				'name'              => get_the_title( $attachment ),
72
-				'alt'               => get_post_meta( $image_id, '_wp_attachment_image_alt', true ),
66
+				'date_created'      => wc_rest_prepare_date_response($attachment->post_date),
67
+				'date_created_gmt'  => wc_rest_prepare_date_response($attachment->post_date_gmt),
68
+				'date_modified'     => wc_rest_prepare_date_response($attachment->post_modified),
69
+				'date_modified_gmt' => wc_rest_prepare_date_response($attachment->post_modified_gmt),
70
+				'src'               => wp_get_attachment_url($image_id),
71
+				'name'              => get_the_title($attachment),
72
+				'alt'               => get_post_meta($image_id, '_wp_attachment_image_alt', true),
73 73
 			);
74 74
 		}
75 75
 
76
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
77
-		$data    = $this->add_additional_fields_to_object( $data, $request );
78
-		$data    = $this->filter_response_by_context( $data, $context );
76
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
77
+		$data    = $this->add_additional_fields_to_object($data, $request);
78
+		$data    = $this->filter_response_by_context($data, $context);
79 79
 
80
-		$response = rest_ensure_response( $data );
80
+		$response = rest_ensure_response($data);
81 81
 
82
-		$response->add_links( $this->prepare_links( $item, $request ) );
82
+		$response->add_links($this->prepare_links($item, $request));
83 83
 
84 84
 		/**
85 85
 		 * Filter a term item returned from the API.
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		 * @param object            $item      The original term object.
91 91
 		 * @param \WP_REST_Request   $request   Request used to generate the response.
92 92
 		 */
93
-		return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request );
93
+		return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
94 94
 	}
95 95
 
96 96
 	/**
@@ -102,50 +102,50 @@  discard block
 block discarded – undo
102 102
 	 *
103 103
 	 * @since 3.5.5
104 104
 	 */
105
-	protected function update_term_meta_fields( $term, $request ) {
105
+	protected function update_term_meta_fields($term, $request) {
106 106
 		$id = (int) $term->term_id;
107 107
 
108
-		if ( isset( $request['display'] ) ) {
109
-			update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] );
108
+		if (isset($request['display'])) {
109
+			update_term_meta($id, 'display_type', 'default' === $request['display'] ? '' : $request['display']);
110 110
 		}
111 111
 
112
-		if ( isset( $request['menu_order'] ) ) {
113
-			update_term_meta( $id, 'order', $request['menu_order'] );
112
+		if (isset($request['menu_order'])) {
113
+			update_term_meta($id, 'order', $request['menu_order']);
114 114
 		}
115 115
 
116
-		if ( isset( $request['image'] ) ) {
117
-			if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) {
118
-				$upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) );
116
+		if (isset($request['image'])) {
117
+			if (empty($request['image']['id']) && ! empty($request['image']['src'])) {
118
+				$upload = wc_rest_upload_image_from_url(esc_url_raw($request['image']['src']));
119 119
 
120
-				if ( is_wp_error( $upload ) ) {
120
+				if (is_wp_error($upload)) {
121 121
 					return $upload;
122 122
 				}
123 123
 
124
-				$image_id = wc_rest_set_uploaded_image_as_attachment( $upload );
124
+				$image_id = wc_rest_set_uploaded_image_as_attachment($upload);
125 125
 			} else {
126
-				$image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0;
126
+				$image_id = isset($request['image']['id']) ? absint($request['image']['id']) : 0;
127 127
 			}
128 128
 
129 129
 			// Check if image_id is a valid image attachment before updating the term meta.
130
-			if ( $image_id && wp_attachment_is_image( $image_id ) ) {
131
-				update_term_meta( $id, 'thumbnail_id', $image_id );
130
+			if ($image_id && wp_attachment_is_image($image_id)) {
131
+				update_term_meta($id, 'thumbnail_id', $image_id);
132 132
 
133 133
 				// Set the image alt.
134
-				if ( ! empty( $request['image']['alt'] ) ) {
135
-					update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) );
134
+				if ( ! empty($request['image']['alt'])) {
135
+					update_post_meta($image_id, '_wp_attachment_image_alt', wc_clean($request['image']['alt']));
136 136
 				}
137 137
 
138 138
 				// Set the image title.
139
-				if ( ! empty( $request['image']['name'] ) ) {
139
+				if ( ! empty($request['image']['name'])) {
140 140
 					wp_update_post(
141 141
 						array(
142 142
 							'ID'         => $image_id,
143
-							'post_title' => wc_clean( $request['image']['name'] ),
143
+							'post_title' => wc_clean($request['image']['name']),
144 144
 						)
145 145
 					);
146 146
 				}
147 147
 			} else {
148
-				delete_term_meta( $id, 'thumbnail_id' );
148
+				delete_term_meta($id, 'thumbnail_id');
149 149
 			}
150 150
 		}
151 151
 
@@ -164,113 +164,113 @@  discard block
 block discarded – undo
164 164
 			'type'       => 'object',
165 165
 			'properties' => array(
166 166
 				'id'          => array(
167
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
167
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
168 168
 					'type'        => 'integer',
169
-					'context'     => array( 'view', 'edit' ),
169
+					'context'     => array('view', 'edit'),
170 170
 					'readonly'    => true,
171 171
 				),
172 172
 				'name'        => array(
173
-					'description' => __( 'Category name.', 'woocommerce' ),
173
+					'description' => __('Category name.', 'woocommerce'),
174 174
 					'type'        => 'string',
175
-					'context'     => array( 'view', 'edit' ),
175
+					'context'     => array('view', 'edit'),
176 176
 					'arg_options' => array(
177 177
 						'sanitize_callback' => 'sanitize_text_field',
178 178
 					),
179 179
 				),
180 180
 				'slug'        => array(
181
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
181
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
182 182
 					'type'        => 'string',
183
-					'context'     => array( 'view', 'edit' ),
183
+					'context'     => array('view', 'edit'),
184 184
 					'arg_options' => array(
185 185
 						'sanitize_callback' => 'sanitize_title',
186 186
 					),
187 187
 				),
188 188
 				'parent'      => array(
189
-					'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ),
189
+					'description' => __('The ID for the parent of the resource.', 'woocommerce'),
190 190
 					'type'        => 'integer',
191
-					'context'     => array( 'view', 'edit' ),
191
+					'context'     => array('view', 'edit'),
192 192
 				),
193 193
 				'description' => array(
194
-					'description' => __( 'HTML description of the resource.', 'woocommerce' ),
194
+					'description' => __('HTML description of the resource.', 'woocommerce'),
195 195
 					'type'        => 'string',
196
-					'context'     => array( 'view', 'edit' ),
196
+					'context'     => array('view', 'edit'),
197 197
 					'arg_options' => array(
198 198
 						'sanitize_callback' => 'wp_filter_post_kses',
199 199
 					),
200 200
 				),
201 201
 				'display'     => array(
202
-					'description' => __( 'Category archive display type.', 'woocommerce' ),
202
+					'description' => __('Category archive display type.', 'woocommerce'),
203 203
 					'type'        => 'string',
204 204
 					'default'     => 'default',
205
-					'enum'        => array( 'default', 'products', 'subcategories', 'both' ),
206
-					'context'     => array( 'view', 'edit' ),
205
+					'enum'        => array('default', 'products', 'subcategories', 'both'),
206
+					'context'     => array('view', 'edit'),
207 207
 				),
208 208
 				'image'       => array(
209
-					'description' => __( 'Image data.', 'woocommerce' ),
209
+					'description' => __('Image data.', 'woocommerce'),
210 210
 					'type'        => 'object',
211
-					'context'     => array( 'view', 'edit' ),
211
+					'context'     => array('view', 'edit'),
212 212
 					'properties'  => array(
213 213
 						'id'                => array(
214
-							'description' => __( 'Image ID.', 'woocommerce' ),
214
+							'description' => __('Image ID.', 'woocommerce'),
215 215
 							'type'        => 'integer',
216
-							'context'     => array( 'view', 'edit' ),
216
+							'context'     => array('view', 'edit'),
217 217
 						),
218 218
 						'date_created'      => array(
219
-							'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
219
+							'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'),
220 220
 							'type'        => 'date-time',
221
-							'context'     => array( 'view', 'edit' ),
221
+							'context'     => array('view', 'edit'),
222 222
 							'readonly'    => true,
223 223
 						),
224 224
 						'date_created_gmt'  => array(
225
-							'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
225
+							'description' => __('The date the image was created, as GMT.', 'woocommerce'),
226 226
 							'type'        => 'date-time',
227
-							'context'     => array( 'view', 'edit' ),
227
+							'context'     => array('view', 'edit'),
228 228
 							'readonly'    => true,
229 229
 						),
230 230
 						'date_modified'     => array(
231
-							'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
231
+							'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'),
232 232
 							'type'        => 'date-time',
233
-							'context'     => array( 'view', 'edit' ),
233
+							'context'     => array('view', 'edit'),
234 234
 							'readonly'    => true,
235 235
 						),
236 236
 						'date_modified_gmt' => array(
237
-							'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
237
+							'description' => __('The date the image was last modified, as GMT.', 'woocommerce'),
238 238
 							'type'        => 'date-time',
239
-							'context'     => array( 'view', 'edit' ),
239
+							'context'     => array('view', 'edit'),
240 240
 							'readonly'    => true,
241 241
 						),
242 242
 						'src'               => array(
243
-							'description' => __( 'Image URL.', 'woocommerce' ),
243
+							'description' => __('Image URL.', 'woocommerce'),
244 244
 							'type'        => 'string',
245 245
 							'format'      => 'uri',
246
-							'context'     => array( 'view', 'edit' ),
246
+							'context'     => array('view', 'edit'),
247 247
 						),
248 248
 						'name'              => array(
249
-							'description' => __( 'Image name.', 'woocommerce' ),
249
+							'description' => __('Image name.', 'woocommerce'),
250 250
 							'type'        => 'string',
251
-							'context'     => array( 'view', 'edit' ),
251
+							'context'     => array('view', 'edit'),
252 252
 						),
253 253
 						'alt'               => array(
254
-							'description' => __( 'Image alternative text.', 'woocommerce' ),
254
+							'description' => __('Image alternative text.', 'woocommerce'),
255 255
 							'type'        => 'string',
256
-							'context'     => array( 'view', 'edit' ),
256
+							'context'     => array('view', 'edit'),
257 257
 						),
258 258
 					),
259 259
 				),
260 260
 				'menu_order'  => array(
261
-					'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ),
261
+					'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'),
262 262
 					'type'        => 'integer',
263
-					'context'     => array( 'view', 'edit' ),
263
+					'context'     => array('view', 'edit'),
264 264
 				),
265 265
 				'count'       => array(
266
-					'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
266
+					'description' => __('Number of published products for the resource.', 'woocommerce'),
267 267
 					'type'        => 'integer',
268
-					'context'     => array( 'view', 'edit' ),
268
+					'context'     => array('view', 'edit'),
269 269
 					'readonly'    => true,
270 270
 				),
271 271
 			),
272 272
 		);
273 273
 
274
-		return $this->add_additional_fields_schema( $schema );
274
+		return $this->add_additional_fields_schema($schema);
275 275
 	}
276 276
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Data/DownloadIPs.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Data as DataController;
15 15
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 			array(
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::READABLE,
40
-					'callback'            => array( $this, 'get_items' ),
41
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
+					'callback'            => array($this, 'get_items'),
41
+					'permission_callback' => array($this, 'get_items_permissions_check'),
42 42
 				),
43
-				'schema' => array( $this, 'get_public_item_schema' ),
43
+				'schema' => array($this, 'get_public_item_schema'),
44 44
 			)
45 45
 		);
46 46
 	}
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
 	 * @param  \WP_REST_Request $request Request data.
53 53
 	 * @return \WP_Error\WP_REST_Response
54 54
 	 */
55
-	public function get_items( $request ) {
55
+	public function get_items($request) {
56 56
 		global $wpdb;
57 57
 
58
-		if ( isset( $request['match'] ) ) {
58
+		if (isset($request['match'])) {
59 59
 			$downloads = $wpdb->get_results(
60 60
 				$wpdb->prepare(
61 61
 					"SELECT DISTINCT( user_ip_address ) FROM {$wpdb->prefix}wc_download_log
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
 				)
66 66
 			);
67 67
 		} else {
68
-			return new \WP_Error( 'woocommerce_rest_data_download_ips_invalid_request', __( 'Invalid request. Please pass the match parameter.', 'woocommerce' ), array( 'status' => 400 ) );
68
+			return new \WP_Error('woocommerce_rest_data_download_ips_invalid_request', __('Invalid request. Please pass the match parameter.', 'woocommerce'), array('status' => 400));
69 69
 		}
70 70
 
71 71
 		$data = array();
72 72
 
73
-		if ( ! empty( $downloads ) ) {
74
-			foreach ( $downloads as $download ) {
75
-				$response = $this->prepare_item_for_response( $download, $request );
76
-				$data[]   = $this->prepare_response_for_collection( $response );
73
+		if ( ! empty($downloads)) {
74
+			foreach ($downloads as $download) {
75
+				$response = $this->prepare_item_for_response($download, $request);
76
+				$data[]   = $this->prepare_response_for_collection($response);
77 77
 			}
78 78
 		}
79 79
 
80
-		return rest_ensure_response( $data );
80
+		return rest_ensure_response($data);
81 81
 	}
82 82
 
83 83
 	/**
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
 	 * @param \WP_REST_Request $request Request object.
89 89
 	 * @return \WP_REST_Response $response Response data.
90 90
 	 */
91
-	public function prepare_item_for_response( $item, $request ) {
92
-		$data     = $this->add_additional_fields_to_object( $item, $request );
93
-		$data     = $this->filter_response_by_context( $data, 'view' );
94
-		$response = rest_ensure_response( $data );
91
+	public function prepare_item_for_response($item, $request) {
92
+		$data     = $this->add_additional_fields_to_object($item, $request);
93
+		$data     = $this->filter_response_by_context($data, 'view');
94
+		$response = rest_ensure_response($data);
95 95
 
96
-		$response->add_links( $this->prepare_links( $item ) );
96
+		$response->add_links($this->prepare_links($item));
97 97
 
98 98
 		/**
99 99
 		 * Filter the list returned from the API.
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		 * @param array            $item     The original item.
103 103
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
104 104
 		 */
105
-		return apply_filters( 'woocommerce_rest_prepare_data_download_ip', $response, $item, $request );
105
+		return apply_filters('woocommerce_rest_prepare_data_download_ip', $response, $item, $request);
106 106
 	}
107 107
 
108 108
 	/**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
 	 * @param object $item Data object.
112 112
 	 * @return array Links for the given object.
113 113
 	 */
114
-	protected function prepare_links( $item ) {
114
+	protected function prepare_links($item) {
115 115
 		$links = array(
116 116
 			'collection' => array(
117
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
117
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
118 118
 			),
119 119
 		);
120 120
 		return $links;
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 	 */
128 128
 	public function get_collection_params() {
129 129
 		$params            = array();
130
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
130
+		$params['context'] = $this->get_context_param(array('default' => 'view'));
131 131
 		$params['match']   = array(
132
-			'description'       => __( 'A partial IP address can be passed and matching results will be returned.', 'woocommerce' ),
132
+			'description'       => __('A partial IP address can be passed and matching results will be returned.', 'woocommerce'),
133 133
 			'type'              => 'string',
134 134
 			'validate_callback' => 'rest_validate_request_arg',
135 135
 		);
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 			'properties' => array(
151 151
 				'user_ip_address' => array(
152 152
 					'type'        => 'string',
153
-					'description' => __( 'IP address.', 'woocommerce' ),
154
-					'context'     => array( 'view' ),
153
+					'description' => __('IP address.', 'woocommerce'),
154
+					'context'     => array('view'),
155 155
 					'readonly'    => true,
156 156
 				),
157 157
 			),
158 158
 		);
159 159
 
160
-		return $this->add_additional_fields_schema( $schema );
160
+		return $this->add_additional_fields_schema($schema);
161 161
 	}
162 162
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Data/Currencies.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Data as DataController;
15 15
 
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 			array(
36 36
 				array(
37 37
 					'methods'             => \WP_REST_Server::READABLE,
38
-					'callback'            => array( $this, 'get_items' ),
39
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
38
+					'callback'            => array($this, 'get_items'),
39
+					'permission_callback' => array($this, 'get_items_permissions_check'),
40 40
 				),
41
-				'schema' => array( $this, 'get_public_item_schema' ),
41
+				'schema' => array($this, 'get_public_item_schema'),
42 42
 			)
43 43
 		);
44 44
 		register_rest_route(
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 			array(
48 48
 				array(
49 49
 					'methods'             => \WP_REST_Server::READABLE,
50
-					'callback'            => array( $this, 'get_current_item' ),
51
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
50
+					'callback'            => array($this, 'get_current_item'),
51
+					'permission_callback' => array($this, 'get_item_permissions_check'),
52 52
 				),
53
-				'schema' => array( $this, 'get_public_item_schema' ),
53
+				'schema' => array($this, 'get_public_item_schema'),
54 54
 			)
55 55
 		);
56 56
 		register_rest_route(
@@ -59,16 +59,16 @@  discard block
 block discarded – undo
59 59
 			array(
60 60
 				array(
61 61
 					'methods'             => \WP_REST_Server::READABLE,
62
-					'callback'            => array( $this, 'get_item' ),
63
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
62
+					'callback'            => array($this, 'get_item'),
63
+					'permission_callback' => array($this, 'get_item_permissions_check'),
64 64
 					'args'                => array(
65 65
 						'location' => array(
66
-							'description' => __( 'ISO4217 currency code.', 'woocommerce' ),
66
+							'description' => __('ISO4217 currency code.', 'woocommerce'),
67 67
 							'type'        => 'string',
68 68
 						),
69 69
 					),
70 70
 				),
71
-				'schema' => array( $this, 'get_public_item_schema' ),
71
+				'schema' => array($this, 'get_public_item_schema'),
72 72
 			)
73 73
 		);
74 74
 	}
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
 	 * @param  \WP_REST_Request $request Request data.
81 81
 	 * @return array|mixed Response data, ready for insertion into collection data.
82 82
 	 */
83
-	public function get_currency( $code = false, $request ) {
83
+	public function get_currency($code = false, $request) {
84 84
 		$currencies = get_woocommerce_currencies();
85 85
 		$data       = array();
86 86
 
87
-		if ( ! array_key_exists( $code, $currencies ) ) {
87
+		if ( ! array_key_exists($code, $currencies)) {
88 88
 			return false;
89 89
 		}
90 90
 
91 91
 		$currency = array(
92 92
 			'code'   => $code,
93
-			'name'   => $currencies[ $code ],
94
-			'symbol' => get_woocommerce_currency_symbol( $code ),
93
+			'name'   => $currencies[$code],
94
+			'symbol' => get_woocommerce_currency_symbol($code),
95 95
 		);
96 96
 
97 97
 		return $currency;
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 	 * @param  \WP_REST_Request $request Request data.
104 104
 	 * @return \WP_Error\WP_REST_Response
105 105
 	 */
106
-	public function get_items( $request ) {
106
+	public function get_items($request) {
107 107
 		$currencies = get_woocommerce_currencies();
108
-		foreach ( array_keys( $currencies ) as $code ) {
109
-			$currency = $this->get_currency( $code, $request );
110
-			$response = $this->prepare_item_for_response( $currency, $request );
111
-			$data[]   = $this->prepare_response_for_collection( $response );
108
+		foreach (array_keys($currencies) as $code) {
109
+			$currency = $this->get_currency($code, $request);
110
+			$response = $this->prepare_item_for_response($currency, $request);
111
+			$data[]   = $this->prepare_response_for_collection($response);
112 112
 		}
113 113
 
114
-		return rest_ensure_response( $data );
114
+		return rest_ensure_response($data);
115 115
 	}
116 116
 
117 117
 	/**
@@ -120,12 +120,12 @@  discard block
 block discarded – undo
120 120
 	 * @param  \WP_REST_Request $request Request data.
121 121
 	 * @return \WP_Error\WP_REST_Response
122 122
 	 */
123
-	public function get_item( $request ) {
124
-		$data = $this->get_currency( strtoupper( $request['currency'] ), $request );
125
-		if ( empty( $data ) ) {
126
-			return new \WP_Error( 'woocommerce_rest_data_invalid_currency', __( 'There are no currencies matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
123
+	public function get_item($request) {
124
+		$data = $this->get_currency(strtoupper($request['currency']), $request);
125
+		if (empty($data)) {
126
+			return new \WP_Error('woocommerce_rest_data_invalid_currency', __('There are no currencies matching these parameters.', 'woocommerce'), array('status' => 404));
127 127
 		}
128
-		return $this->prepare_item_for_response( $data, $request );
128
+		return $this->prepare_item_for_response($data, $request);
129 129
 	}
130 130
 
131 131
 	/**
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 	 * @param  \WP_REST_Request $request Request data.
135 135
 	 * @return \WP_Error\WP_REST_Response
136 136
 	 */
137
-	public function get_current_item( $request ) {
138
-		$currency = get_option( 'woocommerce_currency' );
139
-		return $this->prepare_item_for_response( $this->get_currency( $currency, $request ), $request );
137
+	public function get_current_item($request) {
138
+		$currency = get_option('woocommerce_currency');
139
+		return $this->prepare_item_for_response($this->get_currency($currency, $request), $request);
140 140
 	}
141 141
 
142 142
 	/**
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
 	 * @param \WP_REST_Request $request Request object.
147 147
 	 * @return \WP_REST_Response $response Response data.
148 148
 	 */
149
-	public function prepare_item_for_response( $item, $request ) {
150
-		$data     = $this->add_additional_fields_to_object( $item, $request );
151
-		$data     = $this->filter_response_by_context( $data, 'view' );
152
-		$response = rest_ensure_response( $data );
149
+	public function prepare_item_for_response($item, $request) {
150
+		$data     = $this->add_additional_fields_to_object($item, $request);
151
+		$data     = $this->filter_response_by_context($data, 'view');
152
+		$response = rest_ensure_response($data);
153 153
 
154
-		$response->add_links( $this->prepare_links( $item ) );
154
+		$response->add_links($this->prepare_links($item));
155 155
 
156 156
 		/**
157 157
 		 * Filter currency returned from the API.
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		 * @param array            $item     Currency data.
161 161
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
162 162
 		 */
163
-		return apply_filters( 'woocommerce_rest_prepare_data_currency', $response, $item, $request );
163
+		return apply_filters('woocommerce_rest_prepare_data_currency', $response, $item, $request);
164 164
 	}
165 165
 
166 166
 	/**
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 	 * @param object $item Data object.
170 170
 	 * @return array Links for the given currency.
171 171
 	 */
172
-	protected function prepare_links( $item ) {
173
-		$code  = strtoupper( $item['code'] );
172
+	protected function prepare_links($item) {
173
+		$code  = strtoupper($item['code']);
174 174
 		$links = array(
175 175
 			'self'       => array(
176
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $code ) ),
176
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $code)),
177 177
 			),
178 178
 			'collection' => array(
179
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
179
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
180 180
 			),
181 181
 		);
182 182
 
@@ -197,25 +197,25 @@  discard block
 block discarded – undo
197 197
 			'properties' => array(
198 198
 				'code'   => array(
199 199
 					'type'        => 'string',
200
-					'description' => __( 'ISO4217 currency code.', 'woocommerce' ),
201
-					'context'     => array( 'view' ),
200
+					'description' => __('ISO4217 currency code.', 'woocommerce'),
201
+					'context'     => array('view'),
202 202
 					'readonly'    => true,
203 203
 				),
204 204
 				'name'   => array(
205 205
 					'type'        => 'string',
206
-					'description' => __( 'Full name of currency.', 'woocommerce' ),
207
-					'context'     => array( 'view' ),
206
+					'description' => __('Full name of currency.', 'woocommerce'),
207
+					'context'     => array('view'),
208 208
 					'readonly'    => true,
209 209
 				),
210 210
 				'symbol' => array(
211 211
 					'type'        => 'string',
212
-					'description' => __( 'Currency symbol.', 'woocommerce' ),
213
-					'context'     => array( 'view' ),
212
+					'description' => __('Currency symbol.', 'woocommerce'),
213
+					'context'     => array('view'),
214 214
 					'readonly'    => true,
215 215
 				),
216 216
 			),
217 217
 		);
218 218
 
219
-		return $this->add_additional_fields_schema( $schema );
219
+		return $this->add_additional_fields_schema($schema);
220 220
 	}
221 221
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Data/Continents.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Data as DataController;
15 15
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 			array(
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::READABLE,
40
-					'callback'            => array( $this, 'get_items' ),
41
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
+					'callback'            => array($this, 'get_items'),
41
+					'permission_callback' => array($this, 'get_items_permissions_check'),
42 42
 				),
43
-				'schema' => array( $this, 'get_public_item_schema' ),
43
+				'schema' => array($this, 'get_public_item_schema'),
44 44
 			)
45 45
 		);
46 46
 		register_rest_route(
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
 			array(
50 50
 				array(
51 51
 					'methods'             => \WP_REST_Server::READABLE,
52
-					'callback'            => array( $this, 'get_item' ),
53
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
52
+					'callback'            => array($this, 'get_item'),
53
+					'permission_callback' => array($this, 'get_items_permissions_check'),
54 54
 					'args'                => array(
55 55
 						'continent' => array(
56
-							'description' => __( '2 character continent code.', 'woocommerce' ),
56
+							'description' => __('2 character continent code.', 'woocommerce'),
57 57
 							'type'        => 'string',
58 58
 						),
59 59
 					),
60 60
 				),
61
-				'schema' => array( $this, 'get_public_item_schema' ),
61
+				'schema' => array($this, 'get_public_item_schema'),
62 62
 			)
63 63
 		);
64 64
 	}
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
 	 * @param  \WP_REST_Request $request        Request data.
72 72
 	 * @return array|mixed Response data, ready for insertion into collection data.
73 73
 	 */
74
-	public function get_continent( $continent_code = false, $request ) {
74
+	public function get_continent($continent_code = false, $request) {
75 75
 		$continents  = WC()->countries->get_continents();
76 76
 		$countries   = WC()->countries->get_countries();
77 77
 		$states      = WC()->countries->get_states();
78 78
 		$locale_info = include WC()->plugin_path() . '/i18n/locale-info.php';
79 79
 		$data        = array();
80 80
 
81
-		if ( ! array_key_exists( $continent_code, $continents ) ) {
81
+		if ( ! array_key_exists($continent_code, $continents)) {
82 82
 			return false;
83 83
 		}
84 84
 
85
-		$continent_list = $continents[ $continent_code ];
85
+		$continent_list = $continents[$continent_code];
86 86
 
87 87
 		$continent = array(
88 88
 			'code' => $continent_code,
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
 		);
91 91
 
92 92
 		$local_countries = array();
93
-		foreach ( $continent_list['countries'] as $country_code ) {
94
-			if ( isset( $countries[ $country_code ] ) ) {
93
+		foreach ($continent_list['countries'] as $country_code) {
94
+			if (isset($countries[$country_code])) {
95 95
 				$country = array(
96 96
 					'code' => $country_code,
97
-					'name' => $countries[ $country_code ],
97
+					'name' => $countries[$country_code],
98 98
 				);
99 99
 
100 100
 				// If we have detailed locale information include that in the response.
101
-				if ( array_key_exists( $country_code, $locale_info ) ) {
101
+				if (array_key_exists($country_code, $locale_info)) {
102 102
 					// Defensive programming against unexpected changes in locale-info.php.
103 103
 					$country_data = wp_parse_args(
104
-						$locale_info[ $country_code ],
104
+						$locale_info[$country_code],
105 105
 						array(
106 106
 							'currency_code'  => 'USD',
107 107
 							'currency_pos'   => 'left',
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 						)
114 114
 					);
115 115
 
116
-					$country = array_merge( $country, $country_data );
116
+					$country = array_merge($country, $country_data);
117 117
 				}
118 118
 
119 119
 				$local_states = array();
120
-				if ( isset( $states[ $country_code ] ) ) {
121
-					foreach ( $states[ $country_code ] as $state_code => $state_name ) {
120
+				if (isset($states[$country_code])) {
121
+					foreach ($states[$country_code] as $state_code => $state_name) {
122 122
 						$local_states[] = array(
123 123
 							'code' => $state_code,
124 124
 							'name' => $state_name,
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 					'thousand_sep',
141 141
 					'weight_unit',
142 142
 				);
143
-				$country = array_intersect_key( $country, array_flip( $allowed ) );
143
+				$country = array_intersect_key($country, array_flip($allowed));
144 144
 
145 145
 				$local_countries[] = $country;
146 146
 			}
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
 	 * @param  \WP_REST_Request $request Request data.
158 158
 	 * @return \WP_Error\WP_REST_Response
159 159
 	 */
160
-	public function get_items( $request ) {
160
+	public function get_items($request) {
161 161
 		$continents = WC()->countries->get_continents();
162 162
 		$data       = array();
163 163
 
164
-		foreach ( array_keys( $continents ) as $continent_code ) {
165
-			$continent = $this->get_continent( $continent_code, $request );
166
-			$response  = $this->prepare_item_for_response( $continent, $request );
167
-			$data[]    = $this->prepare_response_for_collection( $response );
164
+		foreach (array_keys($continents) as $continent_code) {
165
+			$continent = $this->get_continent($continent_code, $request);
166
+			$response  = $this->prepare_item_for_response($continent, $request);
167
+			$data[]    = $this->prepare_response_for_collection($response);
168 168
 		}
169 169
 
170
-		return rest_ensure_response( $data );
170
+		return rest_ensure_response($data);
171 171
 	}
172 172
 
173 173
 	/**
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
 	 * @param  \WP_REST_Request $request Request data.
178 178
 	 * @return \WP_Error\WP_REST_Response
179 179
 	 */
180
-	public function get_item( $request ) {
181
-		$data = $this->get_continent( strtoupper( $request['location'] ), $request );
182
-		if ( empty( $data ) ) {
183
-			return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
180
+	public function get_item($request) {
181
+		$data = $this->get_continent(strtoupper($request['location']), $request);
182
+		if (empty($data)) {
183
+			return new \WP_Error('woocommerce_rest_data_invalid_location', __('There are no locations matching these parameters.', 'woocommerce'), array('status' => 404));
184 184
 		}
185
-		return $this->prepare_item_for_response( $data, $request );
185
+		return $this->prepare_item_for_response($data, $request);
186 186
 	}
187 187
 
188 188
 	/**
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
 	 * @param \WP_REST_Request $request Request object.
194 194
 	 * @return \WP_REST_Response $response Response data.
195 195
 	 */
196
-	public function prepare_item_for_response( $item, $request ) {
197
-		$data     = $this->add_additional_fields_to_object( $item, $request );
198
-		$data     = $this->filter_response_by_context( $data, 'view' );
199
-		$response = rest_ensure_response( $data );
196
+	public function prepare_item_for_response($item, $request) {
197
+		$data     = $this->add_additional_fields_to_object($item, $request);
198
+		$data     = $this->filter_response_by_context($data, 'view');
199
+		$response = rest_ensure_response($data);
200 200
 
201
-		$response->add_links( $this->prepare_links( $item ) );
201
+		$response->add_links($this->prepare_links($item));
202 202
 
203 203
 		/**
204 204
 		 * Filter the location list returned from the API.
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 		 * @param array            $item     The original list of continent(s), countries, and states.
210 210
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
211 211
 		 */
212
-		return apply_filters( 'woocommerce_rest_prepare_data_continent', $response, $item, $request );
212
+		return apply_filters('woocommerce_rest_prepare_data_continent', $response, $item, $request);
213 213
 	}
214 214
 
215 215
 	/**
@@ -218,14 +218,14 @@  discard block
 block discarded – undo
218 218
 	 * @param object $item Data object.
219 219
 	 * @return array Links for the given continent.
220 220
 	 */
221
-	protected function prepare_links( $item ) {
222
-		$continent_code = strtolower( $item['code'] );
221
+	protected function prepare_links($item) {
222
+		$continent_code = strtolower($item['code']);
223 223
 		$links          = array(
224 224
 			'self'       => array(
225
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code ) ),
225
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code)),
226 226
 			),
227 227
 			'collection' => array(
228
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
228
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
229 229
 			),
230 230
 		);
231 231
 		return $links;
@@ -245,88 +245,88 @@  discard block
 block discarded – undo
245 245
 			'properties' => array(
246 246
 				'code'      => array(
247 247
 					'type'        => 'string',
248
-					'description' => __( '2 character continent code.', 'woocommerce' ),
249
-					'context'     => array( 'view' ),
248
+					'description' => __('2 character continent code.', 'woocommerce'),
249
+					'context'     => array('view'),
250 250
 					'readonly'    => true,
251 251
 				),
252 252
 				'name'      => array(
253 253
 					'type'        => 'string',
254
-					'description' => __( 'Full name of continent.', 'woocommerce' ),
255
-					'context'     => array( 'view' ),
254
+					'description' => __('Full name of continent.', 'woocommerce'),
255
+					'context'     => array('view'),
256 256
 					'readonly'    => true,
257 257
 				),
258 258
 				'countries' => array(
259 259
 					'type'        => 'array',
260
-					'description' => __( 'List of countries on this continent.', 'woocommerce' ),
261
-					'context'     => array( 'view' ),
260
+					'description' => __('List of countries on this continent.', 'woocommerce'),
261
+					'context'     => array('view'),
262 262
 					'readonly'    => true,
263 263
 					'items'       => array(
264 264
 						'type'       => 'object',
265
-						'context'    => array( 'view' ),
265
+						'context'    => array('view'),
266 266
 						'readonly'   => true,
267 267
 						'properties' => array(
268 268
 							'code'           => array(
269 269
 								'type'        => 'string',
270
-								'description' => __( 'ISO3166 alpha-2 country code.', 'woocommerce' ),
271
-								'context'     => array( 'view' ),
270
+								'description' => __('ISO3166 alpha-2 country code.', 'woocommerce'),
271
+								'context'     => array('view'),
272 272
 								'readonly'    => true,
273 273
 							),
274 274
 							'currency_code'  => array(
275 275
 								'type'        => 'string',
276
-								'description' => __( 'Default ISO4127 alpha-3 currency code for the country.', 'woocommerce' ),
277
-								'context'     => array( 'view' ),
276
+								'description' => __('Default ISO4127 alpha-3 currency code for the country.', 'woocommerce'),
277
+								'context'     => array('view'),
278 278
 								'readonly'    => true,
279 279
 							),
280 280
 							'currency_pos'   => array(
281 281
 								'type'        => 'string',
282
-								'description' => __( 'Currency symbol position for this country.', 'woocommerce' ),
283
-								'context'     => array( 'view' ),
282
+								'description' => __('Currency symbol position for this country.', 'woocommerce'),
283
+								'context'     => array('view'),
284 284
 								'readonly'    => true,
285 285
 							),
286 286
 							'decimal_sep'    => array(
287 287
 								'type'        => 'string',
288
-								'description' => __( 'Decimal separator for displayed prices for this country.', 'woocommerce' ),
289
-								'context'     => array( 'view' ),
288
+								'description' => __('Decimal separator for displayed prices for this country.', 'woocommerce'),
289
+								'context'     => array('view'),
290 290
 								'readonly'    => true,
291 291
 							),
292 292
 							'dimension_unit' => array(
293 293
 								'type'        => 'string',
294
-								'description' => __( 'The unit lengths are defined in for this country.', 'woocommerce' ),
295
-								'context'     => array( 'view' ),
294
+								'description' => __('The unit lengths are defined in for this country.', 'woocommerce'),
295
+								'context'     => array('view'),
296 296
 								'readonly'    => true,
297 297
 							),
298 298
 							'name'           => array(
299 299
 								'type'        => 'string',
300
-								'description' => __( 'Full name of country.', 'woocommerce' ),
301
-								'context'     => array( 'view' ),
300
+								'description' => __('Full name of country.', 'woocommerce'),
301
+								'context'     => array('view'),
302 302
 								'readonly'    => true,
303 303
 							),
304 304
 							'num_decimals'   => array(
305 305
 								'type'        => 'integer',
306
-								'description' => __( 'Number of decimal points shown in displayed prices for this country.', 'woocommerce' ),
307
-								'context'     => array( 'view' ),
306
+								'description' => __('Number of decimal points shown in displayed prices for this country.', 'woocommerce'),
307
+								'context'     => array('view'),
308 308
 								'readonly'    => true,
309 309
 							),
310 310
 							'states'         => array(
311 311
 								'type'        => 'array',
312
-								'description' => __( 'List of states in this country.', 'woocommerce' ),
313
-								'context'     => array( 'view' ),
312
+								'description' => __('List of states in this country.', 'woocommerce'),
313
+								'context'     => array('view'),
314 314
 								'readonly'    => true,
315 315
 								'items'       => array(
316 316
 									'type'       => 'object',
317
-									'context'    => array( 'view' ),
317
+									'context'    => array('view'),
318 318
 									'readonly'   => true,
319 319
 									'properties' => array(
320 320
 										'code' => array(
321 321
 											'type'        => 'string',
322
-											'description' => __( 'State code.', 'woocommerce' ),
323
-											'context'     => array( 'view' ),
322
+											'description' => __('State code.', 'woocommerce'),
323
+											'context'     => array('view'),
324 324
 											'readonly'    => true,
325 325
 										),
326 326
 										'name' => array(
327 327
 											'type'        => 'string',
328
-											'description' => __( 'Full name of state.', 'woocommerce' ),
329
-											'context'     => array( 'view' ),
328
+											'description' => __('Full name of state.', 'woocommerce'),
329
+											'context'     => array('view'),
330 330
 											'readonly'    => true,
331 331
 										),
332 332
 									),
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
 							),
335 335
 							'thousand_sep'   => array(
336 336
 								'type'        => 'string',
337
-								'description' => __( 'Thousands separator for displayed prices in this country.', 'woocommerce' ),
338
-								'context'     => array( 'view' ),
337
+								'description' => __('Thousands separator for displayed prices in this country.', 'woocommerce'),
338
+								'context'     => array('view'),
339 339
 								'readonly'    => true,
340 340
 							),
341 341
 							'weight_unit'    => array(
342 342
 								'type'        => 'string',
343
-								'description' => __( 'The unit weights are defined in for this country.', 'woocommerce' ),
344
-								'context'     => array( 'view' ),
343
+								'description' => __('The unit weights are defined in for this country.', 'woocommerce'),
344
+								'context'     => array('view'),
345 345
 								'readonly'    => true,
346 346
 							),
347 347
 						),
@@ -350,6 +350,6 @@  discard block
 block discarded – undo
350 350
 			),
351 351
 		);
352 352
 
353
-		return $this->add_additional_fields_schema( $schema );
353
+		return $this->add_additional_fields_schema($schema);
354 354
 	}
355 355
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Data/Countries.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Data;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Data as DataController;
15 15
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 			array(
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::READABLE,
40
-					'callback'            => array( $this, 'get_items' ),
41
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
+					'callback'            => array($this, 'get_items'),
41
+					'permission_callback' => array($this, 'get_items_permissions_check'),
42 42
 				),
43
-				'schema' => array( $this, 'get_public_item_schema' ),
43
+				'schema' => array($this, 'get_public_item_schema'),
44 44
 			)
45 45
 		);
46 46
 		register_rest_route(
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
 			array(
50 50
 				array(
51 51
 					'methods'             => \WP_REST_Server::READABLE,
52
-					'callback'            => array( $this, 'get_item' ),
53
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
52
+					'callback'            => array($this, 'get_item'),
53
+					'permission_callback' => array($this, 'get_items_permissions_check'),
54 54
 					'args'                => array(
55 55
 						'location' => array(
56
-							'description' => __( 'ISO3166 alpha-2 country code.', 'woocommerce' ),
56
+							'description' => __('ISO3166 alpha-2 country code.', 'woocommerce'),
57 57
 							'type'        => 'string',
58 58
 						),
59 59
 					),
60 60
 				),
61
-				'schema' => array( $this, 'get_public_item_schema' ),
61
+				'schema' => array($this, 'get_public_item_schema'),
62 62
 			)
63 63
 		);
64 64
 	}
@@ -70,23 +70,23 @@  discard block
 block discarded – undo
70 70
 	 * @param  \WP_REST_Request $request      Request data.
71 71
 	 * @return array|mixed Response data, ready for insertion into collection data.
72 72
 	 */
73
-	public function get_country( $country_code = false, $request ) {
73
+	public function get_country($country_code = false, $request) {
74 74
 		$countries = WC()->countries->get_countries();
75 75
 		$states    = WC()->countries->get_states();
76 76
 		$data      = array();
77 77
 
78
-		if ( ! array_key_exists( $country_code, $countries ) ) {
78
+		if ( ! array_key_exists($country_code, $countries)) {
79 79
 			return false;
80 80
 		}
81 81
 
82 82
 		$country = array(
83 83
 			'code' => $country_code,
84
-			'name' => $countries[ $country_code ],
84
+			'name' => $countries[$country_code],
85 85
 		);
86 86
 
87 87
 		$local_states = array();
88
-		if ( isset( $states[ $country_code ] ) ) {
89
-			foreach ( $states[ $country_code ] as $state_code => $state_name ) {
88
+		if (isset($states[$country_code])) {
89
+			foreach ($states[$country_code] as $state_code => $state_name) {
90 90
 				$local_states[] = array(
91 91
 					'code' => $state_code,
92 92
 					'name' => $state_name,
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
 	 * @param  \WP_REST_Request $request Request data.
105 105
 	 * @return \WP_Error\WP_REST_Response
106 106
 	 */
107
-	public function get_items( $request ) {
107
+	public function get_items($request) {
108 108
 		$countries = WC()->countries->get_countries();
109 109
 		$data      = array();
110 110
 
111
-		foreach ( array_keys( $countries ) as $country_code ) {
112
-			$country  = $this->get_country( $country_code, $request );
113
-			$response = $this->prepare_item_for_response( $country, $request );
114
-			$data[]   = $this->prepare_response_for_collection( $response );
111
+		foreach (array_keys($countries) as $country_code) {
112
+			$country  = $this->get_country($country_code, $request);
113
+			$response = $this->prepare_item_for_response($country, $request);
114
+			$data[]   = $this->prepare_response_for_collection($response);
115 115
 		}
116 116
 
117
-		return rest_ensure_response( $data );
117
+		return rest_ensure_response($data);
118 118
 	}
119 119
 
120 120
 	/**
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 	 * @param  \WP_REST_Request $request Request data.
125 125
 	 * @return \WP_Error\WP_REST_Response
126 126
 	 */
127
-	public function get_item( $request ) {
128
-		$data = $this->get_country( strtoupper( $request['location'] ), $request );
129
-		if ( empty( $data ) ) {
130
-			return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) );
127
+	public function get_item($request) {
128
+		$data = $this->get_country(strtoupper($request['location']), $request);
129
+		if (empty($data)) {
130
+			return new \WP_Error('woocommerce_rest_data_invalid_location', __('There are no locations matching these parameters.', 'woocommerce'), array('status' => 404));
131 131
 		}
132
-		return $this->prepare_item_for_response( $data, $request );
132
+		return $this->prepare_item_for_response($data, $request);
133 133
 	}
134 134
 
135 135
 	/**
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 * @param \WP_REST_Request $request Request object.
141 141
 	 * @return \WP_REST_Response $response Response data.
142 142
 	 */
143
-	public function prepare_item_for_response( $item, $request ) {
144
-		$data     = $this->add_additional_fields_to_object( $item, $request );
145
-		$data     = $this->filter_response_by_context( $data, 'view' );
146
-		$response = rest_ensure_response( $data );
143
+	public function prepare_item_for_response($item, $request) {
144
+		$data     = $this->add_additional_fields_to_object($item, $request);
145
+		$data     = $this->filter_response_by_context($data, 'view');
146
+		$response = rest_ensure_response($data);
147 147
 
148
-		$response->add_links( $this->prepare_links( $item ) );
148
+		$response->add_links($this->prepare_links($item));
149 149
 
150 150
 		/**
151 151
 		 * Filter the states list for a country returned from the API.
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		 * @param array            $data     The original country's states list.
157 157
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
158 158
 		 */
159
-		return apply_filters( 'woocommerce_rest_prepare_data_country', $response, $item, $request );
159
+		return apply_filters('woocommerce_rest_prepare_data_country', $response, $item, $request);
160 160
 	}
161 161
 
162 162
 	/**
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
 	 * @param object $item Data object.
166 166
 	 * @return array Links for the given country.
167 167
 	 */
168
-	protected function prepare_links( $item ) {
169
-		$country_code = strtolower( $item['code'] );
168
+	protected function prepare_links($item) {
169
+		$country_code = strtolower($item['code']);
170 170
 		$links        = array(
171 171
 			'self'       => array(
172
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $country_code ) ),
172
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $country_code)),
173 173
 			),
174 174
 			'collection' => array(
175
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
175
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
176 176
 			),
177 177
 		);
178 178
 
@@ -194,36 +194,36 @@  discard block
 block discarded – undo
194 194
 			'properties' => array(
195 195
 				'code'   => array(
196 196
 					'type'        => 'string',
197
-					'description' => __( 'ISO3166 alpha-2 country code.', 'woocommerce' ),
198
-					'context'     => array( 'view' ),
197
+					'description' => __('ISO3166 alpha-2 country code.', 'woocommerce'),
198
+					'context'     => array('view'),
199 199
 					'readonly'    => true,
200 200
 				),
201 201
 				'name'   => array(
202 202
 					'type'        => 'string',
203
-					'description' => __( 'Full name of country.', 'woocommerce' ),
204
-					'context'     => array( 'view' ),
203
+					'description' => __('Full name of country.', 'woocommerce'),
204
+					'context'     => array('view'),
205 205
 					'readonly'    => true,
206 206
 				),
207 207
 				'states' => array(
208 208
 					'type'        => 'array',
209
-					'description' => __( 'List of states in this country.', 'woocommerce' ),
210
-					'context'     => array( 'view' ),
209
+					'description' => __('List of states in this country.', 'woocommerce'),
210
+					'context'     => array('view'),
211 211
 					'readonly'    => true,
212 212
 					'items'       => array(
213 213
 						'type'       => 'object',
214
-						'context'    => array( 'view' ),
214
+						'context'    => array('view'),
215 215
 						'readonly'   => true,
216 216
 						'properties' => array(
217 217
 							'code' => array(
218 218
 								'type'        => 'string',
219
-								'description' => __( 'State code.', 'woocommerce' ),
220
-								'context'     => array( 'view' ),
219
+								'description' => __('State code.', 'woocommerce'),
220
+								'context'     => array('view'),
221 221
 								'readonly'    => true,
222 222
 							),
223 223
 							'name' => array(
224 224
 								'type'        => 'string',
225
-								'description' => __( 'Full name of state.', 'woocommerce' ),
226
-								'context'     => array( 'view' ),
225
+								'description' => __('Full name of state.', 'woocommerce'),
226
+								'context'     => array('view'),
227 227
 								'readonly'    => true,
228 228
 							),
229 229
 						),
@@ -232,6 +232,6 @@  discard block
 block discarded – undo
232 232
 			),
233 233
 		);
234 234
 
235
-		return $this->add_additional_fields_schema( $schema );
235
+		return $this->add_additional_fields_schema($schema);
236 236
 	}
237 237
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports/PerformanceIndicators.php 1 patch
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Reports;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
15 15
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 			array(
64 64
 				array(
65 65
 					'methods'             => \WP_REST_Server::READABLE,
66
-					'callback'            => array( $this, 'get_items' ),
67
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
66
+					'callback'            => array($this, 'get_items'),
67
+					'permission_callback' => array($this, 'get_items_permissions_check'),
68 68
 					'args'                => $this->get_collection_params(),
69 69
 				),
70
-				'schema' => array( $this, 'get_public_item_schema' ),
70
+				'schema' => array($this, 'get_public_item_schema'),
71 71
 			)
72 72
 		);
73 73
 
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 			array(
78 78
 				array(
79 79
 					'methods'             => \WP_REST_Server::READABLE,
80
-					'callback'            => array( $this, 'get_allowed_items' ),
81
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
80
+					'callback'            => array($this, 'get_allowed_items'),
81
+					'permission_callback' => array($this, 'get_items_permissions_check'),
82 82
 					'args'                => $this->get_collection_params(),
83 83
 				),
84
-				'schema' => array( $this, 'get_public_allowed_item_schema' ),
84
+				'schema' => array($this, 'get_public_allowed_item_schema'),
85 85
 			)
86 86
 		);
87 87
 	}
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @param array $request Request array.
93 93
 	 * @return array
94 94
 	 */
95
-	protected function prepare_reports_query( $request ) {
95
+	protected function prepare_reports_query($request) {
96 96
 		$args           = array();
97 97
 		$args['before'] = $request['before'];
98 98
 		$args['after']  = $request['after'];
@@ -107,44 +107,44 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	private function get_indicator_data() {
109 109
 		// Data already retrieved.
110
-		if ( ! empty( $this->endpoints ) && ! empty( $this->labels ) && ! empty( $this->allowed_stats ) ) {
110
+		if ( ! empty($this->endpoints) && ! empty($this->labels) && ! empty($this->allowed_stats)) {
111 111
 			return true;
112 112
 		}
113 113
 
114
-		$request       = new \WP_REST_Request( 'GET', '/wc/v4/reports' );
115
-		$response      = rest_do_request( $request );
114
+		$request       = new \WP_REST_Request('GET', '/wc/v4/reports');
115
+		$response      = rest_do_request($request);
116 116
 		$endpoints     = $response->get_data();
117 117
 		$allowed_stats = array();
118
-		if ( 200 !== $response->get_status() ) {
119
-			return new \WP_Error( 'woocommerce_reports_performance_indicators_result_failed', __( 'Sorry, fetching performance indicators failed.', 'woocommerce' ) );
118
+		if (200 !== $response->get_status()) {
119
+			return new \WP_Error('woocommerce_reports_performance_indicators_result_failed', __('Sorry, fetching performance indicators failed.', 'woocommerce'));
120 120
 		}
121 121
 
122
-		foreach ( $endpoints as $endpoint ) {
123
-			if ( '/stats' === substr( $endpoint['slug'], -6 ) ) {
124
-				$request  = new \WP_REST_Request( 'OPTIONS', $endpoint['path'] );
125
-				$response = rest_do_request( $request );
122
+		foreach ($endpoints as $endpoint) {
123
+			if ('/stats' === substr($endpoint['slug'], -6)) {
124
+				$request  = new \WP_REST_Request('OPTIONS', $endpoint['path']);
125
+				$response = rest_do_request($request);
126 126
 				$data     = $response->get_data();
127 127
 
128
-				$prefix = substr( $endpoint['slug'], 0, -6 );
128
+				$prefix = substr($endpoint['slug'], 0, -6);
129 129
 
130
-				if ( empty( $data['schema']['properties']['totals']['properties'] ) ) {
130
+				if (empty($data['schema']['properties']['totals']['properties'])) {
131 131
 					continue;
132 132
 				}
133 133
 
134
-				foreach ( $data['schema']['properties']['totals']['properties'] as $property_key => $schema_info ) {
135
-					if ( empty( $schema_info['indicator'] ) || ! $schema_info['indicator'] ) {
134
+				foreach ($data['schema']['properties']['totals']['properties'] as $property_key => $schema_info) {
135
+					if (empty($schema_info['indicator']) || ! $schema_info['indicator']) {
136 136
 						continue;
137 137
 					}
138 138
 
139 139
 					$stat            = $prefix . '/' . $property_key;
140 140
 					$allowed_stats[] = $stat;
141 141
 
142
-					$this->labels[ $stat ]  = trim( preg_replace( '/\W+/', ' ', $schema_info['description'] ) );
143
-					$this->formats[ $stat ] = isset( $schema_info['format'] ) ? $schema_info['format'] : 'number';
142
+					$this->labels[$stat]  = trim(preg_replace('/\W+/', ' ', $schema_info['description']));
143
+					$this->formats[$stat] = isset($schema_info['format']) ? $schema_info['format'] : 'number';
144 144
 				}
145 145
 
146
-				$this->endpoints[ $prefix ] = $endpoint['path'];
147
-				$this->urls[ $prefix ]      = $endpoint['_links']['report'][0]['href'];
146
+				$this->endpoints[$prefix] = $endpoint['path'];
147
+				$this->urls[$prefix]      = $endpoint['_links']['report'][0]['href'];
148 148
 			}
149 149
 		}
150 150
 
@@ -158,37 +158,37 @@  discard block
 block discarded – undo
158 158
 	 * @param  \WP_REST_Request $request Request data.
159 159
 	 * @return array|\WP_Error
160 160
 	 */
161
-	public function get_allowed_items( $request ) {
161
+	public function get_allowed_items($request) {
162 162
 		$indicator_data = $this->get_indicator_data();
163
-		if ( is_wp_error( $indicator_data ) ) {
163
+		if (is_wp_error($indicator_data)) {
164 164
 			return $indicator_data;
165 165
 		}
166 166
 
167 167
 		$data = array();
168
-		foreach ( $this->allowed_stats as $stat ) {
169
-			$pieces = $this->get_stats_parts( $stat );
168
+		foreach ($this->allowed_stats as $stat) {
169
+			$pieces = $this->get_stats_parts($stat);
170 170
 			$report = $pieces[0];
171 171
 			$chart  = $pieces[1];
172 172
 			$data[] = (object) array(
173 173
 				'stat'  => $stat,
174 174
 				'chart' => $chart,
175
-				'label' => $this->labels[ $stat ],
175
+				'label' => $this->labels[$stat],
176 176
 			);
177 177
 		}
178 178
 
179
-		usort( $data, array( $this, 'sort' ) );
179
+		usort($data, array($this, 'sort'));
180 180
 
181 181
 		$objects = array();
182
-		foreach ( $data as $item ) {
183
-			$prepared  = $this->prepare_item_for_response( $item, $request );
184
-			$objects[] = $this->prepare_response_for_collection( $prepared );
182
+		foreach ($data as $item) {
183
+			$prepared  = $this->prepare_item_for_response($item, $request);
184
+			$objects[] = $this->prepare_response_for_collection($prepared);
185 185
 		}
186 186
 
187
-		$response = rest_ensure_response( $objects );
188
-		$response->header( 'X-WP-Total', count( $data ) );
189
-		$response->header( 'X-WP-TotalPages', 1 );
187
+		$response = rest_ensure_response($objects);
188
+		$response->header('X-WP-Total', count($data));
189
+		$response->header('X-WP-TotalPages', 1);
190 190
 
191
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
191
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
192 192
 
193 193
 		return $response;
194 194
 	}
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 * @param object $b Second item.
202 202
 	 * @return order
203 203
 	 */
204
-	public function sort( $a, $b ) {
204
+	public function sort($a, $b) {
205 205
 		/**
206 206
 		 * Custom ordering for store performance indicators.
207 207
 		 *
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 			)
228 228
 		);
229 229
 
230
-		$a = array_search( $a->stat, $stat_order );
231
-		$b = array_search( $b->stat, $stat_order );
230
+		$a = array_search($a->stat, $stat_order);
231
+		$b = array_search($b->stat, $stat_order);
232 232
 
233
-		if ( false === $a && false === $b ) {
233
+		if (false === $a && false === $b) {
234 234
 			return 0;
235
-		} elseif ( false === $a ) {
235
+		} elseif (false === $a) {
236 236
 			return 1;
237
-		} elseif ( false === $b ) {
237
+		} elseif (false === $b) {
238 238
 			return -1;
239 239
 		} else {
240 240
 			return $a - $b;
@@ -247,41 +247,41 @@  discard block
 block discarded – undo
247 247
 	 * @param  \WP_REST_Request $request Request data.
248 248
 	 * @return array|\WP_Error
249 249
 	 */
250
-	public function get_items( $request ) {
250
+	public function get_items($request) {
251 251
 		$indicator_data = $this->get_indicator_data();
252
-		if ( is_wp_error( $indicator_data ) ) {
252
+		if (is_wp_error($indicator_data)) {
253 253
 			return $indicator_data;
254 254
 		}
255 255
 
256
-		$query_args = $this->prepare_reports_query( $request );
257
-		if ( empty( $query_args['stats'] ) ) {
258
-			return new \WP_Error( 'woocommerce_reports_performance_indicators_empty_query', __( 'A list of stats to query must be provided.', 'woocommerce' ), 400 );
256
+		$query_args = $this->prepare_reports_query($request);
257
+		if (empty($query_args['stats'])) {
258
+			return new \WP_Error('woocommerce_reports_performance_indicators_empty_query', __('A list of stats to query must be provided.', 'woocommerce'), 400);
259 259
 		}
260 260
 
261 261
 		$stats = array();
262
-		foreach ( $query_args['stats'] as $stat ) {
262
+		foreach ($query_args['stats'] as $stat) {
263 263
 			$is_error = false;
264 264
 
265
-			$pieces = $this->get_stats_parts( $stat );
265
+			$pieces = $this->get_stats_parts($stat);
266 266
 			$report = $pieces[0];
267 267
 			$chart  = $pieces[1];
268 268
 
269
-			if ( ! in_array( $stat, $this->allowed_stats ) ) {
269
+			if ( ! in_array($stat, $this->allowed_stats)) {
270 270
 				continue;
271 271
 			}
272 272
 
273
-			$request_url = $this->endpoints[ $report ];
274
-			$request     = new \WP_REST_Request( 'GET', $request_url );
275
-			$request->set_param( 'before', $query_args['before'] );
276
-			$request->set_param( 'after', $query_args['after'] );
273
+			$request_url = $this->endpoints[$report];
274
+			$request     = new \WP_REST_Request('GET', $request_url);
275
+			$request->set_param('before', $query_args['before']);
276
+			$request->set_param('after', $query_args['after']);
277 277
 
278
-			$response = rest_do_request( $request );
278
+			$response = rest_do_request($request);
279 279
 
280 280
 			$data   = $response->get_data();
281
-			$format = $this->formats[ $stat ];
282
-			$label  = $this->labels[ $stat ];
281
+			$format = $this->formats[$stat];
282
+			$label  = $this->labels[$stat];
283 283
 
284
-			if ( 200 !== $response->get_status() || ! isset( $data['totals'][ $chart ] ) ) {
284
+			if (200 !== $response->get_status() || ! isset($data['totals'][$chart])) {
285 285
 				$stats[] = (object) array(
286 286
 					'stat'   => $stat,
287 287
 					'chart'  => $chart,
@@ -297,23 +297,23 @@  discard block
 block discarded – undo
297 297
 				'chart'  => $chart,
298 298
 				'label'  => $label,
299 299
 				'format' => $format,
300
-				'value'  => $data['totals'][ $chart ],
300
+				'value'  => $data['totals'][$chart],
301 301
 			);
302 302
 		}
303 303
 
304
-		usort( $stats, array( $this, 'sort' ) );
304
+		usort($stats, array($this, 'sort'));
305 305
 
306 306
 		$objects = array();
307
-		foreach ( $stats as $stat ) {
308
-			$data      = $this->prepare_item_for_response( $stat, $request );
309
-			$objects[] = $this->prepare_response_for_collection( $data );
307
+		foreach ($stats as $stat) {
308
+			$data      = $this->prepare_item_for_response($stat, $request);
309
+			$objects[] = $this->prepare_response_for_collection($data);
310 310
 		}
311 311
 
312
-		$response = rest_ensure_response( $objects );
313
-		$response->header( 'X-WP-Total', count( $stats ) );
314
-		$response->header( 'X-WP-TotalPages', 1 );
312
+		$response = rest_ensure_response($objects);
313
+		$response->header('X-WP-Total', count($stats));
314
+		$response->header('X-WP-TotalPages', 1);
315 315
 
316
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
316
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
317 317
 
318 318
 		return $response;
319 319
 	}
@@ -325,15 +325,15 @@  discard block
 block discarded – undo
325 325
 	 * @param \WP_REST_Request $request Request object.
326 326
 	 * @return \WP_REST_Response
327 327
 	 */
328
-	public function prepare_item_for_response( $stat_data, $request ) {
329
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
330
-		$data    = $this->add_additional_fields_to_object( $stat_data, $request );
331
-		$data    = $this->filter_response_by_context( $data, $context );
328
+	public function prepare_item_for_response($stat_data, $request) {
329
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
330
+		$data    = $this->add_additional_fields_to_object($stat_data, $request);
331
+		$data    = $this->filter_response_by_context($data, $context);
332 332
 
333 333
 		// Wrap the data in a response object.
334
-		$response = rest_ensure_response( $data );
334
+		$response = rest_ensure_response($data);
335 335
 
336
-		$response->add_links( $this->prepare_links( $data ) );
336
+		$response->add_links($this->prepare_links($data));
337 337
 
338 338
 		/**
339 339
 		 * Filter a report returned from the API.
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 		 * @param object           $report   The original report object.
345 345
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
346 346
 		 */
347
-		return apply_filters( 'woocommerce_rest_prepare_report_performance_indicators', $response, $stat_data, $request );
347
+		return apply_filters('woocommerce_rest_prepare_report_performance_indicators', $response, $stat_data, $request);
348 348
 	}
349 349
 
350 350
 	/**
@@ -353,18 +353,18 @@  discard block
 block discarded – undo
353 353
 	 * @param WC_Admin_Reports_Query $object Object data.
354 354
 	 * @return array
355 355
 	 */
356
-	protected function prepare_links( $object ) {
357
-		$pieces   = $this->get_stats_parts( $object->stat );
356
+	protected function prepare_links($object) {
357
+		$pieces   = $this->get_stats_parts($object->stat);
358 358
 		$endpoint = $pieces[0];
359 359
 		$stat     = $pieces[1];
360
-		$url      = $this->urls[ $endpoint ];
360
+		$url      = $this->urls[$endpoint];
361 361
 
362 362
 		$links = array(
363 363
 			'api'    => array(
364
-				'href' => rest_url( $this->endpoints[ $endpoint ] ),
364
+				'href' => rest_url($this->endpoints[$endpoint]),
365 365
 			),
366 366
 			'report' => array(
367
-				'href' => ! empty( $url ) ? $url : '',
367
+				'href' => ! empty($url) ? $url : '',
368 368
 			),
369 369
 		);
370 370
 
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
 	 * @param string $full_stat A stat request string like orders/avg_order_value or fue/emails/sent.
379 379
 	 * @return array Containing the prefix (endpoint) and suffix (stat).
380 380
 	 */
381
-	private function get_stats_parts( $full_stat ) {
382
-		$endpoint = substr( $full_stat, 0, strrpos( $full_stat, '/' ) );
383
-		$stat     = substr( $full_stat, ( strrpos( $full_stat, '/' ) + 1 ) );
381
+	private function get_stats_parts($full_stat) {
382
+		$endpoint = substr($full_stat, 0, strrpos($full_stat, '/'));
383
+		$stat     = substr($full_stat, (strrpos($full_stat, '/') + 1));
384 384
 		return array(
385 385
 			$endpoint,
386 386
 			$stat,
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 	 */
395 395
 	public function get_item_schema() {
396 396
 		$indicator_data = $this->get_indicator_data();
397
-		if ( is_wp_error( $indicator_data ) ) {
397
+		if (is_wp_error($indicator_data)) {
398 398
 			$allowed_stats = array();
399 399
 		} else {
400 400
 			$allowed_stats = $this->allowed_stats;
@@ -406,41 +406,41 @@  discard block
 block discarded – undo
406 406
 			'type'       => 'object',
407 407
 			'properties' => array(
408 408
 				'stat'   => array(
409
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
409
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
410 410
 					'type'        => 'string',
411
-					'context'     => array( 'view', 'edit' ),
411
+					'context'     => array('view', 'edit'),
412 412
 					'readonly'    => true,
413 413
 					'enum'        => $allowed_stats,
414 414
 				),
415 415
 				'chart'  => array(
416
-					'description' => __( 'The specific chart this stat referrers to.', 'woocommerce' ),
416
+					'description' => __('The specific chart this stat referrers to.', 'woocommerce'),
417 417
 					'type'        => 'string',
418
-					'context'     => array( 'view', 'edit' ),
418
+					'context'     => array('view', 'edit'),
419 419
 					'readonly'    => true,
420 420
 				),
421 421
 				'label'  => array(
422
-					'description' => __( 'Human readable label for the stat.', 'woocommerce' ),
422
+					'description' => __('Human readable label for the stat.', 'woocommerce'),
423 423
 					'type'        => 'string',
424
-					'context'     => array( 'view', 'edit' ),
424
+					'context'     => array('view', 'edit'),
425 425
 					'readonly'    => true,
426 426
 				),
427 427
 				'format' => array(
428
-					'description' => __( 'Format of the stat.', 'woocommerce' ),
428
+					'description' => __('Format of the stat.', 'woocommerce'),
429 429
 					'type'        => 'number',
430
-					'context'     => array( 'view', 'edit' ),
430
+					'context'     => array('view', 'edit'),
431 431
 					'readonly'    => true,
432
-					'enum'        => array( 'number', 'currency' ),
432
+					'enum'        => array('number', 'currency'),
433 433
 				),
434 434
 				'value'  => array(
435
-					'description' => __( 'Value of the stat. Returns null if the stat does not exist or cannot be loaded.', 'woocommerce' ),
435
+					'description' => __('Value of the stat. Returns null if the stat does not exist or cannot be loaded.', 'woocommerce'),
436 436
 					'type'        => 'number',
437
-					'context'     => array( 'view', 'edit' ),
437
+					'context'     => array('view', 'edit'),
438 438
 					'readonly'    => true,
439 439
 				),
440 440
 			),
441 441
 		);
442 442
 
443
-		return $this->add_additional_fields_schema( $schema );
443
+		return $this->add_additional_fields_schema($schema);
444 444
 	}
445 445
 
446 446
 	/**
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
 	 */
451 451
 	public function get_public_allowed_item_schema() {
452 452
 		$schema = $this->get_public_item_schema();
453
-		unset( $schema['properties']['value'] );
454
-		unset( $schema['properties']['format'] );
453
+		unset($schema['properties']['value']);
454
+		unset($schema['properties']['format']);
455 455
 		return $schema;
456 456
 	}
457 457
 
@@ -462,18 +462,18 @@  discard block
 block discarded – undo
462 462
 	 */
463 463
 	public function get_collection_params() {
464 464
 		$indicator_data = $this->get_indicator_data();
465
-		if ( is_wp_error( $indicator_data ) ) {
466
-			$allowed_stats = __( 'There was an issue loading the report endpoints', 'woocommerce' );
465
+		if (is_wp_error($indicator_data)) {
466
+			$allowed_stats = __('There was an issue loading the report endpoints', 'woocommerce');
467 467
 		} else {
468
-			$allowed_stats = implode( ', ', $this->allowed_stats );
468
+			$allowed_stats = implode(', ', $this->allowed_stats);
469 469
 		}
470 470
 
471 471
 		$params            = array();
472
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
472
+		$params['context'] = $this->get_context_param(array('default' => 'view'));
473 473
 		$params['stats']   = array(
474 474
 			'description'       => sprintf(
475 475
 				/* translators: Allowed values is a list of stat endpoints. */
476
-				__( 'Limit response to specific report stats. Allowed values: %s.', 'woocommerce' ),
476
+				__('Limit response to specific report stats. Allowed values: %s.', 'woocommerce'),
477 477
 				$allowed_stats
478 478
 			),
479 479
 			'type'              => 'array',
@@ -482,14 +482,14 @@  discard block
 block discarded – undo
482 482
 				'type' => 'string',
483 483
 			),
484 484
 		);
485
-		$params['after']   = array(
486
-			'description'       => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
485
+		$params['after'] = array(
486
+			'description'       => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
487 487
 			'type'              => 'string',
488 488
 			'format'            => 'date-time',
489 489
 			'validate_callback' => 'rest_validate_request_arg',
490 490
 		);
491
-		$params['before']  = array(
492
-			'description'       => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
491
+		$params['before'] = array(
492
+			'description'       => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
493 493
 			'type'              => 'string',
494 494
 			'format'            => 'date-time',
495 495
 			'validate_callback' => 'rest_validate_request_arg',
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports/RevenueStats.php 1 patch
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Reports;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
15 15
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @param array $request Request array.
32 32
 	 * @return array
33 33
 	 */
34
-	protected function prepare_reports_query( $request ) {
34
+	protected function prepare_reports_query($request) {
35 35
 		$args              = array();
36 36
 		$args['before']    = $request['before'];
37 37
 		$args['after']     = $request['after'];
@@ -51,44 +51,44 @@  discard block
 block discarded – undo
51 51
 	 * @param \WP_REST_Request $request Request data.
52 52
 	 * @return array|\WP_Error
53 53
 	 */
54
-	public function get_items( $request ) {
55
-		$query_args      = $this->prepare_reports_query( $request );
56
-		$reports_revenue = new \WC_Admin_Reports_Revenue_Query( $query_args );
54
+	public function get_items($request) {
55
+		$query_args      = $this->prepare_reports_query($request);
56
+		$reports_revenue = new \WC_Admin_Reports_Revenue_Query($query_args);
57 57
 		try {
58 58
 			$report_data = $reports_revenue->get_data();
59
-		} catch ( WC_Admin_Reports_Parameter_Exception $e ) {
60
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
59
+		} catch (WC_Admin_Reports_Parameter_Exception $e) {
60
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
61 61
 		}
62 62
 
63 63
 		$out_data = array(
64
-			'totals'    => get_object_vars( $report_data->totals ),
64
+			'totals'    => get_object_vars($report_data->totals),
65 65
 			'intervals' => array(),
66 66
 		);
67 67
 
68
-		foreach ( $report_data->intervals as $interval_data ) {
69
-			$item                    = $this->prepare_item_for_response( $interval_data, $request );
70
-			$out_data['intervals'][] = $this->prepare_response_for_collection( $item );
68
+		foreach ($report_data->intervals as $interval_data) {
69
+			$item                    = $this->prepare_item_for_response($interval_data, $request);
70
+			$out_data['intervals'][] = $this->prepare_response_for_collection($item);
71 71
 		}
72 72
 
73
-		$response = rest_ensure_response( $out_data );
74
-		$response->header( 'X-WP-Total', (int) $report_data->total );
75
-		$response->header( 'X-WP-TotalPages', (int) $report_data->pages );
73
+		$response = rest_ensure_response($out_data);
74
+		$response->header('X-WP-Total', (int) $report_data->total);
75
+		$response->header('X-WP-TotalPages', (int) $report_data->pages);
76 76
 
77 77
 		$page      = $report_data->page_no;
78 78
 		$max_pages = $report_data->pages;
79
-		$base      = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
80
-		if ( $page > 1 ) {
79
+		$base      = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
80
+		if ($page > 1) {
81 81
 			$prev_page = $page - 1;
82
-			if ( $prev_page > $max_pages ) {
82
+			if ($prev_page > $max_pages) {
83 83
 				$prev_page = $max_pages;
84 84
 			}
85
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
86
-			$response->link_header( 'prev', $prev_link );
85
+			$prev_link = add_query_arg('page', $prev_page, $base);
86
+			$response->link_header('prev', $prev_link);
87 87
 		}
88
-		if ( $max_pages > $page ) {
88
+		if ($max_pages > $page) {
89 89
 			$next_page = $page + 1;
90
-			$next_link = add_query_arg( 'page', $next_page, $base );
91
-			$response->link_header( 'next', $next_link );
90
+			$next_link = add_query_arg('page', $next_page, $base);
91
+			$response->link_header('next', $next_link);
92 92
 		}
93 93
 
94 94
 		return $response;
@@ -101,15 +101,15 @@  discard block
 block discarded – undo
101 101
 	 * @param \WP_REST_Request $request Request object.
102 102
 	 * @return \WP_REST_Response
103 103
 	 */
104
-	public function prepare_item_for_response( $report, $request ) {
104
+	public function prepare_item_for_response($report, $request) {
105 105
 		$data = $report;
106 106
 
107
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
108
-		$data    = $this->add_additional_fields_to_object( $data, $request );
109
-		$data    = $this->filter_response_by_context( $data, $context );
107
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
108
+		$data    = $this->add_additional_fields_to_object($data, $request);
109
+		$data    = $this->filter_response_by_context($data, $context);
110 110
 
111 111
 		// Wrap the data in a response object.
112
-		$response = rest_ensure_response( $data );
112
+		$response = rest_ensure_response($data);
113 113
 
114 114
 		/**
115 115
 		 * Filter a report returned from the API.
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		 * @param object           $report   The original report object.
121 121
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
122 122
 		 */
123
-		return apply_filters( 'woocommerce_rest_prepare_report_revenue_stats', $response, $report, $request );
123
+		return apply_filters('woocommerce_rest_prepare_report_revenue_stats', $response, $report, $request);
124 124
 	}
125 125
 
126 126
 	/**
@@ -131,96 +131,96 @@  discard block
 block discarded – undo
131 131
 	public function get_item_schema() {
132 132
 		$data_values = array(
133 133
 			'gross_revenue'  => array(
134
-				'description' => __( 'Gross revenue.', 'woocommerce' ),
134
+				'description' => __('Gross revenue.', 'woocommerce'),
135 135
 				'type'        => 'number',
136
-				'context'     => array( 'view', 'edit' ),
136
+				'context'     => array('view', 'edit'),
137 137
 				'readonly'    => true,
138 138
 				'indicator'   => true,
139 139
 				'format'      => 'currency',
140 140
 			),
141 141
 			'net_revenue'    => array(
142
-				'description' => __( 'Net revenue.', 'woocommerce' ),
142
+				'description' => __('Net revenue.', 'woocommerce'),
143 143
 				'type'        => 'number',
144
-				'context'     => array( 'view', 'edit' ),
144
+				'context'     => array('view', 'edit'),
145 145
 				'readonly'    => true,
146 146
 				'indicator'   => true,
147 147
 				'format'      => 'currency',
148 148
 			),
149 149
 			'coupons'        => array(
150
-				'description' => __( 'Amount discounted by coupons.', 'woocommerce' ),
150
+				'description' => __('Amount discounted by coupons.', 'woocommerce'),
151 151
 				'type'        => 'number',
152
-				'context'     => array( 'view', 'edit' ),
152
+				'context'     => array('view', 'edit'),
153 153
 				'readonly'    => true,
154 154
 			),
155 155
 			'coupons_count'  => array(
156
-				'description' => __( 'Unique coupons count.', 'woocommerce' ),
156
+				'description' => __('Unique coupons count.', 'woocommerce'),
157 157
 				'type'        => 'number',
158
-				'context'     => array( 'view', 'edit' ),
158
+				'context'     => array('view', 'edit'),
159 159
 				'readonly'    => true,
160 160
 				'format'      => 'currency',
161 161
 			),
162 162
 			'shipping'       => array(
163
-				'description' => __( 'Total of shipping.', 'woocommerce' ),
163
+				'description' => __('Total of shipping.', 'woocommerce'),
164 164
 				'type'        => 'number',
165
-				'context'     => array( 'view', 'edit' ),
165
+				'context'     => array('view', 'edit'),
166 166
 				'readonly'    => true,
167 167
 				'indicator'   => true,
168 168
 				'format'      => 'currency',
169 169
 			),
170 170
 			'taxes'          => array(
171
-				'description' => __( 'Total of taxes.', 'woocommerce' ),
171
+				'description' => __('Total of taxes.', 'woocommerce'),
172 172
 				'type'        => 'number',
173
-				'context'     => array( 'view', 'edit' ),
173
+				'context'     => array('view', 'edit'),
174 174
 				'readonly'    => true,
175 175
 				'format'      => 'currency',
176 176
 			),
177 177
 			'refunds'        => array(
178
-				'description' => __( 'Total of refunds.', 'woocommerce' ),
178
+				'description' => __('Total of refunds.', 'woocommerce'),
179 179
 				'type'        => 'number',
180
-				'context'     => array( 'view', 'edit' ),
180
+				'context'     => array('view', 'edit'),
181 181
 				'readonly'    => true,
182 182
 				'indicator'   => true,
183 183
 				'format'      => 'currency',
184 184
 			),
185 185
 			'orders_count'   => array(
186
-				'description' => __( 'Amount of orders.', 'woocommerce' ),
186
+				'description' => __('Amount of orders.', 'woocommerce'),
187 187
 				'type'        => 'integer',
188
-				'context'     => array( 'view', 'edit' ),
188
+				'context'     => array('view', 'edit'),
189 189
 				'readonly'    => true,
190 190
 			),
191 191
 			'num_items_sold' => array(
192
-				'description' => __( 'Items sold.', 'woocommerce' ),
192
+				'description' => __('Items sold.', 'woocommerce'),
193 193
 				'type'        => 'integer',
194
-				'context'     => array( 'view', 'edit' ),
194
+				'context'     => array('view', 'edit'),
195 195
 				'readonly'    => true,
196 196
 			),
197 197
 			'products'       => array(
198
-				'description' => __( 'Products sold.', 'woocommerce' ),
198
+				'description' => __('Products sold.', 'woocommerce'),
199 199
 				'type'        => 'integer',
200
-				'context'     => array( 'view', 'edit' ),
200
+				'context'     => array('view', 'edit'),
201 201
 				'readonly'    => true,
202 202
 			),
203 203
 		);
204 204
 
205 205
 		$segments = array(
206 206
 			'segments' => array(
207
-				'description' => __( 'Reports data grouped by segment condition.', 'woocommerce' ),
207
+				'description' => __('Reports data grouped by segment condition.', 'woocommerce'),
208 208
 				'type'        => 'array',
209
-				'context'     => array( 'view', 'edit' ),
209
+				'context'     => array('view', 'edit'),
210 210
 				'readonly'    => true,
211 211
 				'items'       => array(
212 212
 					'type'       => 'object',
213 213
 					'properties' => array(
214 214
 						'segment_id' => array(
215
-							'description' => __( 'Segment identificator.', 'woocommerce' ),
215
+							'description' => __('Segment identificator.', 'woocommerce'),
216 216
 							'type'        => 'integer',
217
-							'context'     => array( 'view', 'edit' ),
217
+							'context'     => array('view', 'edit'),
218 218
 							'readonly'    => true,
219 219
 						),
220 220
 						'subtotals'  => array(
221
-							'description' => __( 'Interval subtotals.', 'woocommerce' ),
221
+							'description' => __('Interval subtotals.', 'woocommerce'),
222 222
 							'type'        => 'object',
223
-							'context'     => array( 'view', 'edit' ),
223
+							'context'     => array('view', 'edit'),
224 224
 							'readonly'    => true,
225 225
 							'properties'  => $data_values,
226 226
 						),
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
 			),
230 230
 		);
231 231
 
232
-		$totals = array_merge( $data_values, $segments );
232
+		$totals = array_merge($data_values, $segments);
233 233
 
234 234
 		// Products is not shown in intervals.
235
-		unset( $data_values['products'] );
235
+		unset($data_values['products']);
236 236
 
237
-		$intervals = array_merge( $data_values, $segments );
237
+		$intervals = array_merge($data_values, $segments);
238 238
 
239 239
 		$schema = array(
240 240
 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
@@ -242,55 +242,55 @@  discard block
 block discarded – undo
242 242
 			'type'       => 'object',
243 243
 			'properties' => array(
244 244
 				'totals'    => array(
245
-					'description' => __( 'Totals data.', 'woocommerce' ),
245
+					'description' => __('Totals data.', 'woocommerce'),
246 246
 					'type'        => 'object',
247
-					'context'     => array( 'view', 'edit' ),
247
+					'context'     => array('view', 'edit'),
248 248
 					'readonly'    => true,
249 249
 					'properties'  => $totals,
250 250
 				),
251 251
 				'intervals' => array(
252
-					'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ),
252
+					'description' => __('Reports data grouped by intervals.', 'woocommerce'),
253 253
 					'type'        => 'array',
254
-					'context'     => array( 'view', 'edit' ),
254
+					'context'     => array('view', 'edit'),
255 255
 					'readonly'    => true,
256 256
 					'items'       => array(
257 257
 						'type'       => 'object',
258 258
 						'properties' => array(
259 259
 							'interval'       => array(
260
-								'description' => __( 'Type of interval.', 'woocommerce' ),
260
+								'description' => __('Type of interval.', 'woocommerce'),
261 261
 								'type'        => 'string',
262
-								'context'     => array( 'view', 'edit' ),
262
+								'context'     => array('view', 'edit'),
263 263
 								'readonly'    => true,
264
-								'enum'        => array( 'day', 'week', 'month', 'year' ),
264
+								'enum'        => array('day', 'week', 'month', 'year'),
265 265
 							),
266 266
 							'date_start'     => array(
267
-								'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ),
267
+								'description' => __("The date the report start, in the site's timezone.", 'woocommerce'),
268 268
 								'type'        => 'date-time',
269
-								'context'     => array( 'view', 'edit' ),
269
+								'context'     => array('view', 'edit'),
270 270
 								'readonly'    => true,
271 271
 							),
272 272
 							'date_start_gmt' => array(
273
-								'description' => __( 'The date the report start, as GMT.', 'woocommerce' ),
273
+								'description' => __('The date the report start, as GMT.', 'woocommerce'),
274 274
 								'type'        => 'date-time',
275
-								'context'     => array( 'view', 'edit' ),
275
+								'context'     => array('view', 'edit'),
276 276
 								'readonly'    => true,
277 277
 							),
278 278
 							'date_end'       => array(
279
-								'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ),
279
+								'description' => __("The date the report end, in the site's timezone.", 'woocommerce'),
280 280
 								'type'        => 'date-time',
281
-								'context'     => array( 'view', 'edit' ),
281
+								'context'     => array('view', 'edit'),
282 282
 								'readonly'    => true,
283 283
 							),
284 284
 							'date_end_gmt'   => array(
285
-								'description' => __( 'The date the report end, as GMT.', 'woocommerce' ),
285
+								'description' => __('The date the report end, as GMT.', 'woocommerce'),
286 286
 								'type'        => 'date-time',
287
-								'context'     => array( 'view', 'edit' ),
287
+								'context'     => array('view', 'edit'),
288 288
 								'readonly'    => true,
289 289
 							),
290 290
 							'subtotals'      => array(
291
-								'description' => __( 'Interval subtotals.', 'woocommerce' ),
291
+								'description' => __('Interval subtotals.', 'woocommerce'),
292 292
 								'type'        => 'object',
293
-								'context'     => array( 'view', 'edit' ),
293
+								'context'     => array('view', 'edit'),
294 294
 								'readonly'    => true,
295 295
 								'properties'  => $intervals,
296 296
 							),
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 			),
301 301
 		);
302 302
 
303
-		return $this->add_additional_fields_schema( $schema );
303
+		return $this->add_additional_fields_schema($schema);
304 304
 	}
305 305
 
306 306
 	/**
@@ -310,17 +310,17 @@  discard block
 block discarded – undo
310 310
 	 */
311 311
 	public function get_collection_params() {
312 312
 		$params              = array();
313
-		$params['context']   = $this->get_context_param( array( 'default' => 'view' ) );
313
+		$params['context']   = $this->get_context_param(array('default' => 'view'));
314 314
 		$params['page']      = array(
315
-			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
315
+			'description'       => __('Current page of the collection.', 'woocommerce'),
316 316
 			'type'              => 'integer',
317 317
 			'default'           => 1,
318 318
 			'sanitize_callback' => 'absint',
319 319
 			'validate_callback' => 'rest_validate_request_arg',
320 320
 			'minimum'           => 1,
321 321
 		);
322
-		$params['per_page']  = array(
323
-			'description'       => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
322
+		$params['per_page'] = array(
323
+			'description'       => __('Maximum number of items to be returned in result set.', 'woocommerce'),
324 324
 			'type'              => 'integer',
325 325
 			'default'           => 10,
326 326
 			'minimum'           => 1,
@@ -328,27 +328,27 @@  discard block
 block discarded – undo
328 328
 			'sanitize_callback' => 'absint',
329 329
 			'validate_callback' => 'rest_validate_request_arg',
330 330
 		);
331
-		$params['after']     = array(
332
-			'description'       => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
331
+		$params['after'] = array(
332
+			'description'       => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
333 333
 			'type'              => 'string',
334 334
 			'format'            => 'date-time',
335 335
 			'validate_callback' => 'rest_validate_request_arg',
336 336
 		);
337
-		$params['before']    = array(
338
-			'description'       => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
337
+		$params['before'] = array(
338
+			'description'       => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
339 339
 			'type'              => 'string',
340 340
 			'format'            => 'date-time',
341 341
 			'validate_callback' => 'rest_validate_request_arg',
342 342
 		);
343
-		$params['order']     = array(
344
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
343
+		$params['order'] = array(
344
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
345 345
 			'type'              => 'string',
346 346
 			'default'           => 'desc',
347
-			'enum'              => array( 'asc', 'desc' ),
347
+			'enum'              => array('asc', 'desc'),
348 348
 			'validate_callback' => 'rest_validate_request_arg',
349 349
 		);
350
-		$params['orderby']   = array(
351
-			'description'       => __( 'Sort collection by object attribute.', 'woocommerce' ),
350
+		$params['orderby'] = array(
351
+			'description'       => __('Sort collection by object attribute.', 'woocommerce'),
352 352
 			'type'              => 'string',
353 353
 			'default'           => 'date',
354 354
 			'enum'              => array(
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
 			),
365 365
 			'validate_callback' => 'rest_validate_request_arg',
366 366
 		);
367
-		$params['interval']  = array(
368
-			'description'       => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
367
+		$params['interval'] = array(
368
+			'description'       => __('Time interval to use for buckets in the returned data.', 'woocommerce'),
369 369
 			'type'              => 'string',
370 370
 			'default'           => 'week',
371 371
 			'enum'              => array(
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 			'validate_callback' => 'rest_validate_request_arg',
380 380
 		);
381 381
 		$params['segmentby'] = array(
382
-			'description'       => __( 'Segment the response by additional constraint.', 'woocommerce' ),
382
+			'description'       => __('Segment the response by additional constraint.', 'woocommerce'),
383 383
 			'type'              => 'string',
384 384
 			'enum'              => array(
385 385
 				'product',
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports/Coupons.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Reports;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
15 15
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @param array $request Request array.
32 32
 	 * @return array
33 33
 	 */
34
-	protected function prepare_reports_query( $request ) {
34
+	protected function prepare_reports_query($request) {
35 35
 		$args                  = array();
36 36
 		$args['before']        = $request['before'];
37 37
 		$args['after']         = $request['after'];
@@ -50,37 +50,37 @@  discard block
 block discarded – undo
50 50
 	 * @param \WP_REST_Request $request Request data.
51 51
 	 * @return array|\WP_Error
52 52
 	 */
53
-	public function get_items( $request ) {
54
-		$query_args    = $this->prepare_reports_query( $request );
55
-		$coupons_query = new \WC_Admin_Reports_Coupons_Query( $query_args );
53
+	public function get_items($request) {
54
+		$query_args    = $this->prepare_reports_query($request);
55
+		$coupons_query = new \WC_Admin_Reports_Coupons_Query($query_args);
56 56
 		$report_data   = $coupons_query->get_data();
57 57
 
58 58
 		$data = array();
59 59
 
60
-		foreach ( $report_data->data as $coupons_data ) {
61
-			$item   = $this->prepare_item_for_response( $coupons_data, $request );
62
-			$data[] = $this->prepare_response_for_collection( $item );
60
+		foreach ($report_data->data as $coupons_data) {
61
+			$item   = $this->prepare_item_for_response($coupons_data, $request);
62
+			$data[] = $this->prepare_response_for_collection($item);
63 63
 		}
64 64
 
65
-		$response = rest_ensure_response( $data );
66
-		$response->header( 'X-WP-Total', (int) $report_data->total );
67
-		$response->header( 'X-WP-TotalPages', (int) $report_data->pages );
65
+		$response = rest_ensure_response($data);
66
+		$response->header('X-WP-Total', (int) $report_data->total);
67
+		$response->header('X-WP-TotalPages', (int) $report_data->pages);
68 68
 
69 69
 		$page      = $report_data->page_no;
70 70
 		$max_pages = $report_data->pages;
71
-		$base      = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
72
-		if ( $page > 1 ) {
71
+		$base      = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
72
+		if ($page > 1) {
73 73
 			$prev_page = $page - 1;
74
-			if ( $prev_page > $max_pages ) {
74
+			if ($prev_page > $max_pages) {
75 75
 				$prev_page = $max_pages;
76 76
 			}
77
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
78
-			$response->link_header( 'prev', $prev_link );
77
+			$prev_link = add_query_arg('page', $prev_page, $base);
78
+			$response->link_header('prev', $prev_link);
79 79
 		}
80
-		if ( $max_pages > $page ) {
80
+		if ($max_pages > $page) {
81 81
 			$next_page = $page + 1;
82
-			$next_link = add_query_arg( 'page', $next_page, $base );
83
-			$response->link_header( 'next', $next_link );
82
+			$next_link = add_query_arg('page', $next_page, $base);
83
+			$response->link_header('next', $next_link);
84 84
 		}
85 85
 
86 86
 		return $response;
@@ -93,16 +93,16 @@  discard block
 block discarded – undo
93 93
 	 * @param \WP_REST_Request $request Request object.
94 94
 	 * @return \WP_REST_Response
95 95
 	 */
96
-	public function prepare_item_for_response( $report, $request ) {
96
+	public function prepare_item_for_response($report, $request) {
97 97
 		$data = $report;
98 98
 
99
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
100
-		$data    = $this->add_additional_fields_to_object( $data, $request );
101
-		$data    = $this->filter_response_by_context( $data, $context );
99
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
100
+		$data    = $this->add_additional_fields_to_object($data, $request);
101
+		$data    = $this->filter_response_by_context($data, $context);
102 102
 
103 103
 		// Wrap the data in a response object.
104
-		$response = rest_ensure_response( $data );
105
-		$response->add_links( $this->prepare_links( $report ) );
104
+		$response = rest_ensure_response($data);
105
+		$response->add_links($this->prepare_links($report));
106 106
 
107 107
 		/**
108 108
 		 * Filter a report returned from the API.
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * @param object           $report   The original report object.
114 114
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
115 115
 		 */
116
-		return apply_filters( 'woocommerce_rest_prepare_report_coupons', $response, $report, $request );
116
+		return apply_filters('woocommerce_rest_prepare_report_coupons', $response, $report, $request);
117 117
 	}
118 118
 
119 119
 	/**
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
 	 * @param WC_Reports_Query $object Object data.
123 123
 	 * @return array
124 124
 	 */
125
-	protected function prepare_links( $object ) {
125
+	protected function prepare_links($object) {
126 126
 		$links = array(
127 127
 			'coupon' => array(
128
-				'href' => rest_url( sprintf( '/%s/coupons/%d', $this->namespace, $object['coupon_id'] ) ),
128
+				'href' => rest_url(sprintf('/%s/coupons/%d', $this->namespace, $object['coupon_id'])),
129 129
 			),
130 130
 		);
131 131
 
@@ -144,66 +144,66 @@  discard block
 block discarded – undo
144 144
 			'type'       => 'object',
145 145
 			'properties' => array(
146 146
 				'coupon_id'     => array(
147
-					'description' => __( 'Coupon ID.', 'woocommerce' ),
147
+					'description' => __('Coupon ID.', 'woocommerce'),
148 148
 					'type'        => 'integer',
149
-					'context'     => array( 'view', 'edit' ),
149
+					'context'     => array('view', 'edit'),
150 150
 					'readonly'    => true,
151 151
 				),
152 152
 				'amount'        => array(
153
-					'description' => __( 'Net discount amount.', 'woocommerce' ),
153
+					'description' => __('Net discount amount.', 'woocommerce'),
154 154
 					'type'        => 'number',
155
-					'context'     => array( 'view', 'edit' ),
155
+					'context'     => array('view', 'edit'),
156 156
 					'readonly'    => true,
157 157
 				),
158 158
 				'orders_count'  => array(
159
-					'description' => __( 'Amount of orders.', 'woocommerce' ),
159
+					'description' => __('Amount of orders.', 'woocommerce'),
160 160
 					'type'        => 'integer',
161
-					'context'     => array( 'view', 'edit' ),
161
+					'context'     => array('view', 'edit'),
162 162
 					'readonly'    => true,
163 163
 				),
164 164
 				'extended_info' => array(
165 165
 					'code'             => array(
166 166
 						'type'        => 'string',
167 167
 						'readonly'    => true,
168
-						'context'     => array( 'view', 'edit' ),
169
-						'description' => __( 'Coupon code.', 'woocommerce' ),
168
+						'context'     => array('view', 'edit'),
169
+						'description' => __('Coupon code.', 'woocommerce'),
170 170
 					),
171 171
 					'date_created'     => array(
172 172
 						'type'        => 'date-time',
173 173
 						'readonly'    => true,
174
-						'context'     => array( 'view', 'edit' ),
175
-						'description' => __( 'Coupon creation date.', 'woocommerce' ),
174
+						'context'     => array('view', 'edit'),
175
+						'description' => __('Coupon creation date.', 'woocommerce'),
176 176
 					),
177 177
 					'date_created_gmt' => array(
178 178
 						'type'        => 'date-time',
179 179
 						'readonly'    => true,
180
-						'context'     => array( 'view', 'edit' ),
181
-						'description' => __( 'Coupon creation date in GMT.', 'woocommerce' ),
180
+						'context'     => array('view', 'edit'),
181
+						'description' => __('Coupon creation date in GMT.', 'woocommerce'),
182 182
 					),
183 183
 					'date_expires'     => array(
184 184
 						'type'        => 'date-time',
185 185
 						'readonly'    => true,
186
-						'context'     => array( 'view', 'edit' ),
187
-						'description' => __( 'Coupon expiration date.', 'woocommerce' ),
186
+						'context'     => array('view', 'edit'),
187
+						'description' => __('Coupon expiration date.', 'woocommerce'),
188 188
 					),
189 189
 					'date_expires_gmt' => array(
190 190
 						'type'        => 'date-time',
191 191
 						'readonly'    => true,
192
-						'context'     => array( 'view', 'edit' ),
193
-						'description' => __( 'Coupon expiration date in GMT.', 'woocommerce' ),
192
+						'context'     => array('view', 'edit'),
193
+						'description' => __('Coupon expiration date in GMT.', 'woocommerce'),
194 194
 					),
195 195
 					'discount_type'    => array(
196 196
 						'type'        => 'string',
197 197
 						'readonly'    => true,
198
-						'context'     => array( 'view', 'edit' ),
199
-						'enum'        => array_keys( wc_get_coupon_types() ),
200
-						'description' => __( 'Coupon discount type.', 'woocommerce' ),
198
+						'context'     => array('view', 'edit'),
199
+						'enum'        => array_keys(wc_get_coupon_types()),
200
+						'description' => __('Coupon discount type.', 'woocommerce'),
201 201
 					),
202 202
 				),
203 203
 			),
204 204
 		);
205 205
 
206
-		return $this->add_additional_fields_schema( $schema );
206
+		return $this->add_additional_fields_schema($schema);
207 207
 	}
208 208
 
209 209
 	/**
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
 	 */
214 214
 	public function get_collection_params() {
215 215
 		$params                  = array();
216
-		$params['context']       = $this->get_context_param( array( 'default' => 'view' ) );
216
+		$params['context']       = $this->get_context_param(array('default' => 'view'));
217 217
 		$params['page']          = array(
218
-			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
218
+			'description'       => __('Current page of the collection.', 'woocommerce'),
219 219
 			'type'              => 'integer',
220 220
 			'default'           => 1,
221 221
 			'sanitize_callback' => 'absint',
222 222
 			'validate_callback' => 'rest_validate_request_arg',
223 223
 			'minimum'           => 1,
224 224
 		);
225
-		$params['per_page']      = array(
226
-			'description'       => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
225
+		$params['per_page'] = array(
226
+			'description'       => __('Maximum number of items to be returned in result set.', 'woocommerce'),
227 227
 			'type'              => 'integer',
228 228
 			'default'           => 10,
229 229
 			'minimum'           => 1,
@@ -231,27 +231,27 @@  discard block
 block discarded – undo
231 231
 			'sanitize_callback' => 'absint',
232 232
 			'validate_callback' => 'rest_validate_request_arg',
233 233
 		);
234
-		$params['after']         = array(
235
-			'description'       => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
234
+		$params['after'] = array(
235
+			'description'       => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
236 236
 			'type'              => 'string',
237 237
 			'format'            => 'date-time',
238 238
 			'validate_callback' => 'rest_validate_request_arg',
239 239
 		);
240
-		$params['before']        = array(
241
-			'description'       => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
240
+		$params['before'] = array(
241
+			'description'       => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
242 242
 			'type'              => 'string',
243 243
 			'format'            => 'date-time',
244 244
 			'validate_callback' => 'rest_validate_request_arg',
245 245
 		);
246
-		$params['order']         = array(
247
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
246
+		$params['order'] = array(
247
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
248 248
 			'type'              => 'string',
249 249
 			'default'           => 'desc',
250
-			'enum'              => array( 'asc', 'desc' ),
250
+			'enum'              => array('asc', 'desc'),
251 251
 			'validate_callback' => 'rest_validate_request_arg',
252 252
 		);
253
-		$params['orderby']       = array(
254
-			'description'       => __( 'Sort collection by object attribute.', 'woocommerce' ),
253
+		$params['orderby'] = array(
254
+			'description'       => __('Sort collection by object attribute.', 'woocommerce'),
255 255
 			'type'              => 'string',
256 256
 			'default'           => 'coupon_id',
257 257
 			'enum'              => array(
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
 			),
263 263
 			'validate_callback' => 'rest_validate_request_arg',
264 264
 		);
265
-		$params['coupons']       = array(
266
-			'description'       => __( 'Limit result set to coupons assigned specific coupon IDs.', 'woocommerce' ),
265
+		$params['coupons'] = array(
266
+			'description'       => __('Limit result set to coupons assigned specific coupon IDs.', 'woocommerce'),
267 267
 			'type'              => 'array',
268 268
 			'sanitize_callback' => 'wp_parse_id_list',
269 269
 			'validate_callback' => 'rest_validate_request_arg',
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 			),
273 273
 		);
274 274
 		$params['extended_info'] = array(
275
-			'description'       => __( 'Add additional piece of info about each coupon to the report.', 'woocommerce' ),
275
+			'description'       => __('Add additional piece of info about each coupon to the report.', 'woocommerce'),
276 276
 			'type'              => 'boolean',
277 277
 			'default'           => false,
278 278
 			'sanitize_callback' => 'wc_string_to_bool',
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports/Orders.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers\Reports;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
15 15
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @param array $request Request array.
32 32
 	 * @return array
33 33
 	 */
34
-	protected function prepare_reports_query( $request ) {
34
+	protected function prepare_reports_query($request) {
35 35
 		$args                     = array();
36 36
 		$args['before']           = $request['before'];
37 37
 		$args['after']            = $request['after'];
@@ -57,38 +57,38 @@  discard block
 block discarded – undo
57 57
 	 * @param \WP_REST_Request $request Request data.
58 58
 	 * @return array|\WP_Error
59 59
 	 */
60
-	public function get_items( $request ) {
61
-		$query_args   = $this->prepare_reports_query( $request );
62
-		$orders_query = new \WC_Admin_Reports_Orders_Query( $query_args );
60
+	public function get_items($request) {
61
+		$query_args   = $this->prepare_reports_query($request);
62
+		$orders_query = new \WC_Admin_Reports_Orders_Query($query_args);
63 63
 		$report_data  = $orders_query->get_data();
64 64
 
65 65
 		$data = array();
66 66
 
67
-		foreach ( $report_data->data as $orders_data ) {
68
-			$orders_data['order_number'] = $this->get_order_number( $orders_data['order_id'] );
69
-			$item                        = $this->prepare_item_for_response( $orders_data, $request );
70
-			$data[]                      = $this->prepare_response_for_collection( $item );
67
+		foreach ($report_data->data as $orders_data) {
68
+			$orders_data['order_number'] = $this->get_order_number($orders_data['order_id']);
69
+			$item                        = $this->prepare_item_for_response($orders_data, $request);
70
+			$data[]                      = $this->prepare_response_for_collection($item);
71 71
 		}
72 72
 
73
-		$response = rest_ensure_response( $data );
74
-		$response->header( 'X-WP-Total', (int) $report_data->total );
75
-		$response->header( 'X-WP-TotalPages', (int) $report_data->pages );
73
+		$response = rest_ensure_response($data);
74
+		$response->header('X-WP-Total', (int) $report_data->total);
75
+		$response->header('X-WP-TotalPages', (int) $report_data->pages);
76 76
 
77 77
 		$page      = $report_data->page_no;
78 78
 		$max_pages = $report_data->pages;
79
-		$base      = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
80
-		if ( $page > 1 ) {
79
+		$base      = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
80
+		if ($page > 1) {
81 81
 			$prev_page = $page - 1;
82
-			if ( $prev_page > $max_pages ) {
82
+			if ($prev_page > $max_pages) {
83 83
 				$prev_page = $max_pages;
84 84
 			}
85
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
86
-			$response->link_header( 'prev', $prev_link );
85
+			$prev_link = add_query_arg('page', $prev_page, $base);
86
+			$response->link_header('prev', $prev_link);
87 87
 		}
88
-		if ( $max_pages > $page ) {
88
+		if ($max_pages > $page) {
89 89
 			$next_page = $page + 1;
90
-			$next_link = add_query_arg( 'page', $next_page, $base );
91
-			$response->link_header( 'next', $next_link );
90
+			$next_link = add_query_arg('page', $next_page, $base);
91
+			$response->link_header('next', $next_link);
92 92
 		}
93 93
 
94 94
 		return $response;
@@ -101,16 +101,16 @@  discard block
 block discarded – undo
101 101
 	 * @param \WP_REST_Request $request Request object.
102 102
 	 * @return \WP_REST_Response
103 103
 	 */
104
-	public function prepare_item_for_response( $report, $request ) {
104
+	public function prepare_item_for_response($report, $request) {
105 105
 		$data = $report;
106 106
 
107
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
108
-		$data    = $this->add_additional_fields_to_object( $data, $request );
109
-		$data    = $this->filter_response_by_context( $data, $context );
107
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
108
+		$data    = $this->add_additional_fields_to_object($data, $request);
109
+		$data    = $this->filter_response_by_context($data, $context);
110 110
 
111 111
 		// Wrap the data in a response object.
112
-		$response = rest_ensure_response( $data );
113
-		$response->add_links( $this->prepare_links( $report ) );
112
+		$response = rest_ensure_response($data);
113
+		$response->add_links($this->prepare_links($report));
114 114
 
115 115
 		/**
116 116
 		 * Filter a report returned from the API.
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		 * @param object           $report   The original report object.
122 122
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
123 123
 		 */
124
-		return apply_filters( 'woocommerce_rest_prepare_report_orders', $response, $report, $request );
124
+		return apply_filters('woocommerce_rest_prepare_report_orders', $response, $report, $request);
125 125
 	}
126 126
 
127 127
 	/**
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
 	 * @param WC_Reports_Query $object Object data.
131 131
 	 * @return array
132 132
 	 */
133
-	protected function prepare_links( $object ) {
133
+	protected function prepare_links($object) {
134 134
 		$links = array(
135 135
 			'order' => array(
136
-				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object['order_id'] ) ),
136
+				'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $object['order_id'])),
137 137
 			),
138 138
 		);
139 139
 
@@ -152,71 +152,71 @@  discard block
 block discarded – undo
152 152
 			'type'       => 'object',
153 153
 			'properties' => array(
154 154
 				'order_id'       => array(
155
-					'description' => __( 'Order ID.', 'woocommerce' ),
155
+					'description' => __('Order ID.', 'woocommerce'),
156 156
 					'type'        => 'integer',
157
-					'context'     => array( 'view', 'edit' ),
157
+					'context'     => array('view', 'edit'),
158 158
 					'readonly'    => true,
159 159
 				),
160 160
 				'order_number'   => array(
161
-					'description' => __( 'Order Number.', 'woocommerce' ),
161
+					'description' => __('Order Number.', 'woocommerce'),
162 162
 					'type'        => 'string',
163
-					'context'     => array( 'view', 'edit' ),
163
+					'context'     => array('view', 'edit'),
164 164
 					'readonly'    => true,
165 165
 				),
166 166
 				'date_created'   => array(
167
-					'description' => __( 'Date the order was created.', 'woocommerce' ),
167
+					'description' => __('Date the order was created.', 'woocommerce'),
168 168
 					'type'        => 'string',
169
-					'context'     => array( 'view', 'edit' ),
169
+					'context'     => array('view', 'edit'),
170 170
 					'readonly'    => true,
171 171
 				),
172 172
 				'status'         => array(
173
-					'description' => __( 'Order status.', 'woocommerce' ),
173
+					'description' => __('Order status.', 'woocommerce'),
174 174
 					'type'        => 'string',
175
-					'context'     => array( 'view', 'edit' ),
175
+					'context'     => array('view', 'edit'),
176 176
 					'readonly'    => true,
177 177
 				),
178 178
 				'customer_id'    => array(
179
-					'description' => __( 'Customer ID.', 'woocommerce' ),
179
+					'description' => __('Customer ID.', 'woocommerce'),
180 180
 					'type'        => 'integer',
181
-					'context'     => array( 'view', 'edit' ),
181
+					'context'     => array('view', 'edit'),
182 182
 					'readonly'    => true,
183 183
 				),
184 184
 				'num_items_sold' => array(
185
-					'description' => __( 'Number of items sold.', 'woocommerce' ),
185
+					'description' => __('Number of items sold.', 'woocommerce'),
186 186
 					'type'        => 'integer',
187
-					'context'     => array( 'view', 'edit' ),
187
+					'context'     => array('view', 'edit'),
188 188
 					'readonly'    => true,
189 189
 				),
190 190
 				'net_total'      => array(
191
-					'description' => __( 'Net total revenue.', 'woocommerce' ),
191
+					'description' => __('Net total revenue.', 'woocommerce'),
192 192
 					'type'        => 'float',
193
-					'context'     => array( 'view', 'edit' ),
193
+					'context'     => array('view', 'edit'),
194 194
 					'readonly'    => true,
195 195
 				),
196 196
 				'customer_type'  => array(
197
-					'description' => __( 'Returning or new customer.', 'woocommerce' ),
197
+					'description' => __('Returning or new customer.', 'woocommerce'),
198 198
 					'type'        => 'string',
199
-					'context'     => array( 'view', 'edit' ),
199
+					'context'     => array('view', 'edit'),
200 200
 					'readonly'    => true,
201 201
 				),
202 202
 				'extended_info'  => array(
203 203
 					'products'   => array(
204 204
 						'type'        => 'array',
205 205
 						'readonly'    => true,
206
-						'context'     => array( 'view', 'edit' ),
207
-						'description' => __( 'List of product IDs and names.', 'woocommerce' ),
206
+						'context'     => array('view', 'edit'),
207
+						'description' => __('List of product IDs and names.', 'woocommerce'),
208 208
 					),
209 209
 					'categories' => array(
210 210
 						'type'        => 'array',
211 211
 						'readonly'    => true,
212
-						'context'     => array( 'view', 'edit' ),
213
-						'description' => __( 'Category IDs.', 'woocommerce' ),
212
+						'context'     => array('view', 'edit'),
213
+						'description' => __('Category IDs.', 'woocommerce'),
214 214
 					),
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
 
222 222
 	/**
@@ -226,17 +226,17 @@  discard block
 block discarded – undo
226 226
 	 */
227 227
 	public function get_collection_params() {
228 228
 		$params                     = array();
229
-		$params['context']          = $this->get_context_param( array( 'default' => 'view' ) );
229
+		$params['context']          = $this->get_context_param(array('default' => 'view'));
230 230
 		$params['page']             = array(
231
-			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
231
+			'description'       => __('Current page of the collection.', 'woocommerce'),
232 232
 			'type'              => 'integer',
233 233
 			'default'           => 1,
234 234
 			'sanitize_callback' => 'absint',
235 235
 			'validate_callback' => 'rest_validate_request_arg',
236 236
 			'minimum'           => 1,
237 237
 		);
238
-		$params['per_page']         = array(
239
-			'description'       => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
238
+		$params['per_page'] = array(
239
+			'description'       => __('Maximum number of items to be returned in result set.', 'woocommerce'),
240 240
 			'type'              => 'integer',
241 241
 			'default'           => 10,
242 242
 			'minimum'           => 0,
@@ -244,27 +244,27 @@  discard block
 block discarded – undo
244 244
 			'sanitize_callback' => 'absint',
245 245
 			'validate_callback' => 'rest_validate_request_arg',
246 246
 		);
247
-		$params['after']            = array(
248
-			'description'       => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
247
+		$params['after'] = array(
248
+			'description'       => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
249 249
 			'type'              => 'string',
250 250
 			'format'            => 'date-time',
251 251
 			'validate_callback' => 'rest_validate_request_arg',
252 252
 		);
253
-		$params['before']           = array(
254
-			'description'       => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
253
+		$params['before'] = array(
254
+			'description'       => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
255 255
 			'type'              => 'string',
256 256
 			'format'            => 'date-time',
257 257
 			'validate_callback' => 'rest_validate_request_arg',
258 258
 		);
259
-		$params['order']            = array(
260
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
259
+		$params['order'] = array(
260
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
261 261
 			'type'              => 'string',
262 262
 			'default'           => 'desc',
263
-			'enum'              => array( 'asc', 'desc' ),
263
+			'enum'              => array('asc', 'desc'),
264 264
 			'validate_callback' => 'rest_validate_request_arg',
265 265
 		);
266
-		$params['orderby']          = array(
267
-			'description'       => __( 'Sort collection by object attribute.', 'woocommerce' ),
266
+		$params['orderby'] = array(
267
+			'description'       => __('Sort collection by object attribute.', 'woocommerce'),
268 268
 			'type'              => 'string',
269 269
 			'default'           => 'date',
270 270
 			'enum'              => array(
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 			'validate_callback' => 'rest_validate_request_arg',
276 276
 		);
277 277
 		$params['product_includes'] = array(
278
-			'description'       => __( 'Limit result set to items that have the specified product(s) assigned.', 'woocommerce' ),
278
+			'description'       => __('Limit result set to items that have the specified product(s) assigned.', 'woocommerce'),
279 279
 			'type'              => 'array',
280 280
 			'items'             => array(
281 281
 				'type' => 'integer',
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 			'validate_callback' => 'rest_validate_request_arg',
286 286
 		);
287 287
 		$params['product_excludes'] = array(
288
-			'description'       => __( 'Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce' ),
288
+			'description'       => __('Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce'),
289 289
 			'type'              => 'array',
290 290
 			'items'             => array(
291 291
 				'type' => 'integer',
@@ -294,8 +294,8 @@  discard block
 block discarded – undo
294 294
 			'validate_callback' => 'rest_validate_request_arg',
295 295
 			'sanitize_callback' => 'wp_parse_id_list',
296 296
 		);
297
-		$params['coupon_includes']  = array(
298
-			'description'       => __( 'Limit result set to items that have the specified coupon(s) assigned.', 'woocommerce' ),
297
+		$params['coupon_includes'] = array(
298
+			'description'       => __('Limit result set to items that have the specified coupon(s) assigned.', 'woocommerce'),
299 299
 			'type'              => 'array',
300 300
 			'items'             => array(
301 301
 				'type' => 'integer',
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 			'sanitize_callback' => 'wp_parse_id_list',
305 305
 			'validate_callback' => 'rest_validate_request_arg',
306 306
 		);
307
-		$params['coupon_excludes']  = array(
308
-			'description'       => __( 'Limit result set to items that don\'t have the specified coupon(s) assigned.', 'woocommerce' ),
307
+		$params['coupon_excludes'] = array(
308
+			'description'       => __('Limit result set to items that don\'t have the specified coupon(s) assigned.', 'woocommerce'),
309 309
 			'type'              => 'array',
310 310
 			'items'             => array(
311 311
 				'type' => 'integer',
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
 			'validate_callback' => 'rest_validate_request_arg',
315 315
 			'sanitize_callback' => 'wp_parse_id_list',
316 316
 		);
317
-		$params['status_is']        = array(
318
-			'description'       => __( 'Limit result set to items that have the specified order status.', 'woocommerce' ),
317
+		$params['status_is'] = array(
318
+			'description'       => __('Limit result set to items that have the specified order status.', 'woocommerce'),
319 319
 			'type'              => 'array',
320 320
 			'sanitize_callback' => 'wp_parse_slug_list',
321 321
 			'validate_callback' => 'rest_validate_request_arg',
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
 				'type' => 'string',
325 325
 			),
326 326
 		);
327
-		$params['status_is_not']    = array(
328
-			'description'       => __( 'Limit result set to items that don\'t have the specified order status.', 'woocommerce' ),
327
+		$params['status_is_not'] = array(
328
+			'description'       => __('Limit result set to items that don\'t have the specified order status.', 'woocommerce'),
329 329
 			'type'              => 'array',
330 330
 			'sanitize_callback' => 'wp_parse_slug_list',
331 331
 			'validate_callback' => 'rest_validate_request_arg',
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
 				'type' => 'string',
335 335
 			),
336 336
 		);
337
-		$params['customer_type']    = array(
338
-			'description'       => __( 'Limit result set to returning or new customers.', 'woocommerce' ),
337
+		$params['customer_type'] = array(
338
+			'description'       => __('Limit result set to returning or new customers.', 'woocommerce'),
339 339
 			'type'              => 'string',
340 340
 			'default'           => '',
341 341
 			'enum'              => array(
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 			),
346 346
 			'validate_callback' => 'rest_validate_request_arg',
347 347
 		);
348
-		$params['refunds']          = array(
349
-			'description'       => __( 'Limit result set to specific types of refunds.', 'woocommerce' ),
348
+		$params['refunds'] = array(
349
+			'description'       => __('Limit result set to specific types of refunds.', 'woocommerce'),
350 350
 			'type'              => 'string',
351 351
 			'default'           => '',
352 352
 			'enum'              => array(
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 			),
359 359
 			'validate_callback' => 'rest_validate_request_arg',
360 360
 		);
361
-		$params['extended_info']    = array(
362
-			'description'       => __( 'Add additional piece of info about each coupon to the report.', 'woocommerce' ),
361
+		$params['extended_info'] = array(
362
+			'description'       => __('Add additional piece of info about each coupon to the report.', 'woocommerce'),
363 363
 			'type'              => 'boolean',
364 364
 			'default'           => false,
365 365
 			'sanitize_callback' => 'wc_string_to_bool',
Please login to merge, or discard this patch.