Completed
Push — master ( 561e44...129ea3 )
by Mike
453:41 queued 408:32
created
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.
src/RestApi/Version4/Controllers/Reports/CustomerStats.php 1 patch
Spacing   +93 added lines, -93 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['registered_before']   = $request['registered_before'];
37 37
 		$args['registered_after']    = $request['registered_after'];
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
 		$args['last_order_after']    = $request['last_order_after'];
58 58
 		$args['customers']           = $request['customers'];
59 59
 
60
-		$between_params_numeric    = array( 'orders_count', 'total_spend', 'avg_order_value' );
61
-		$normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false );
62
-		$between_params_date       = array( 'last_active', 'registered' );
63
-		$normalized_params_date    = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true );
64
-		$args                      = array_merge( $args, $normalized_params_numeric, $normalized_params_date );
60
+		$between_params_numeric    = array('orders_count', 'total_spend', 'avg_order_value');
61
+		$normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params($request, $between_params_numeric, false);
62
+		$between_params_date       = array('last_active', 'registered');
63
+		$normalized_params_date    = \WC_Admin_Reports_Interval::normalize_between_params($request, $between_params_date, true);
64
+		$args                      = array_merge($args, $normalized_params_numeric, $normalized_params_date);
65 65
 
66 66
 		return $args;
67 67
 	}
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
 	 * @param \WP_REST_Request $request Request data.
73 73
 	 * @return array|\WP_Error
74 74
 	 */
75
-	public function get_items( $request ) {
76
-		$query_args      = $this->prepare_reports_query( $request );
77
-		$customers_query = new \WC_Admin_Reports_Customers_Stats_Query( $query_args );
75
+	public function get_items($request) {
76
+		$query_args      = $this->prepare_reports_query($request);
77
+		$customers_query = new \WC_Admin_Reports_Customers_Stats_Query($query_args);
78 78
 		$report_data     = $customers_query->get_data();
79 79
 		$out_data        = array(
80 80
 			'totals' => $report_data,
81 81
 		);
82 82
 
83
-		return rest_ensure_response( $out_data );
83
+		return rest_ensure_response($out_data);
84 84
 	}
85 85
 
86 86
 	/**
@@ -90,15 +90,15 @@  discard block
 block discarded – undo
90 90
 	 * @param \WP_REST_Request $request Request object.
91 91
 	 * @return \WP_REST_Response
92 92
 	 */
93
-	public function prepare_item_for_response( $report, $request ) {
93
+	public function prepare_item_for_response($report, $request) {
94 94
 		$data = $report;
95 95
 
96
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
97
-		$data    = $this->add_additional_fields_to_object( $data, $request );
98
-		$data    = $this->filter_response_by_context( $data, $context );
96
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
97
+		$data    = $this->add_additional_fields_to_object($data, $request);
98
+		$data    = $this->filter_response_by_context($data, $context);
99 99
 
100 100
 		// Wrap the data in a response object.
101
-		$response = rest_ensure_response( $data );
101
+		$response = rest_ensure_response($data);
102 102
 
103 103
 		/**
104 104
 		 * Filter a report returned from the API.
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		 * @param object           $report   The original report object.
110 110
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
111 111
 		 */
112
-		return apply_filters( 'woocommerce_rest_prepare_report_customers_stats', $response, $report, $request );
112
+		return apply_filters('woocommerce_rest_prepare_report_customers_stats', $response, $report, $request);
113 113
 	}
114 114
 
115 115
 	/**
@@ -121,28 +121,28 @@  discard block
 block discarded – undo
121 121
 		// @todo Should any of these be 'indicator's?
122 122
 		$totals = array(
123 123
 			'customers_count'     => array(
124
-				'description' => __( 'Number of customers.', 'woocommerce' ),
124
+				'description' => __('Number of customers.', 'woocommerce'),
125 125
 				'type'        => 'integer',
126
-				'context'     => array( 'view', 'edit' ),
126
+				'context'     => array('view', 'edit'),
127 127
 				'readonly'    => true,
128 128
 			),
129 129
 			'avg_orders_count'    => array(
130
-				'description' => __( 'Average number of orders.', 'woocommerce' ),
130
+				'description' => __('Average number of orders.', 'woocommerce'),
131 131
 				'type'        => 'integer',
132
-				'context'     => array( 'view', 'edit' ),
132
+				'context'     => array('view', 'edit'),
133 133
 				'readonly'    => true,
134 134
 			),
135 135
 			'avg_total_spend'     => array(
136
-				'description' => __( 'Average total spend per customer.', 'woocommerce' ),
136
+				'description' => __('Average total spend per customer.', 'woocommerce'),
137 137
 				'type'        => 'number',
138
-				'context'     => array( 'view', 'edit' ),
138
+				'context'     => array('view', 'edit'),
139 139
 				'readonly'    => true,
140 140
 				'format'      => 'currency',
141 141
 			),
142 142
 			'avg_avg_order_value' => array(
143
-				'description' => __( 'Average AOV per customer.', 'woocommerce' ),
143
+				'description' => __('Average AOV per customer.', 'woocommerce'),
144 144
 				'type'        => 'number',
145
-				'context'     => array( 'view', 'edit' ),
145
+				'context'     => array('view', 'edit'),
146 146
 				'readonly'    => true,
147 147
 				'format'      => 'currency',
148 148
 			),
@@ -154,16 +154,16 @@  discard block
 block discarded – undo
154 154
 			'type'       => 'object',
155 155
 			'properties' => array(
156 156
 				'totals' => array(
157
-					'description' => __( 'Totals data.', 'woocommerce' ),
157
+					'description' => __('Totals data.', 'woocommerce'),
158 158
 					'type'        => 'object',
159
-					'context'     => array( 'view', 'edit' ),
159
+					'context'     => array('view', 'edit'),
160 160
 					'readonly'    => true,
161 161
 					'properties'  => $totals,
162 162
 				),
163 163
 			),
164 164
 		);
165 165
 
166
-		return $this->add_additional_fields_schema( $schema );
166
+		return $this->add_additional_fields_schema($schema);
167 167
 	}
168 168
 
169 169
 	/**
@@ -173,21 +173,21 @@  discard block
 block discarded – undo
173 173
 	 */
174 174
 	public function get_collection_params() {
175 175
 		$params                            = array();
176
-		$params['context']                 = $this->get_context_param( array( 'default' => 'view' ) );
176
+		$params['context']                 = $this->get_context_param(array('default' => 'view'));
177 177
 		$params['registered_before']       = array(
178
-			'description'       => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
178
+			'description'       => __('Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
179 179
 			'type'              => 'string',
180 180
 			'format'            => 'date-time',
181 181
 			'validate_callback' => 'rest_validate_request_arg',
182 182
 		);
183
-		$params['registered_after']        = array(
184
-			'description'       => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
183
+		$params['registered_after'] = array(
184
+			'description'       => __('Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
185 185
 			'type'              => 'string',
186 186
 			'format'            => 'date-time',
187 187
 			'validate_callback' => 'rest_validate_request_arg',
188 188
 		);
189
-		$params['match']                   = array(
190
-			'description'       => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ),
189
+		$params['match'] = array(
190
+			'description'       => __('Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce'),
191 191
 			'type'              => 'string',
192 192
 			'default'           => 'all',
193 193
 			'enum'              => array(
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
 			),
197 197
 			'validate_callback' => 'rest_validate_request_arg',
198 198
 		);
199
-		$params['search']                  = array(
200
-			'description'       => __( 'Limit response to objects with a customer field containing the search term. Searches the field provided by `searchby`.', 'woocommerce' ),
199
+		$params['search'] = array(
200
+			'description'       => __('Limit response to objects with a customer field containing the search term. Searches the field provided by `searchby`.', 'woocommerce'),
201 201
 			'type'              => 'string',
202 202
 			'validate_callback' => 'rest_validate_request_arg',
203 203
 		);
204
-		$params['searchby']                = array(
204
+		$params['searchby'] = array(
205 205
 			'description' => 'Limit results with `search` and `searchby` to specific fields containing the search term.',
206 206
 			'type'        => 'string',
207 207
 			'default'     => 'name',
@@ -211,141 +211,141 @@  discard block
 block discarded – undo
211 211
 				'email',
212 212
 			),
213 213
 		);
214
-		$params['name_includes']           = array(
215
-			'description'       => __( 'Limit response to objects with specfic names.', 'woocommerce' ),
214
+		$params['name_includes'] = array(
215
+			'description'       => __('Limit response to objects with specfic names.', 'woocommerce'),
216 216
 			'type'              => 'string',
217 217
 			'validate_callback' => 'rest_validate_request_arg',
218 218
 		);
219
-		$params['name_excludes']           = array(
220
-			'description'       => __( 'Limit response to objects excluding specfic names.', 'woocommerce' ),
219
+		$params['name_excludes'] = array(
220
+			'description'       => __('Limit response to objects excluding specfic names.', 'woocommerce'),
221 221
 			'type'              => 'string',
222 222
 			'validate_callback' => 'rest_validate_request_arg',
223 223
 		);
224
-		$params['username_includes']       = array(
225
-			'description'       => __( 'Limit response to objects with specfic usernames.', 'woocommerce' ),
224
+		$params['username_includes'] = array(
225
+			'description'       => __('Limit response to objects with specfic usernames.', 'woocommerce'),
226 226
 			'type'              => 'string',
227 227
 			'validate_callback' => 'rest_validate_request_arg',
228 228
 		);
229
-		$params['username_excludes']       = array(
230
-			'description'       => __( 'Limit response to objects excluding specfic usernames.', 'woocommerce' ),
229
+		$params['username_excludes'] = array(
230
+			'description'       => __('Limit response to objects excluding specfic usernames.', 'woocommerce'),
231 231
 			'type'              => 'string',
232 232
 			'validate_callback' => 'rest_validate_request_arg',
233 233
 		);
234
-		$params['email_includes']          = array(
235
-			'description'       => __( 'Limit response to objects including emails.', 'woocommerce' ),
234
+		$params['email_includes'] = array(
235
+			'description'       => __('Limit response to objects including emails.', 'woocommerce'),
236 236
 			'type'              => 'string',
237 237
 			'validate_callback' => 'rest_validate_request_arg',
238 238
 		);
239
-		$params['email_excludes']          = array(
240
-			'description'       => __( 'Limit response to objects excluding emails.', 'woocommerce' ),
239
+		$params['email_excludes'] = array(
240
+			'description'       => __('Limit response to objects excluding emails.', 'woocommerce'),
241 241
 			'type'              => 'string',
242 242
 			'validate_callback' => 'rest_validate_request_arg',
243 243
 		);
244
-		$params['country_includes']        = array(
245
-			'description'       => __( 'Limit response to objects with specfic countries.', 'woocommerce' ),
244
+		$params['country_includes'] = array(
245
+			'description'       => __('Limit response to objects with specfic countries.', 'woocommerce'),
246 246
 			'type'              => 'string',
247 247
 			'validate_callback' => 'rest_validate_request_arg',
248 248
 		);
249
-		$params['country_excludes']        = array(
250
-			'description'       => __( 'Limit response to objects excluding specfic countries.', 'woocommerce' ),
249
+		$params['country_excludes'] = array(
250
+			'description'       => __('Limit response to objects excluding specfic countries.', 'woocommerce'),
251 251
 			'type'              => 'string',
252 252
 			'validate_callback' => 'rest_validate_request_arg',
253 253
 		);
254
-		$params['last_active_before']      = array(
255
-			'description'       => __( 'Limit response to objects last active before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
254
+		$params['last_active_before'] = array(
255
+			'description'       => __('Limit response to objects last active before (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
256 256
 			'type'              => 'string',
257 257
 			'format'            => 'date-time',
258 258
 			'validate_callback' => 'rest_validate_request_arg',
259 259
 		);
260
-		$params['last_active_after']       = array(
261
-			'description'       => __( 'Limit response to objects last active after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
260
+		$params['last_active_after'] = array(
261
+			'description'       => __('Limit response to objects last active after (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
262 262
 			'type'              => 'string',
263 263
 			'format'            => 'date-time',
264 264
 			'validate_callback' => 'rest_validate_request_arg',
265 265
 		);
266
-		$params['last_active_between']     = array(
267
-			'description'       => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ),
266
+		$params['last_active_between'] = array(
267
+			'description'       => __('Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce'),
268 268
 			'type'              => 'array',
269
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ),
269
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_date_arg'),
270 270
 		);
271
-		$params['registered_before']       = array(
272
-			'description'       => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
271
+		$params['registered_before'] = array(
272
+			'description'       => __('Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
273 273
 			'type'              => 'string',
274 274
 			'format'            => 'date-time',
275 275
 			'validate_callback' => 'rest_validate_request_arg',
276 276
 		);
277
-		$params['registered_after']        = array(
278
-			'description'       => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
277
+		$params['registered_after'] = array(
278
+			'description'       => __('Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
279 279
 			'type'              => 'string',
280 280
 			'format'            => 'date-time',
281 281
 			'validate_callback' => 'rest_validate_request_arg',
282 282
 		);
283
-		$params['registered_between']      = array(
284
-			'description'       => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ),
283
+		$params['registered_between'] = array(
284
+			'description'       => __('Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce'),
285 285
 			'type'              => 'array',
286
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ),
286
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_date_arg'),
287 287
 		);
288
-		$params['orders_count_min']        = array(
289
-			'description'       => __( 'Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce' ),
288
+		$params['orders_count_min'] = array(
289
+			'description'       => __('Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce'),
290 290
 			'type'              => 'integer',
291 291
 			'sanitize_callback' => 'absint',
292 292
 			'validate_callback' => 'rest_validate_request_arg',
293 293
 		);
294
-		$params['orders_count_max']        = array(
295
-			'description'       => __( 'Limit response to objects with an order count less than or equal to given integer.', 'woocommerce' ),
294
+		$params['orders_count_max'] = array(
295
+			'description'       => __('Limit response to objects with an order count less than or equal to given integer.', 'woocommerce'),
296 296
 			'type'              => 'integer',
297 297
 			'sanitize_callback' => 'absint',
298 298
 			'validate_callback' => 'rest_validate_request_arg',
299 299
 		);
300
-		$params['orders_count_between']    = array(
301
-			'description'       => __( 'Limit response to objects with an order count between two given integers.', 'woocommerce' ),
300
+		$params['orders_count_between'] = array(
301
+			'description'       => __('Limit response to objects with an order count between two given integers.', 'woocommerce'),
302 302
 			'type'              => 'array',
303
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ),
303
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'),
304 304
 		);
305
-		$params['total_spend_min']         = array(
306
-			'description'       => __( 'Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce' ),
305
+		$params['total_spend_min'] = array(
306
+			'description'       => __('Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce'),
307 307
 			'type'              => 'number',
308 308
 			'validate_callback' => 'rest_validate_request_arg',
309 309
 		);
310
-		$params['total_spend_max']         = array(
311
-			'description'       => __( 'Limit response to objects with a total order spend less than or equal to given number.', 'woocommerce' ),
310
+		$params['total_spend_max'] = array(
311
+			'description'       => __('Limit response to objects with a total order spend less than or equal to given number.', 'woocommerce'),
312 312
 			'type'              => 'number',
313 313
 			'validate_callback' => 'rest_validate_request_arg',
314 314
 		);
315
-		$params['total_spend_between']     = array(
316
-			'description'       => __( 'Limit response to objects with a total order spend between two given numbers.', 'woocommerce' ),
315
+		$params['total_spend_between'] = array(
316
+			'description'       => __('Limit response to objects with a total order spend between two given numbers.', 'woocommerce'),
317 317
 			'type'              => 'array',
318
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ),
318
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'),
319 319
 		);
320
-		$params['avg_order_value_min']     = array(
321
-			'description'       => __( 'Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce' ),
320
+		$params['avg_order_value_min'] = array(
321
+			'description'       => __('Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce'),
322 322
 			'type'              => 'number',
323 323
 			'validate_callback' => 'rest_validate_request_arg',
324 324
 		);
325
-		$params['avg_order_value_max']     = array(
326
-			'description'       => __( 'Limit response to objects with an average order spend less than or equal to given number.', 'woocommerce' ),
325
+		$params['avg_order_value_max'] = array(
326
+			'description'       => __('Limit response to objects with an average order spend less than or equal to given number.', 'woocommerce'),
327 327
 			'type'              => 'number',
328 328
 			'validate_callback' => 'rest_validate_request_arg',
329 329
 		);
330 330
 		$params['avg_order_value_between'] = array(
331
-			'description'       => __( 'Limit response to objects with an average order spend between two given numbers.', 'woocommerce' ),
331
+			'description'       => __('Limit response to objects with an average order spend between two given numbers.', 'woocommerce'),
332 332
 			'type'              => 'array',
333
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ),
333
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'),
334 334
 		);
335
-		$params['last_order_before']       = array(
336
-			'description'       => __( 'Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
335
+		$params['last_order_before'] = array(
336
+			'description'       => __('Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
337 337
 			'type'              => 'string',
338 338
 			'format'            => 'date-time',
339 339
 			'validate_callback' => 'rest_validate_request_arg',
340 340
 		);
341
-		$params['last_order_after']        = array(
342
-			'description'       => __( 'Limit response to objects with last order after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
341
+		$params['last_order_after'] = array(
342
+			'description'       => __('Limit response to objects with last order after (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
343 343
 			'type'              => 'string',
344 344
 			'format'            => 'date-time',
345 345
 			'validate_callback' => 'rest_validate_request_arg',
346 346
 		);
347
-		$params['customers']               = array(
348
-			'description'       => __( 'Limit result to items with specified customer ids.', 'woocommerce' ),
347
+		$params['customers'] = array(
348
+			'description'       => __('Limit result to items with specified customer ids.', 'woocommerce'),
349 349
 			'type'              => 'array',
350 350
 			'sanitize_callback' => 'wp_parse_id_list',
351 351
 			'validate_callback' => 'rest_validate_request_arg',
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports/Customers.php 1 patch
Spacing   +145 added lines, -145 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['registered_before']   = $request['registered_before'];
37 37
 		$args['registered_after']    = $request['registered_after'];
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
 		$args['last_order_after']    = $request['last_order_after'];
65 65
 		$args['customers']           = $request['customers'];
66 66
 
67
-		$between_params_numeric    = array( 'orders_count', 'total_spend', 'avg_order_value' );
68
-		$normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false );
69
-		$between_params_date       = array( 'last_active', 'registered' );
70
-		$normalized_params_date    = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true );
71
-		$args                      = array_merge( $args, $normalized_params_numeric, $normalized_params_date );
67
+		$between_params_numeric    = array('orders_count', 'total_spend', 'avg_order_value');
68
+		$normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params($request, $between_params_numeric, false);
69
+		$between_params_date       = array('last_active', 'registered');
70
+		$normalized_params_date    = \WC_Admin_Reports_Interval::normalize_between_params($request, $between_params_date, true);
71
+		$args                      = array_merge($args, $normalized_params_numeric, $normalized_params_date);
72 72
 
73 73
 		return $args;
74 74
 	}
@@ -79,37 +79,37 @@  discard block
 block discarded – undo
79 79
 	 * @param \WP_REST_Request $request Request data.
80 80
 	 * @return array|\WP_Error
81 81
 	 */
82
-	public function get_items( $request ) {
83
-		$query_args      = $this->prepare_reports_query( $request );
84
-		$customers_query = new \WC_Admin_Reports_Customers_Query( $query_args );
82
+	public function get_items($request) {
83
+		$query_args      = $this->prepare_reports_query($request);
84
+		$customers_query = new \WC_Admin_Reports_Customers_Query($query_args);
85 85
 		$report_data     = $customers_query->get_data();
86 86
 
87 87
 		$data = array();
88 88
 
89
-		foreach ( $report_data->data as $customer_data ) {
90
-			$item   = $this->prepare_item_for_response( $customer_data, $request );
91
-			$data[] = $this->prepare_response_for_collection( $item );
89
+		foreach ($report_data->data as $customer_data) {
90
+			$item   = $this->prepare_item_for_response($customer_data, $request);
91
+			$data[] = $this->prepare_response_for_collection($item);
92 92
 		}
93 93
 
94
-		$response = rest_ensure_response( $data );
95
-		$response->header( 'X-WP-Total', (int) $report_data->total );
96
-		$response->header( 'X-WP-TotalPages', (int) $report_data->pages );
94
+		$response = rest_ensure_response($data);
95
+		$response->header('X-WP-Total', (int) $report_data->total);
96
+		$response->header('X-WP-TotalPages', (int) $report_data->pages);
97 97
 
98 98
 		$page      = $report_data->page_no;
99 99
 		$max_pages = $report_data->pages;
100
-		$base      = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
101
-		if ( $page > 1 ) {
100
+		$base      = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
101
+		if ($page > 1) {
102 102
 			$prev_page = $page - 1;
103
-			if ( $prev_page > $max_pages ) {
103
+			if ($prev_page > $max_pages) {
104 104
 				$prev_page = $max_pages;
105 105
 			}
106
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
107
-			$response->link_header( 'prev', $prev_link );
106
+			$prev_link = add_query_arg('page', $prev_page, $base);
107
+			$response->link_header('prev', $prev_link);
108 108
 		}
109
-		if ( $max_pages > $page ) {
109
+		if ($max_pages > $page) {
110 110
 			$next_page = $page + 1;
111
-			$next_link = add_query_arg( 'page', $next_page, $base );
112
-			$response->link_header( 'next', $next_link );
111
+			$next_link = add_query_arg('page', $next_page, $base);
112
+			$response->link_header('next', $next_link);
113 113
 		}
114 114
 
115 115
 		return $response;
@@ -122,18 +122,18 @@  discard block
 block discarded – undo
122 122
 	 * @param \WP_REST_Request $request Request object.
123 123
 	 * @return \WP_REST_Response
124 124
 	 */
125
-	public function prepare_item_for_response( $report, $request ) {
126
-		$context                      = ! empty( $request['context'] ) ? $request['context'] : 'view';
127
-		$data                         = $this->add_additional_fields_to_object( $report, $request );
128
-		$data['date_registered_gmt']  = wc_rest_prepare_date_response( $data['date_registered'] );
129
-		$data['date_registered']      = wc_rest_prepare_date_response( $data['date_registered'], false );
130
-		$data['date_last_active_gmt'] = wc_rest_prepare_date_response( $data['date_last_active'] );
131
-		$data['date_last_active']     = wc_rest_prepare_date_response( $data['date_last_active'], false );
132
-		$data                         = $this->filter_response_by_context( $data, $context );
125
+	public function prepare_item_for_response($report, $request) {
126
+		$context                      = ! empty($request['context']) ? $request['context'] : 'view';
127
+		$data                         = $this->add_additional_fields_to_object($report, $request);
128
+		$data['date_registered_gmt']  = wc_rest_prepare_date_response($data['date_registered']);
129
+		$data['date_registered']      = wc_rest_prepare_date_response($data['date_registered'], false);
130
+		$data['date_last_active_gmt'] = wc_rest_prepare_date_response($data['date_last_active']);
131
+		$data['date_last_active']     = wc_rest_prepare_date_response($data['date_last_active'], false);
132
+		$data                         = $this->filter_response_by_context($data, $context);
133 133
 
134 134
 		// Wrap the data in a response object.
135
-		$response = rest_ensure_response( $data );
136
-		$response->add_links( $this->prepare_links( $report ) );
135
+		$response = rest_ensure_response($data);
136
+		$response->add_links($this->prepare_links($report));
137 137
 		/**
138 138
 		 * Filter a report returned from the API.
139 139
 		 *
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		 * @param object           $report   The original report object.
144 144
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
145 145
 		 */
146
-		return apply_filters( 'woocommerce_rest_prepare_report_customers', $response, $report, $request );
146
+		return apply_filters('woocommerce_rest_prepare_report_customers', $response, $report, $request);
147 147
 	}
148 148
 
149 149
 	/**
@@ -152,14 +152,14 @@  discard block
 block discarded – undo
152 152
 	 * @param array $object Object data.
153 153
 	 * @return array
154 154
 	 */
155
-	protected function prepare_links( $object ) {
156
-		if ( empty( $object['user_id'] ) ) {
155
+	protected function prepare_links($object) {
156
+		if (empty($object['user_id'])) {
157 157
 			return array();
158 158
 		}
159 159
 
160 160
 		return array(
161 161
 			'customer' => array(
162
-				'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $object['user_id'] ) ),
162
+				'href' => rest_url(sprintf('/%s/customers/%d', $this->namespace, $object['user_id'])),
163 163
 			),
164 164
 		);
165 165
 	}
@@ -176,92 +176,92 @@  discard block
 block discarded – undo
176 176
 			'type'       => 'object',
177 177
 			'properties' => array(
178 178
 				'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
 				'user_id'              => array(
185
-					'description' => __( 'User ID.', 'woocommerce' ),
185
+					'description' => __('User ID.', 'woocommerce'),
186 186
 					'type'        => 'integer',
187
-					'context'     => array( 'view', 'edit' ),
187
+					'context'     => array('view', 'edit'),
188 188
 					'readonly'    => true,
189 189
 				),
190 190
 				'name'                 => array(
191
-					'description' => __( 'Name.', 'woocommerce' ),
191
+					'description' => __('Name.', 'woocommerce'),
192 192
 					'type'        => 'string',
193
-					'context'     => array( 'view', 'edit' ),
193
+					'context'     => array('view', 'edit'),
194 194
 					'readonly'    => true,
195 195
 				),
196 196
 				'username'             => array(
197
-					'description' => __( 'Username.', 'woocommerce' ),
197
+					'description' => __('Username.', 'woocommerce'),
198 198
 					'type'        => 'string',
199
-					'context'     => array( 'view', 'edit' ),
199
+					'context'     => array('view', 'edit'),
200 200
 					'readonly'    => true,
201 201
 				),
202 202
 				'country'              => array(
203
-					'description' => __( 'Country.', 'woocommerce' ),
203
+					'description' => __('Country.', 'woocommerce'),
204 204
 					'type'        => 'string',
205
-					'context'     => array( 'view', 'edit' ),
205
+					'context'     => array('view', 'edit'),
206 206
 					'readonly'    => true,
207 207
 				),
208 208
 				'city'                 => array(
209
-					'description' => __( 'City.', 'woocommerce' ),
209
+					'description' => __('City.', 'woocommerce'),
210 210
 					'type'        => 'string',
211
-					'context'     => array( 'view', 'edit' ),
211
+					'context'     => array('view', 'edit'),
212 212
 					'readonly'    => true,
213 213
 				),
214 214
 				'postcode'             => array(
215
-					'description' => __( 'Postal code.', 'woocommerce' ),
215
+					'description' => __('Postal code.', 'woocommerce'),
216 216
 					'type'        => 'string',
217
-					'context'     => array( 'view', 'edit' ),
217
+					'context'     => array('view', 'edit'),
218 218
 					'readonly'    => true,
219 219
 				),
220 220
 				'date_registered'      => array(
221
-					'description' => __( 'Date registered.', 'woocommerce' ),
221
+					'description' => __('Date registered.', 'woocommerce'),
222 222
 					'type'        => 'date-time',
223
-					'context'     => array( 'view', 'edit' ),
223
+					'context'     => array('view', 'edit'),
224 224
 					'readonly'    => true,
225 225
 				),
226 226
 				'date_registered_gmt'  => array(
227
-					'description' => __( 'Date registered GMT.', 'woocommerce' ),
227
+					'description' => __('Date registered GMT.', 'woocommerce'),
228 228
 					'type'        => 'date-time',
229
-					'context'     => array( 'view', 'edit' ),
229
+					'context'     => array('view', 'edit'),
230 230
 					'readonly'    => true,
231 231
 				),
232 232
 				'date_last_active'     => array(
233
-					'description' => __( 'Date last active.', 'woocommerce' ),
233
+					'description' => __('Date last active.', 'woocommerce'),
234 234
 					'type'        => 'date-time',
235
-					'context'     => array( 'view', 'edit' ),
235
+					'context'     => array('view', 'edit'),
236 236
 					'readonly'    => true,
237 237
 				),
238 238
 				'date_last_active_gmt' => array(
239
-					'description' => __( 'Date last active GMT.', 'woocommerce' ),
239
+					'description' => __('Date last active GMT.', 'woocommerce'),
240 240
 					'type'        => 'date-time',
241
-					'context'     => array( 'view', 'edit' ),
241
+					'context'     => array('view', 'edit'),
242 242
 					'readonly'    => true,
243 243
 				),
244 244
 				'orders_count'         => array(
245
-					'description' => __( 'Order count.', 'woocommerce' ),
245
+					'description' => __('Order count.', 'woocommerce'),
246 246
 					'type'        => 'integer',
247
-					'context'     => array( 'view', 'edit' ),
247
+					'context'     => array('view', 'edit'),
248 248
 					'readonly'    => true,
249 249
 				),
250 250
 				'total_spend'          => array(
251
-					'description' => __( 'Total spend.', 'woocommerce' ),
251
+					'description' => __('Total spend.', 'woocommerce'),
252 252
 					'type'        => 'number',
253
-					'context'     => array( 'view', 'edit' ),
253
+					'context'     => array('view', 'edit'),
254 254
 					'readonly'    => true,
255 255
 				),
256 256
 				'avg_order_value'      => array(
257
-					'description' => __( 'Avg order value.', 'woocommerce' ),
257
+					'description' => __('Avg order value.', 'woocommerce'),
258 258
 					'type'        => 'number',
259
-					'context'     => array( 'view', 'edit' ),
259
+					'context'     => array('view', 'edit'),
260 260
 					'readonly'    => true,
261 261
 				),
262 262
 			),
263 263
 		);
264
-		return $this->add_additional_fields_schema( $schema );
264
+		return $this->add_additional_fields_schema($schema);
265 265
 	}
266 266
 
267 267
 	/**
@@ -271,41 +271,41 @@  discard block
 block discarded – undo
271 271
 	 */
272 272
 	public function get_collection_params() {
273 273
 		$params                            = array();
274
-		$params['context']                 = $this->get_context_param( array( 'default' => 'view' ) );
274
+		$params['context']                 = $this->get_context_param(array('default' => 'view'));
275 275
 		$params['registered_before']       = array(
276
-			'description'       => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
276
+			'description'       => __('Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
277 277
 			'type'              => 'string',
278 278
 			'format'            => 'date-time',
279 279
 			'validate_callback' => 'rest_validate_request_arg',
280 280
 		);
281
-		$params['registered_after']        = array(
282
-			'description'       => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
281
+		$params['registered_after'] = array(
282
+			'description'       => __('Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
283 283
 			'type'              => 'string',
284 284
 			'format'            => 'date-time',
285 285
 			'validate_callback' => 'rest_validate_request_arg',
286 286
 		);
287
-		$params['after']                   = array(
288
-			'description'       => __( 'Limit response to resources with orders published after a given ISO8601 compliant date.', 'woocommerce' ),
287
+		$params['after'] = array(
288
+			'description'       => __('Limit response to resources with orders published after a given ISO8601 compliant date.', 'woocommerce'),
289 289
 			'type'              => 'string',
290 290
 			'format'            => 'date-time',
291 291
 			'validate_callback' => 'rest_validate_request_arg',
292 292
 		);
293
-		$params['before']                  = array(
294
-			'description'       => __( 'Limit response to resources with orders published before a given ISO8601 compliant date.', 'woocommerce' ),
293
+		$params['before'] = array(
294
+			'description'       => __('Limit response to resources with orders published before a given ISO8601 compliant date.', 'woocommerce'),
295 295
 			'type'              => 'string',
296 296
 			'format'            => 'date-time',
297 297
 			'validate_callback' => 'rest_validate_request_arg',
298 298
 		);
299
-		$params['page']                    = array(
300
-			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
299
+		$params['page'] = array(
300
+			'description'       => __('Current page of the collection.', 'woocommerce'),
301 301
 			'type'              => 'integer',
302 302
 			'default'           => 1,
303 303
 			'sanitize_callback' => 'absint',
304 304
 			'validate_callback' => 'rest_validate_request_arg',
305 305
 			'minimum'           => 1,
306 306
 		);
307
-		$params['per_page']                = array(
308
-			'description'       => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
307
+		$params['per_page'] = array(
308
+			'description'       => __('Maximum number of items to be returned in result set.', 'woocommerce'),
309 309
 			'type'              => 'integer',
310 310
 			'default'           => 10,
311 311
 			'minimum'           => 1,
@@ -313,15 +313,15 @@  discard block
 block discarded – undo
313 313
 			'sanitize_callback' => 'absint',
314 314
 			'validate_callback' => 'rest_validate_request_arg',
315 315
 		);
316
-		$params['order']                   = array(
317
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
316
+		$params['order'] = array(
317
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
318 318
 			'type'              => 'string',
319 319
 			'default'           => 'desc',
320
-			'enum'              => array( 'asc', 'desc' ),
320
+			'enum'              => array('asc', 'desc'),
321 321
 			'validate_callback' => 'rest_validate_request_arg',
322 322
 		);
323
-		$params['orderby']                 = array(
324
-			'description'       => __( 'Sort collection by object attribute.', 'woocommerce' ),
323
+		$params['orderby'] = array(
324
+			'description'       => __('Sort collection by object attribute.', 'woocommerce'),
325 325
 			'type'              => 'string',
326 326
 			'default'           => 'date_registered',
327 327
 			'enum'              => array(
@@ -338,8 +338,8 @@  discard block
 block discarded – undo
338 338
 			),
339 339
 			'validate_callback' => 'rest_validate_request_arg',
340 340
 		);
341
-		$params['match']                   = array(
342
-			'description'       => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ),
341
+		$params['match'] = array(
342
+			'description'       => __('Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce'),
343 343
 			'type'              => 'string',
344 344
 			'default'           => 'all',
345 345
 			'enum'              => array(
@@ -348,12 +348,12 @@  discard block
 block discarded – undo
348 348
 			),
349 349
 			'validate_callback' => 'rest_validate_request_arg',
350 350
 		);
351
-		$params['search']                  = array(
352
-			'description'       => __( 'Limit response to objects with a customer field containing the search term. Searches the field provided by `searchby`.', 'woocommerce' ),
351
+		$params['search'] = array(
352
+			'description'       => __('Limit response to objects with a customer field containing the search term. Searches the field provided by `searchby`.', 'woocommerce'),
353 353
 			'type'              => 'string',
354 354
 			'validate_callback' => 'rest_validate_request_arg',
355 355
 		);
356
-		$params['searchby']                = array(
356
+		$params['searchby'] = array(
357 357
 			'description' => 'Limit results with `search` and `searchby` to specific fields containing the search term.',
358 358
 			'type'        => 'string',
359 359
 			'default'     => 'name',
@@ -363,141 +363,141 @@  discard block
 block discarded – undo
363 363
 				'email',
364 364
 			),
365 365
 		);
366
-		$params['name_includes']           = array(
367
-			'description'       => __( 'Limit response to objects with specfic names.', 'woocommerce' ),
366
+		$params['name_includes'] = array(
367
+			'description'       => __('Limit response to objects with specfic names.', 'woocommerce'),
368 368
 			'type'              => 'string',
369 369
 			'validate_callback' => 'rest_validate_request_arg',
370 370
 		);
371
-		$params['name_excludes']           = array(
372
-			'description'       => __( 'Limit response to objects excluding specfic names.', 'woocommerce' ),
371
+		$params['name_excludes'] = array(
372
+			'description'       => __('Limit response to objects excluding specfic names.', 'woocommerce'),
373 373
 			'type'              => 'string',
374 374
 			'validate_callback' => 'rest_validate_request_arg',
375 375
 		);
376
-		$params['username_includes']       = array(
377
-			'description'       => __( 'Limit response to objects with specfic usernames.', 'woocommerce' ),
376
+		$params['username_includes'] = array(
377
+			'description'       => __('Limit response to objects with specfic usernames.', 'woocommerce'),
378 378
 			'type'              => 'string',
379 379
 			'validate_callback' => 'rest_validate_request_arg',
380 380
 		);
381
-		$params['username_excludes']       = array(
382
-			'description'       => __( 'Limit response to objects excluding specfic usernames.', 'woocommerce' ),
381
+		$params['username_excludes'] = array(
382
+			'description'       => __('Limit response to objects excluding specfic usernames.', 'woocommerce'),
383 383
 			'type'              => 'string',
384 384
 			'validate_callback' => 'rest_validate_request_arg',
385 385
 		);
386
-		$params['email_includes']          = array(
387
-			'description'       => __( 'Limit response to objects including emails.', 'woocommerce' ),
386
+		$params['email_includes'] = array(
387
+			'description'       => __('Limit response to objects including emails.', 'woocommerce'),
388 388
 			'type'              => 'string',
389 389
 			'validate_callback' => 'rest_validate_request_arg',
390 390
 		);
391
-		$params['email_excludes']          = array(
392
-			'description'       => __( 'Limit response to objects excluding emails.', 'woocommerce' ),
391
+		$params['email_excludes'] = array(
392
+			'description'       => __('Limit response to objects excluding emails.', 'woocommerce'),
393 393
 			'type'              => 'string',
394 394
 			'validate_callback' => 'rest_validate_request_arg',
395 395
 		);
396
-		$params['country_includes']        = array(
397
-			'description'       => __( 'Limit response to objects with specfic countries.', 'woocommerce' ),
396
+		$params['country_includes'] = array(
397
+			'description'       => __('Limit response to objects with specfic countries.', 'woocommerce'),
398 398
 			'type'              => 'string',
399 399
 			'validate_callback' => 'rest_validate_request_arg',
400 400
 		);
401
-		$params['country_excludes']        = array(
402
-			'description'       => __( 'Limit response to objects excluding specfic countries.', 'woocommerce' ),
401
+		$params['country_excludes'] = array(
402
+			'description'       => __('Limit response to objects excluding specfic countries.', 'woocommerce'),
403 403
 			'type'              => 'string',
404 404
 			'validate_callback' => 'rest_validate_request_arg',
405 405
 		);
406
-		$params['last_active_before']      = array(
407
-			'description'       => __( 'Limit response to objects last active before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
406
+		$params['last_active_before'] = array(
407
+			'description'       => __('Limit response to objects last active before (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
408 408
 			'type'              => 'string',
409 409
 			'format'            => 'date-time',
410 410
 			'validate_callback' => 'rest_validate_request_arg',
411 411
 		);
412
-		$params['last_active_after']       = array(
413
-			'description'       => __( 'Limit response to objects last active after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
412
+		$params['last_active_after'] = array(
413
+			'description'       => __('Limit response to objects last active after (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
414 414
 			'type'              => 'string',
415 415
 			'format'            => 'date-time',
416 416
 			'validate_callback' => 'rest_validate_request_arg',
417 417
 		);
418
-		$params['last_active_between']     = array(
419
-			'description'       => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ),
418
+		$params['last_active_between'] = array(
419
+			'description'       => __('Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce'),
420 420
 			'type'              => 'array',
421
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ),
421
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_date_arg'),
422 422
 		);
423
-		$params['registered_before']       = array(
424
-			'description'       => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
423
+		$params['registered_before'] = array(
424
+			'description'       => __('Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
425 425
 			'type'              => 'string',
426 426
 			'format'            => 'date-time',
427 427
 			'validate_callback' => 'rest_validate_request_arg',
428 428
 		);
429
-		$params['registered_after']        = array(
430
-			'description'       => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
429
+		$params['registered_after'] = array(
430
+			'description'       => __('Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
431 431
 			'type'              => 'string',
432 432
 			'format'            => 'date-time',
433 433
 			'validate_callback' => 'rest_validate_request_arg',
434 434
 		);
435
-		$params['registered_between']      = array(
436
-			'description'       => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ),
435
+		$params['registered_between'] = array(
436
+			'description'       => __('Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce'),
437 437
 			'type'              => 'array',
438
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ),
438
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_date_arg'),
439 439
 		);
440
-		$params['orders_count_min']        = array(
441
-			'description'       => __( 'Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce' ),
440
+		$params['orders_count_min'] = array(
441
+			'description'       => __('Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce'),
442 442
 			'type'              => 'integer',
443 443
 			'sanitize_callback' => 'absint',
444 444
 			'validate_callback' => 'rest_validate_request_arg',
445 445
 		);
446
-		$params['orders_count_max']        = array(
447
-			'description'       => __( 'Limit response to objects with an order count less than or equal to given integer.', 'woocommerce' ),
446
+		$params['orders_count_max'] = array(
447
+			'description'       => __('Limit response to objects with an order count less than or equal to given integer.', 'woocommerce'),
448 448
 			'type'              => 'integer',
449 449
 			'sanitize_callback' => 'absint',
450 450
 			'validate_callback' => 'rest_validate_request_arg',
451 451
 		);
452
-		$params['orders_count_between']    = array(
453
-			'description'       => __( 'Limit response to objects with an order count between two given integers.', 'woocommerce' ),
452
+		$params['orders_count_between'] = array(
453
+			'description'       => __('Limit response to objects with an order count between two given integers.', 'woocommerce'),
454 454
 			'type'              => 'array',
455
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ),
455
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'),
456 456
 		);
457
-		$params['total_spend_min']         = array(
458
-			'description'       => __( 'Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce' ),
457
+		$params['total_spend_min'] = array(
458
+			'description'       => __('Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce'),
459 459
 			'type'              => 'number',
460 460
 			'validate_callback' => 'rest_validate_request_arg',
461 461
 		);
462
-		$params['total_spend_max']         = array(
463
-			'description'       => __( 'Limit response to objects with a total order spend less than or equal to given number.', 'woocommerce' ),
462
+		$params['total_spend_max'] = array(
463
+			'description'       => __('Limit response to objects with a total order spend less than or equal to given number.', 'woocommerce'),
464 464
 			'type'              => 'number',
465 465
 			'validate_callback' => 'rest_validate_request_arg',
466 466
 		);
467
-		$params['total_spend_between']     = array(
468
-			'description'       => __( 'Limit response to objects with a total order spend between two given numbers.', 'woocommerce' ),
467
+		$params['total_spend_between'] = array(
468
+			'description'       => __('Limit response to objects with a total order spend between two given numbers.', 'woocommerce'),
469 469
 			'type'              => 'array',
470
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ),
470
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'),
471 471
 		);
472
-		$params['avg_order_value_min']     = array(
473
-			'description'       => __( 'Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce' ),
472
+		$params['avg_order_value_min'] = array(
473
+			'description'       => __('Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce'),
474 474
 			'type'              => 'number',
475 475
 			'validate_callback' => 'rest_validate_request_arg',
476 476
 		);
477
-		$params['avg_order_value_max']     = array(
478
-			'description'       => __( 'Limit response to objects with an average order spend less than or equal to given number.', 'woocommerce' ),
477
+		$params['avg_order_value_max'] = array(
478
+			'description'       => __('Limit response to objects with an average order spend less than or equal to given number.', 'woocommerce'),
479 479
 			'type'              => 'number',
480 480
 			'validate_callback' => 'rest_validate_request_arg',
481 481
 		);
482 482
 		$params['avg_order_value_between'] = array(
483
-			'description'       => __( 'Limit response to objects with an average order spend between two given numbers.', 'woocommerce' ),
483
+			'description'       => __('Limit response to objects with an average order spend between two given numbers.', 'woocommerce'),
484 484
 			'type'              => 'array',
485
-			'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ),
485
+			'validate_callback' => array('WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg'),
486 486
 		);
487
-		$params['last_order_before']       = array(
488
-			'description'       => __( 'Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
487
+		$params['last_order_before'] = array(
488
+			'description'       => __('Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
489 489
 			'type'              => 'string',
490 490
 			'format'            => 'date-time',
491 491
 			'validate_callback' => 'rest_validate_request_arg',
492 492
 		);
493
-		$params['last_order_after']        = array(
494
-			'description'       => __( 'Limit response to objects with last order after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
493
+		$params['last_order_after'] = array(
494
+			'description'       => __('Limit response to objects with last order after (or at) a given ISO8601 compliant datetime.', 'woocommerce'),
495 495
 			'type'              => 'string',
496 496
 			'format'            => 'date-time',
497 497
 			'validate_callback' => 'rest_validate_request_arg',
498 498
 		);
499
-		$params['customers']               = array(
500
-			'description'       => __( 'Limit result to items with specified customer ids.', 'woocommerce' ),
499
+		$params['customers'] = array(
500
+			'description'       => __('Limit result to items with specified customer ids.', 'woocommerce'),
501 501
 			'type'              => 'array',
502 502
 			'sanitize_callback' => 'wp_parse_id_list',
503 503
 			'validate_callback' => 'rest_validate_request_arg',
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports/TaxStats.php 1 patch
Spacing   +83 added lines, -83 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
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * Constructor.
30 30
 	 */
31 31
 	public function __construct() {
32
-		add_filter( 'woocommerce_reports_taxes_stats_select_query', array( $this, 'set_default_report_data' ) );
32
+		add_filter('woocommerce_reports_taxes_stats_select_query', array($this, 'set_default_report_data'));
33 33
 	}
34 34
 
35 35
 	/**
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 	 * @param Mixed $results Report data.
39 39
 	 * @return object
40 40
 	 */
41
-	public function set_default_report_data( $results ) {
42
-		if ( empty( $results ) ) {
41
+	public function set_default_report_data($results) {
42
+		if (empty($results)) {
43 43
 			$results                       = new \stdClass();
44 44
 			$results->total                = 0;
45 45
 			$results->totals               = new \stdClass();
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 * @param array $request Request array.
62 62
 	 * @return array
63 63
 	 */
64
-	protected function prepare_reports_query( $request ) {
64
+	protected function prepare_reports_query($request) {
65 65
 		$args              = array();
66 66
 		$args['before']    = $request['before'];
67 67
 		$args['after']     = $request['after'];
@@ -82,40 +82,40 @@  discard block
 block discarded – undo
82 82
 	 * @param \WP_REST_Request $request Request data.
83 83
 	 * @return array|\WP_Error
84 84
 	 */
85
-	public function get_items( $request ) {
86
-		$query_args  = $this->prepare_reports_query( $request );
87
-		$taxes_query = new \WC_Admin_Reports_Taxes_Stats_Query( $query_args );
85
+	public function get_items($request) {
86
+		$query_args  = $this->prepare_reports_query($request);
87
+		$taxes_query = new \WC_Admin_Reports_Taxes_Stats_Query($query_args);
88 88
 		$report_data = $taxes_query->get_data();
89 89
 
90 90
 		$out_data = array(
91
-			'totals'    => get_object_vars( $report_data->totals ),
91
+			'totals'    => get_object_vars($report_data->totals),
92 92
 			'intervals' => array(),
93 93
 		);
94 94
 
95
-		foreach ( $report_data->intervals as $interval_data ) {
96
-			$item                    = $this->prepare_item_for_response( (object) $interval_data, $request );
97
-			$out_data['intervals'][] = $this->prepare_response_for_collection( $item );
95
+		foreach ($report_data->intervals as $interval_data) {
96
+			$item                    = $this->prepare_item_for_response((object) $interval_data, $request);
97
+			$out_data['intervals'][] = $this->prepare_response_for_collection($item);
98 98
 		}
99 99
 
100
-		$response = rest_ensure_response( $out_data );
101
-		$response->header( 'X-WP-Total', (int) $report_data->total );
102
-		$response->header( 'X-WP-TotalPages', (int) $report_data->pages );
100
+		$response = rest_ensure_response($out_data);
101
+		$response->header('X-WP-Total', (int) $report_data->total);
102
+		$response->header('X-WP-TotalPages', (int) $report_data->pages);
103 103
 
104 104
 		$page      = $report_data->page_no;
105 105
 		$max_pages = $report_data->pages;
106
-		$base      = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
107
-		if ( $page > 1 ) {
106
+		$base      = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
107
+		if ($page > 1) {
108 108
 			$prev_page = $page - 1;
109
-			if ( $prev_page > $max_pages ) {
109
+			if ($prev_page > $max_pages) {
110 110
 				$prev_page = $max_pages;
111 111
 			}
112
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
113
-			$response->link_header( 'prev', $prev_link );
112
+			$prev_link = add_query_arg('page', $prev_page, $base);
113
+			$response->link_header('prev', $prev_link);
114 114
 		}
115
-		if ( $max_pages > $page ) {
115
+		if ($max_pages > $page) {
116 116
 			$next_page = $page + 1;
117
-			$next_link = add_query_arg( 'page', $next_page, $base );
118
-			$response->link_header( 'next', $next_link );
117
+			$next_link = add_query_arg('page', $next_page, $base);
118
+			$response->link_header('next', $next_link);
119 119
 		}
120 120
 
121 121
 		return $response;
@@ -128,15 +128,15 @@  discard block
 block discarded – undo
128 128
 	 * @param \WP_REST_Request $request Request object.
129 129
 	 * @return \WP_REST_Response
130 130
 	 */
131
-	public function prepare_item_for_response( $report, $request ) {
132
-		$data = get_object_vars( $report );
131
+	public function prepare_item_for_response($report, $request) {
132
+		$data = get_object_vars($report);
133 133
 
134
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
135
-		$data    = $this->add_additional_fields_to_object( $data, $request );
136
-		$data    = $this->filter_response_by_context( $data, $context );
134
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
135
+		$data    = $this->add_additional_fields_to_object($data, $request);
136
+		$data    = $this->filter_response_by_context($data, $context);
137 137
 
138 138
 		// Wrap the data in a response object.
139
-		$response = rest_ensure_response( $data );
139
+		$response = rest_ensure_response($data);
140 140
 
141 141
 		/**
142 142
 		 * Filter a report returned from the API.
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 		 * @param object           $report   The original report object.
148 148
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
149 149
 		 */
150
-		return apply_filters( 'woocommerce_rest_prepare_report_taxes_stats', $response, $report, $request );
150
+		return apply_filters('woocommerce_rest_prepare_report_taxes_stats', $response, $report, $request);
151 151
 	}
152 152
 
153 153
 	/**
@@ -158,62 +158,62 @@  discard block
 block discarded – undo
158 158
 	public function get_item_schema() {
159 159
 		$data_values = array(
160 160
 			'total_tax'    => array(
161
-				'description' => __( 'Total tax.', 'woocommerce' ),
161
+				'description' => __('Total tax.', 'woocommerce'),
162 162
 				'type'        => 'number',
163
-				'context'     => array( 'view', 'edit' ),
163
+				'context'     => array('view', 'edit'),
164 164
 				'readonly'    => true,
165 165
 				'indicator'   => true,
166 166
 				'format'      => 'currency',
167 167
 			),
168 168
 			'order_tax'    => array(
169
-				'description' => __( 'Order tax.', 'woocommerce' ),
169
+				'description' => __('Order tax.', 'woocommerce'),
170 170
 				'type'        => 'number',
171
-				'context'     => array( 'view', 'edit' ),
171
+				'context'     => array('view', 'edit'),
172 172
 				'readonly'    => true,
173 173
 				'indicator'   => true,
174 174
 				'format'      => 'currency',
175 175
 			),
176 176
 			'shipping_tax' => array(
177
-				'description' => __( 'Shipping tax.', 'woocommerce' ),
177
+				'description' => __('Shipping tax.', 'woocommerce'),
178 178
 				'type'        => 'number',
179
-				'context'     => array( 'view', 'edit' ),
179
+				'context'     => array('view', 'edit'),
180 180
 				'readonly'    => true,
181 181
 				'indicator'   => true,
182 182
 				'format'      => 'currency',
183 183
 			),
184 184
 			'orders_count' => array(
185
-				'description' => __( 'Amount of orders.', 'woocommerce' ),
185
+				'description' => __('Amount of orders.', 'woocommerce'),
186 186
 				'type'        => 'integer',
187
-				'context'     => array( 'view', 'edit' ),
187
+				'context'     => array('view', 'edit'),
188 188
 				'readonly'    => true,
189 189
 			),
190 190
 			'tax_codes'    => array(
191
-				'description' => __( 'Amount of tax codes.', 'woocommerce' ),
191
+				'description' => __('Amount of tax codes.', 'woocommerce'),
192 192
 				'type'        => 'integer',
193
-				'context'     => array( 'view', 'edit' ),
193
+				'context'     => array('view', 'edit'),
194 194
 				'readonly'    => true,
195 195
 			),
196 196
 		);
197 197
 
198 198
 		$segments = array(
199 199
 			'segments' => array(
200
-				'description' => __( 'Reports data grouped by segment condition.', 'woocommerce' ),
200
+				'description' => __('Reports data grouped by segment condition.', 'woocommerce'),
201 201
 				'type'        => 'array',
202
-				'context'     => array( 'view', 'edit' ),
202
+				'context'     => array('view', 'edit'),
203 203
 				'readonly'    => true,
204 204
 				'items'       => array(
205 205
 					'type'       => 'object',
206 206
 					'properties' => array(
207 207
 						'segment_id' => array(
208
-							'description' => __( 'Segment identificator.', 'woocommerce' ),
208
+							'description' => __('Segment identificator.', 'woocommerce'),
209 209
 							'type'        => 'integer',
210
-							'context'     => array( 'view', 'edit' ),
210
+							'context'     => array('view', 'edit'),
211 211
 							'readonly'    => true,
212 212
 						),
213 213
 						'subtotals'  => array(
214
-							'description' => __( 'Interval subtotals.', 'woocommerce' ),
214
+							'description' => __('Interval subtotals.', 'woocommerce'),
215 215
 							'type'        => 'object',
216
-							'context'     => array( 'view', 'edit' ),
216
+							'context'     => array('view', 'edit'),
217 217
 							'readonly'    => true,
218 218
 							'properties'  => $data_values,
219 219
 						),
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 			),
223 223
 		);
224 224
 
225
-		$totals = array_merge( $data_values, $segments );
225
+		$totals = array_merge($data_values, $segments);
226 226
 
227 227
 		$schema = array(
228 228
 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
@@ -230,55 +230,55 @@  discard block
 block discarded – undo
230 230
 			'type'       => 'object',
231 231
 			'properties' => array(
232 232
 				'totals'    => array(
233
-					'description' => __( 'Totals data.', 'woocommerce' ),
233
+					'description' => __('Totals data.', 'woocommerce'),
234 234
 					'type'        => 'object',
235
-					'context'     => array( 'view', 'edit' ),
235
+					'context'     => array('view', 'edit'),
236 236
 					'readonly'    => true,
237 237
 					'properties'  => $totals,
238 238
 				),
239 239
 				'intervals' => array(
240
-					'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ),
240
+					'description' => __('Reports data grouped by intervals.', 'woocommerce'),
241 241
 					'type'        => 'array',
242
-					'context'     => array( 'view', 'edit' ),
242
+					'context'     => array('view', 'edit'),
243 243
 					'readonly'    => true,
244 244
 					'items'       => array(
245 245
 						'type'       => 'object',
246 246
 						'properties' => array(
247 247
 							'interval'       => array(
248
-								'description' => __( 'Type of interval.', 'woocommerce' ),
248
+								'description' => __('Type of interval.', 'woocommerce'),
249 249
 								'type'        => 'string',
250
-								'context'     => array( 'view', 'edit' ),
250
+								'context'     => array('view', 'edit'),
251 251
 								'readonly'    => true,
252
-								'enum'        => array( 'day', 'week', 'month', 'year' ),
252
+								'enum'        => array('day', 'week', 'month', 'year'),
253 253
 							),
254 254
 							'date_start'     => array(
255
-								'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ),
255
+								'description' => __("The date the report start, in the site's timezone.", 'woocommerce'),
256 256
 								'type'        => 'date-time',
257
-								'context'     => array( 'view', 'edit' ),
257
+								'context'     => array('view', 'edit'),
258 258
 								'readonly'    => true,
259 259
 							),
260 260
 							'date_start_gmt' => array(
261
-								'description' => __( 'The date the report start, as GMT.', 'woocommerce' ),
261
+								'description' => __('The date the report start, as GMT.', 'woocommerce'),
262 262
 								'type'        => 'date-time',
263
-								'context'     => array( 'view', 'edit' ),
263
+								'context'     => array('view', 'edit'),
264 264
 								'readonly'    => true,
265 265
 							),
266 266
 							'date_end'       => array(
267
-								'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ),
267
+								'description' => __("The date the report end, 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_end_gmt'   => array(
273
-								'description' => __( 'The date the report end, as GMT.', 'woocommerce' ),
273
+								'description' => __('The date the report end, 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
 							'subtotals'      => array(
279
-								'description' => __( 'Interval subtotals.', 'woocommerce' ),
279
+								'description' => __('Interval subtotals.', 'woocommerce'),
280 280
 								'type'        => 'object',
281
-								'context'     => array( 'view', 'edit' ),
281
+								'context'     => array('view', 'edit'),
282 282
 								'readonly'    => true,
283 283
 								'properties'  => $totals,
284 284
 							),
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 			),
289 289
 		);
290 290
 
291
-		return $this->add_additional_fields_schema( $schema );
291
+		return $this->add_additional_fields_schema($schema);
292 292
 	}
293 293
 
294 294
 	/**
@@ -298,17 +298,17 @@  discard block
 block discarded – undo
298 298
 	 */
299 299
 	public function get_collection_params() {
300 300
 		$params              = array();
301
-		$params['context']   = $this->get_context_param( array( 'default' => 'view' ) );
301
+		$params['context']   = $this->get_context_param(array('default' => 'view'));
302 302
 		$params['page']      = array(
303
-			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
303
+			'description'       => __('Current page of the collection.', 'woocommerce'),
304 304
 			'type'              => 'integer',
305 305
 			'default'           => 1,
306 306
 			'sanitize_callback' => 'absint',
307 307
 			'validate_callback' => 'rest_validate_request_arg',
308 308
 			'minimum'           => 1,
309 309
 		);
310
-		$params['per_page']  = array(
311
-			'description'       => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
310
+		$params['per_page'] = array(
311
+			'description'       => __('Maximum number of items to be returned in result set.', 'woocommerce'),
312 312
 			'type'              => 'integer',
313 313
 			'default'           => 10,
314 314
 			'minimum'           => 1,
@@ -316,27 +316,27 @@  discard block
 block discarded – undo
316 316
 			'sanitize_callback' => 'absint',
317 317
 			'validate_callback' => 'rest_validate_request_arg',
318 318
 		);
319
-		$params['after']     = array(
320
-			'description'       => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
319
+		$params['after'] = array(
320
+			'description'       => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
321 321
 			'type'              => 'string',
322 322
 			'format'            => 'date-time',
323 323
 			'validate_callback' => 'rest_validate_request_arg',
324 324
 		);
325
-		$params['before']    = array(
326
-			'description'       => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
325
+		$params['before'] = array(
326
+			'description'       => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
327 327
 			'type'              => 'string',
328 328
 			'format'            => 'date-time',
329 329
 			'validate_callback' => 'rest_validate_request_arg',
330 330
 		);
331
-		$params['order']     = array(
332
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
331
+		$params['order'] = array(
332
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
333 333
 			'type'              => 'string',
334 334
 			'default'           => 'desc',
335
-			'enum'              => array( 'asc', 'desc' ),
335
+			'enum'              => array('asc', 'desc'),
336 336
 			'validate_callback' => 'rest_validate_request_arg',
337 337
 		);
338
-		$params['orderby']   = array(
339
-			'description'       => __( 'Sort collection by object attribute.', 'woocommerce' ),
338
+		$params['orderby'] = array(
339
+			'description'       => __('Sort collection by object attribute.', 'woocommerce'),
340 340
 			'type'              => 'string',
341 341
 			'default'           => 'date',
342 342
 			'enum'              => array(
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
 			),
349 349
 			'validate_callback' => 'rest_validate_request_arg',
350 350
 		);
351
-		$params['interval']  = array(
352
-			'description'       => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
351
+		$params['interval'] = array(
352
+			'description'       => __('Time interval to use for buckets in the returned data.', 'woocommerce'),
353 353
 			'type'              => 'string',
354 354
 			'default'           => 'week',
355 355
 			'enum'              => array(
@@ -362,8 +362,8 @@  discard block
 block discarded – undo
362 362
 			),
363 363
 			'validate_callback' => 'rest_validate_request_arg',
364 364
 		);
365
-		$params['taxes']     = array(
366
-			'description'       => __( 'Limit result set to all items that have the specified term assigned in the taxes taxonomy.', 'woocommerce' ),
365
+		$params['taxes'] = array(
366
+			'description'       => __('Limit result set to all items that have the specified term assigned in the taxes taxonomy.', 'woocommerce'),
367 367
 			'type'              => 'array',
368 368
 			'sanitize_callback' => 'wp_parse_id_list',
369 369
 			'validate_callback' => 'rest_validate_request_arg',
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 			),
373 373
 		);
374 374
 		$params['segmentby'] = array(
375
-			'description'       => __( 'Segment the response by additional constraint.', 'woocommerce' ),
375
+			'description'       => __('Segment the response by additional constraint.', 'woocommerce'),
376 376
 			'type'              => 'string',
377 377
 			'enum'              => array(
378 378
 				'tax_rate_id',
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports/Stock.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  \WP_REST_Request $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['offset']              = $request['offset'];
37 37
 		$args['order']               = $request['order'];
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 		$args['post_parent__in']     = $request['parent'];
44 44
 		$args['post_parent__not_in'] = $request['parent_exclude'];
45 45
 
46
-		if ( 'date' === $args['orderby'] ) {
46
+		if ('date' === $args['orderby']) {
47 47
 			$args['orderby'] = 'date ID';
48
-		} elseif ( 'stock_status' === $args['orderby'] ) {
48
+		} elseif ('stock_status' === $args['orderby']) {
49 49
 			$args['meta_query'] = array( // WPCS: slow query ok.
50 50
 				'relation'      => 'AND',
51 51
 				'_stock_status' => array(
@@ -58,27 +58,27 @@  discard block
 block discarded – undo
58 58
 					'type'    => 'NUMERIC',
59 59
 				),
60 60
 			);
61
-			$args['orderby']    = array(
61
+			$args['orderby'] = array(
62 62
 				'_stock_status' => $args['order'],
63 63
 				'_stock'        => 'desc' === $args['order'] ? 'asc' : 'desc',
64 64
 			);
65
-		} elseif ( 'stock_quantity' === $args['orderby'] ) {
65
+		} elseif ('stock_quantity' === $args['orderby']) {
66 66
 			$args['meta_key'] = '_stock'; // WPCS: slow query ok.
67 67
 			$args['orderby']  = 'meta_value_num';
68
-		} elseif ( 'include' === $args['orderby'] ) {
68
+		} elseif ('include' === $args['orderby']) {
69 69
 			$args['orderby'] = 'post__in';
70
-		} elseif ( 'id' === $args['orderby'] ) {
70
+		} elseif ('id' === $args['orderby']) {
71 71
 			$args['orderby'] = 'ID'; // ID must be capitalized.
72
-		} elseif ( 'sku' === $args['orderby'] ) {
72
+		} elseif ('sku' === $args['orderby']) {
73 73
 			$args['meta_key'] = '_sku'; // WPCS: slow query ok.
74 74
 			$args['orderby']  = 'meta_value';
75 75
 		}
76 76
 
77
-		$args['post_type'] = array( 'product', 'product_variation' );
77
+		$args['post_type'] = array('product', 'product_variation');
78 78
 
79
-		if ( 'lowstock' === $request['type'] ) {
80
-			$low_stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
81
-			$no_stock  = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
79
+		if ('lowstock' === $request['type']) {
80
+			$low_stock = absint(max(get_option('woocommerce_notify_low_stock_amount'), 1));
81
+			$no_stock  = absint(max(get_option('woocommerce_notify_no_stock_amount'), 0));
82 82
 
83 83
 			$args['meta_query'] = array( // WPCS: slow query ok.
84 84
 				array(
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 				),
88 88
 				array(
89 89
 					'key'     => '_stock',
90
-					'value'   => array( $no_stock, $low_stock ),
90
+					'value'   => array($no_stock, $low_stock),
91 91
 					'compare' => 'BETWEEN',
92 92
 					'type'    => 'NUMERIC',
93 93
 				),
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 					'value' => 'instock',
97 97
 				),
98 98
 			);
99
-		} elseif ( in_array( $request['type'], array_keys( wc_get_product_stock_status_options() ), true ) ) {
99
+		} elseif (in_array($request['type'], array_keys(wc_get_product_stock_status_options()), true)) {
100 100
 			$args['meta_query'] = array( // WPCS: slow query ok.
101 101
 				array(
102 102
 					'key'   => '_stock_status',
@@ -116,23 +116,23 @@  discard block
 block discarded – undo
116 116
 	 * @param  array $query_args Query args.
117 117
 	 * @return array
118 118
 	 */
119
-	protected function get_products( $query_args ) {
119
+	protected function get_products($query_args) {
120 120
 		$query  = new \WP_Query();
121
-		$result = $query->query( $query_args );
121
+		$result = $query->query($query_args);
122 122
 
123 123
 		$total_posts = $query->found_posts;
124
-		if ( $total_posts < 1 ) {
124
+		if ($total_posts < 1) {
125 125
 			// Out-of-bounds, run the query again without LIMIT for total count.
126
-			unset( $query_args['paged'] );
126
+			unset($query_args['paged']);
127 127
 			$count_query = new \WP_Query();
128
-			$count_query->query( $query_args );
128
+			$count_query->query($query_args);
129 129
 			$total_posts = $count_query->found_posts;
130 130
 		}
131 131
 
132 132
 		return array(
133
-			'objects' => array_map( 'wc_get_product', $result ),
133
+			'objects' => array_map('wc_get_product', $result),
134 134
 			'total'   => (int) $total_posts,
135
-			'pages'   => (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ),
135
+			'pages'   => (int) ceil($total_posts / (int) $query->query_vars['posts_per_page']),
136 136
 		);
137 137
 	}
138 138
 
@@ -142,37 +142,37 @@  discard block
 block discarded – undo
142 142
 	 * @param  \WP_REST_Request $request Request data.
143 143
 	 * @return array|\WP_Error
144 144
 	 */
145
-	public function get_items( $request ) {
146
-		$query_args    = $this->prepare_reports_query( $request );
147
-		$query_results = $this->get_products( $query_args );
145
+	public function get_items($request) {
146
+		$query_args    = $this->prepare_reports_query($request);
147
+		$query_results = $this->get_products($query_args);
148 148
 
149 149
 		$objects = array();
150
-		foreach ( $query_results['objects'] as $object ) {
151
-			$data      = $this->prepare_item_for_response( $object, $request );
152
-			$objects[] = $this->prepare_response_for_collection( $data );
150
+		foreach ($query_results['objects'] as $object) {
151
+			$data      = $this->prepare_item_for_response($object, $request);
152
+			$objects[] = $this->prepare_response_for_collection($data);
153 153
 		}
154 154
 
155 155
 		$page      = (int) $query_args['paged'];
156 156
 		$max_pages = $query_results['pages'];
157 157
 
158
-		$response = rest_ensure_response( $objects );
159
-		$response->header( 'X-WP-Total', $query_results['total'] );
160
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
158
+		$response = rest_ensure_response($objects);
159
+		$response->header('X-WP-Total', $query_results['total']);
160
+		$response->header('X-WP-TotalPages', (int) $max_pages);
161 161
 
162
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
162
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
163 163
 
164
-		if ( $page > 1 ) {
164
+		if ($page > 1) {
165 165
 			$prev_page = $page - 1;
166
-			if ( $prev_page > $max_pages ) {
166
+			if ($prev_page > $max_pages) {
167 167
 				$prev_page = $max_pages;
168 168
 			}
169
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
170
-			$response->link_header( 'prev', $prev_link );
169
+			$prev_link = add_query_arg('page', $prev_page, $base);
170
+			$response->link_header('prev', $prev_link);
171 171
 		}
172
-		if ( $max_pages > $page ) {
172
+		if ($max_pages > $page) {
173 173
 			$next_page = $page + 1;
174
-			$next_link = add_query_arg( 'page', $next_page, $base );
175
-			$response->link_header( 'next', $next_link );
174
+			$next_link = add_query_arg('page', $next_page, $base);
175
+			$response->link_header('next', $next_link);
176 176
 		}
177 177
 
178 178
 		return $response;
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * @param  \WP_REST_Request $request Request object.
186 186
 	 * @return \WP_REST_Response
187 187
 	 */
188
-	public function prepare_item_for_response( $product, $request ) {
188
+	public function prepare_item_for_response($product, $request) {
189 189
 		$data = array(
190 190
 			'id'             => $product->get_id(),
191 191
 			'parent_id'      => $product->get_parent_id(),
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
 			'manage_stock'   => $product->get_manage_stock(),
197 197
 		);
198 198
 
199
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
200
-		$data    = $this->add_additional_fields_to_object( $data, $request );
201
-		$data    = $this->filter_response_by_context( $data, $context );
199
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
200
+		$data    = $this->add_additional_fields_to_object($data, $request);
201
+		$data    = $this->filter_response_by_context($data, $context);
202 202
 
203 203
 		// Wrap the data in a response object.
204
-		$response = rest_ensure_response( $data );
205
-		$response->add_links( $this->prepare_links( $product ) );
204
+		$response = rest_ensure_response($data);
205
+		$response->add_links($this->prepare_links($product));
206 206
 
207 207
 		/**
208 208
 		 * Filter a report returned from the API.
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 		 * @param WC_Product       $product   The original product object.
214 214
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
215 215
 		 */
216
-		return apply_filters( 'woocommerce_rest_prepare_report_stock', $response, $product, $request );
216
+		return apply_filters('woocommerce_rest_prepare_report_stock', $response, $product, $request);
217 217
 	}
218 218
 
219 219
 	/**
@@ -222,29 +222,29 @@  discard block
 block discarded – undo
222 222
 	 * @param  WC_Product $product Object data.
223 223
 	 * @return array
224 224
 	 */
225
-	protected function prepare_links( $product ) {
226
-		if ( $product->is_type( 'variation' ) ) {
225
+	protected function prepare_links($product) {
226
+		if ($product->is_type('variation')) {
227 227
 			$links = array(
228 228
 				'product' => array(
229
-					'href' => rest_url( sprintf( '/%s/products/%d/variations/%d', $this->namespace, $product->get_parent_id(), $product->get_id() ) ),
229
+					'href' => rest_url(sprintf('/%s/products/%d/variations/%d', $this->namespace, $product->get_parent_id(), $product->get_id())),
230 230
 				),
231 231
 				'parent'  => array(
232
-					'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_parent_id() ) ),
232
+					'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product->get_parent_id())),
233 233
 				),
234 234
 			);
235
-		} elseif ( $product->get_parent_id() ) {
235
+		} elseif ($product->get_parent_id()) {
236 236
 			$links = array(
237 237
 				'product' => array(
238
-					'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_id() ) ),
238
+					'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product->get_id())),
239 239
 				),
240 240
 				'parent'  => array(
241
-					'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_parent_id() ) ),
241
+					'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product->get_parent_id())),
242 242
 				),
243 243
 			);
244 244
 		} else {
245 245
 			$links = array(
246 246
 				'product' => array(
247
-					'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_id() ) ),
247
+					'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product->get_id())),
248 248
 				),
249 249
 			);
250 250
 		}
@@ -264,52 +264,52 @@  discard block
 block discarded – undo
264 264
 			'type'       => 'object',
265 265
 			'properties' => array(
266 266
 				'id'             => array(
267
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
267
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
268 268
 					'type'        => 'integer',
269
-					'context'     => array( 'view', 'edit' ),
269
+					'context'     => array('view', 'edit'),
270 270
 					'readonly'    => true,
271 271
 				),
272 272
 				'parent_id'      => array(
273
-					'description' => __( 'Product parent ID.', 'woocommerce' ),
273
+					'description' => __('Product parent ID.', 'woocommerce'),
274 274
 					'type'        => 'integer',
275
-					'context'     => array( 'view', 'edit' ),
275
+					'context'     => array('view', 'edit'),
276 276
 					'readonly'    => true,
277 277
 				),
278 278
 				'name'           => array(
279
-					'description' => __( 'Product name.', 'woocommerce' ),
279
+					'description' => __('Product name.', 'woocommerce'),
280 280
 					'type'        => 'string',
281
-					'context'     => array( 'view', 'edit' ),
281
+					'context'     => array('view', 'edit'),
282 282
 					'readonly'    => true,
283 283
 				),
284 284
 				'sku'            => array(
285
-					'description' => __( 'Unique identifier.', 'woocommerce' ),
285
+					'description' => __('Unique identifier.', 'woocommerce'),
286 286
 					'type'        => 'string',
287
-					'context'     => array( 'view', 'edit' ),
287
+					'context'     => array('view', 'edit'),
288 288
 					'readonly'    => true,
289 289
 				),
290 290
 				'stock_status'   => array(
291
-					'description' => __( 'Stock status.', 'woocommerce' ),
291
+					'description' => __('Stock status.', 'woocommerce'),
292 292
 					'type'        => 'string',
293
-					'enum'        => array_keys( wc_get_product_stock_status_options() ),
294
-					'context'     => array( 'view', 'edit' ),
293
+					'enum'        => array_keys(wc_get_product_stock_status_options()),
294
+					'context'     => array('view', 'edit'),
295 295
 					'readonly'    => true,
296 296
 				),
297 297
 				'stock_quantity' => array(
298
-					'description' => __( 'Stock quantity.', 'woocommerce' ),
298
+					'description' => __('Stock quantity.', 'woocommerce'),
299 299
 					'type'        => 'integer',
300
-					'context'     => array( 'view', 'edit' ),
300
+					'context'     => array('view', 'edit'),
301 301
 					'readonly'    => true,
302 302
 				),
303 303
 				'manage_stock'   => array(
304
-					'description' => __( 'Manage stock.', 'woocommerce' ),
304
+					'description' => __('Manage stock.', 'woocommerce'),
305 305
 					'type'        => 'boolean',
306
-					'context'     => array( 'view', 'edit' ),
306
+					'context'     => array('view', 'edit'),
307 307
 					'readonly'    => true,
308 308
 				),
309 309
 			),
310 310
 		);
311 311
 
312
-		return $this->add_additional_fields_schema( $schema );
312
+		return $this->add_additional_fields_schema($schema);
313 313
 	}
314 314
 
315 315
 	/**
@@ -319,17 +319,17 @@  discard block
 block discarded – undo
319 319
 	 */
320 320
 	public function get_collection_params() {
321 321
 		$params                   = array();
322
-		$params['context']        = $this->get_context_param( array( 'default' => 'view' ) );
322
+		$params['context']        = $this->get_context_param(array('default' => 'view'));
323 323
 		$params['page']           = array(
324
-			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
324
+			'description'       => __('Current page of the collection.', 'woocommerce'),
325 325
 			'type'              => 'integer',
326 326
 			'default'           => 1,
327 327
 			'sanitize_callback' => 'absint',
328 328
 			'validate_callback' => 'rest_validate_request_arg',
329 329
 			'minimum'           => 1,
330 330
 		);
331
-		$params['per_page']       = array(
332
-			'description'       => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
331
+		$params['per_page'] = array(
332
+			'description'       => __('Maximum number of items to be returned in result set.', 'woocommerce'),
333 333
 			'type'              => 'integer',
334 334
 			'default'           => 10,
335 335
 			'minimum'           => 1,
@@ -337,8 +337,8 @@  discard block
 block discarded – undo
337 337
 			'sanitize_callback' => 'absint',
338 338
 			'validate_callback' => 'rest_validate_request_arg',
339 339
 		);
340
-		$params['exclude']        = array(
341
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
340
+		$params['exclude'] = array(
341
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
342 342
 			'type'              => 'array',
343 343
 			'items'             => array(
344 344
 				'type' => 'integer',
@@ -346,8 +346,8 @@  discard block
 block discarded – undo
346 346
 			'default'           => array(),
347 347
 			'sanitize_callback' => 'wp_parse_id_list',
348 348
 		);
349
-		$params['include']        = array(
350
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
349
+		$params['include'] = array(
350
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
351 351
 			'type'              => 'array',
352 352
 			'items'             => array(
353 353
 				'type' => 'integer',
@@ -355,21 +355,21 @@  discard block
 block discarded – undo
355 355
 			'default'           => array(),
356 356
 			'sanitize_callback' => 'wp_parse_id_list',
357 357
 		);
358
-		$params['offset']         = array(
359
-			'description'       => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
358
+		$params['offset'] = array(
359
+			'description'       => __('Offset the result set by a specific number of items.', 'woocommerce'),
360 360
 			'type'              => 'integer',
361 361
 			'sanitize_callback' => 'absint',
362 362
 			'validate_callback' => 'rest_validate_request_arg',
363 363
 		);
364
-		$params['order']          = array(
365
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
364
+		$params['order'] = array(
365
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
366 366
 			'type'              => 'string',
367 367
 			'default'           => 'asc',
368
-			'enum'              => array( 'asc', 'desc' ),
368
+			'enum'              => array('asc', 'desc'),
369 369
 			'validate_callback' => 'rest_validate_request_arg',
370 370
 		);
371
-		$params['orderby']        = array(
372
-			'description'       => __( 'Sort collection by object attribute.', 'woocommerce' ),
371
+		$params['orderby'] = array(
372
+			'description'       => __('Sort collection by object attribute.', 'woocommerce'),
373 373
 			'type'              => 'string',
374 374
 			'default'           => 'stock_status',
375 375
 			'enum'              => array(
@@ -383,8 +383,8 @@  discard block
 block discarded – undo
383 383
 			),
384 384
 			'validate_callback' => 'rest_validate_request_arg',
385 385
 		);
386
-		$params['parent']         = array(
387
-			'description'       => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
386
+		$params['parent'] = array(
387
+			'description'       => __('Limit result set to those of particular parent IDs.', 'woocommerce'),
388 388
 			'type'              => 'array',
389 389
 			'items'             => array(
390 390
 				'type' => 'integer',
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 			'default'           => array(),
394 394
 		);
395 395
 		$params['parent_exclude'] = array(
396
-			'description'       => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
396
+			'description'       => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'),
397 397
 			'type'              => 'array',
398 398
 			'items'             => array(
399 399
 				'type' => 'integer',
@@ -401,11 +401,11 @@  discard block
 block discarded – undo
401 401
 			'sanitize_callback' => 'wp_parse_id_list',
402 402
 			'default'           => array(),
403 403
 		);
404
-		$params['type']           = array(
405
-			'description' => __( 'Limit result set to items assigned a stock report type.', 'woocommerce' ),
404
+		$params['type'] = array(
405
+			'description' => __('Limit result set to items assigned a stock report type.', 'woocommerce'),
406 406
 			'type'        => 'string',
407 407
 			'default'     => 'all',
408
-			'enum'        => array_merge( array( 'all', 'lowstock' ), array_keys( wc_get_product_stock_status_options() ) ),
408
+			'enum'        => array_merge(array('all', 'lowstock'), array_keys(wc_get_product_stock_status_options())),
409 409
 		);
410 410
 
411 411
 		return $params;
Please login to merge, or discard this patch.