Passed
Push — master ( a518b9...854ac9 )
by Mike
03:28
created
src/Controllers/Version4/Data/Currencies.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		foreach ( array_keys( $currencies ) as $code ) {
109 109
 			$currency = $this->get_currency( $code, $request );
110 110
 			$response = $this->prepare_item_for_response( $currency, $request );
111
-			$data[]   = $this->prepare_response_for_collection( $response );
111
+			$data[ ]   = $this->prepare_response_for_collection( $response );
112 112
 		}
113 113
 
114 114
 		return rest_ensure_response( $data );
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @return \WP_Error|\WP_REST_Response
122 122
 	 */
123 123
 	public function get_item( $request ) {
124
-		$data = $this->get_currency( strtoupper( $request['currency'] ), $request );
124
+		$data = $this->get_currency( strtoupper( $request[ 'currency' ] ), $request );
125 125
 		if ( empty( $data ) ) {
126 126
 			return new \WP_Error( 'woocommerce_rest_data_invalid_currency', __( 'There are no currencies matching these parameters.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
127 127
 		}
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 * @return array
159 159
 	 */
160 160
 	protected function prepare_links( $item, $request ) {
161
-		$code  = strtoupper( $item['code'] );
161
+		$code  = strtoupper( $item[ 'code' ] );
162 162
 		$links = array(
163 163
 			'self'       => array(
164 164
 				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $code ) ),
Please login to merge, or discard this patch.
src/Controllers/Version4/Data/Continents.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 
87 87
 		$continent = array(
88 88
 			'code' => $continent_code,
89
-			'name' => $continent_list['name'],
89
+			'name' => $continent_list[ 'name' ],
90 90
 		);
91 91
 
92 92
 		$local_countries = array();
93
-		foreach ( $continent_list['countries'] as $country_code ) {
93
+		foreach ( $continent_list[ 'countries' ] as $country_code ) {
94 94
 			if ( isset( $countries[ $country_code ] ) ) {
95 95
 				$country = array(
96 96
 					'code' => $country_code,
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 				$local_states = array();
120 120
 				if ( isset( $states[ $country_code ] ) ) {
121 121
 					foreach ( $states[ $country_code ] as $state_code => $state_name ) {
122
-						$local_states[] = array(
122
+						$local_states[ ] = array(
123 123
 							'code' => $state_code,
124 124
 							'name' => $state_name,
125 125
 						);
126 126
 					}
127 127
 				}
128
-				$country['states'] = $local_states;
128
+				$country[ 'states' ] = $local_states;
129 129
 
130 130
 				// Allow only desired keys (e.g. filter out tax rates).
131 131
 				$allowed = array(
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 				);
143 143
 				$country = array_intersect_key( $country, array_flip( $allowed ) );
144 144
 
145
-				$local_countries[] = $country;
145
+				$local_countries[ ] = $country;
146 146
 			}
147 147
 		}
148 148
 
149
-		$continent['countries'] = $local_countries;
149
+		$continent[ 'countries' ] = $local_countries;
150 150
 		return $continent;
151 151
 	}
152 152
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 		foreach ( array_keys( $continents ) as $continent_code ) {
165 165
 			$continent = $this->get_continent( $continent_code, $request );
166 166
 			$response  = $this->prepare_item_for_response( $continent, $request );
167
-			$data[]    = $this->prepare_response_for_collection( $response );
167
+			$data[ ]    = $this->prepare_response_for_collection( $response );
168 168
 		}
169 169
 
170 170
 		return rest_ensure_response( $data );
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @return \WP_Error|\WP_REST_Response
179 179
 	 */
180 180
 	public function get_item( $request ) {
181
-		$data = $this->get_continent( strtoupper( $request['location'] ), $request );
181
+		$data = $this->get_continent( strtoupper( $request[ 'location' ] ), $request );
182 182
 		if ( empty( $data ) ) {
183 183
 			return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
184 184
 		}
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * @return array
205 205
 	 */
206 206
 	protected function prepare_links( $item, $request ) {
207
-		$continent_code = strtolower( $item['code'] );
207
+		$continent_code = strtolower( $item[ 'code' ] );
208 208
 		$links          = array(
209 209
 			'self'       => array(
210 210
 				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code ) ),
Please login to merge, or discard this patch.
src/Controllers/Version4/Data/Countries.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
 		$local_states = array();
88 88
 		if ( isset( $states[ $country_code ] ) ) {
89 89
 			foreach ( $states[ $country_code ] as $state_code => $state_name ) {
90
-				$local_states[] = array(
90
+				$local_states[ ] = array(
91 91
 					'code' => $state_code,
92 92
 					'name' => $state_name,
93 93
 				);
94 94
 			}
95 95
 		}
96
-		$country['states'] = $local_states;
96
+		$country[ 'states' ] = $local_states;
97 97
 		return $country;
98 98
 	}
99 99
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		foreach ( array_keys( $countries ) as $country_code ) {
112 112
 			$country  = $this->get_country( $country_code, $request );
113 113
 			$response = $this->prepare_item_for_response( $country, $request );
114
-			$data[]   = $this->prepare_response_for_collection( $response );
114
+			$data[ ]   = $this->prepare_response_for_collection( $response );
115 115
 		}
116 116
 
117 117
 		return rest_ensure_response( $data );
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 * @return \WP_Error|\WP_REST_Response
126 126
 	 */
127 127
 	public function get_item( $request ) {
128
-		$data = $this->get_country( strtoupper( $request['location'] ), $request );
128
+		$data = $this->get_country( strtoupper( $request[ 'location' ] ), $request );
129 129
 		if ( empty( $data ) ) {
130 130
 			return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
131 131
 		}
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * @return array
152 152
 	 */
153 153
 	protected function prepare_links( $item, $request ) {
154
-		$country_code = strtolower( $item['code'] );
154
+		$country_code = strtolower( $item[ 'code' ] );
155 155
 		$links        = array(
156 156
 			'self'       => array(
157 157
 				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $country_code ) ),
Please login to merge, or discard this patch.
src/Controllers/Version4/SettingsOptions.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @return \WP_Error|\WP_REST_Response
120 120
 	 */
121 121
 	public function get_item( $request ) {
122
-		$setting = $this->get_setting( $request['group_id'], $request['id'] );
122
+		$setting = $this->get_setting( $request[ 'group_id' ], $request[ 'id' ] );
123 123
 
124 124
 		if ( is_wp_error( $setting ) ) {
125 125
 			return $setting;
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 * @return \WP_Error|\WP_REST_Response
139 139
 	 */
140 140
 	public function get_items( $request ) {
141
-		$settings = $this->get_group_settings( $request['group_id'] );
141
+		$settings = $this->get_group_settings( $request[ 'group_id' ] );
142 142
 
143 143
 		if ( is_wp_error( $settings ) ) {
144 144
 			return $settings;
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
 		foreach ( $settings as $setting_obj ) {
150 150
 			$setting = $this->prepare_item_for_response( $setting_obj, $request );
151 151
 			$setting = $this->prepare_response_for_collection( $setting );
152
-			if ( $this->is_setting_type_valid( $setting['type'] ) ) {
153
-				$data[] = $setting;
152
+			if ( $this->is_setting_type_valid( $setting[ 'type' ] ) ) {
153
+				$data[ ] = $setting;
154 154
 			}
155 155
 		}
156 156
 
@@ -176,26 +176,26 @@  discard block
 block discarded – undo
176 176
 
177 177
 		$filtered_settings = array();
178 178
 		foreach ( $settings as $setting ) {
179
-			$option_key = $setting['option_key'];
179
+			$option_key = $setting[ 'option_key' ];
180 180
 			$setting    = $this->filter_setting( $setting );
181
-			$default    = isset( $setting['default'] ) ? $setting['default'] : '';
181
+			$default    = isset( $setting[ 'default' ] ) ? $setting[ 'default' ] : '';
182 182
 			// Get the option value.
183 183
 			if ( is_array( $option_key ) ) {
184
-				$option           = get_option( $option_key[0] );
185
-				$setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default;
184
+				$option           = get_option( $option_key[ 0 ] );
185
+				$setting[ 'value' ] = isset( $option[ $option_key[ 1 ] ] ) ? $option[ $option_key[ 1 ] ] : $default;
186 186
 			} else {
187 187
 				$admin_setting_value = \WC_Admin_Settings::get_option( $option_key, $default );
188
-				$setting['value']    = $admin_setting_value;
188
+				$setting[ 'value' ]    = $admin_setting_value;
189 189
 			}
190 190
 
191
-			if ( 'multi_select_countries' === $setting['type'] ) {
192
-				$setting['options'] = WC()->countries->get_countries();
193
-				$setting['type']    = 'multiselect';
194
-			} elseif ( 'single_select_country' === $setting['type'] ) {
195
-				$setting['type']    = 'select';
196
-				$setting['options'] = $this->get_countries_and_states();
197
-			} elseif ( 'single_select_page' === $setting['type'] ) {
198
-				$pages   = get_pages(
191
+			if ( 'multi_select_countries' === $setting[ 'type' ] ) {
192
+				$setting[ 'options' ] = WC()->countries->get_countries();
193
+				$setting[ 'type' ]    = 'multiselect';
194
+			} elseif ( 'single_select_country' === $setting[ 'type' ] ) {
195
+				$setting[ 'type' ]    = 'select';
196
+				$setting[ 'options' ] = $this->get_countries_and_states();
197
+			} elseif ( 'single_select_page' === $setting[ 'type' ] ) {
198
+				$pages = get_pages(
199 199
 					array(
200 200
 						'sort_column'  => 'menu_order',
201 201
 						'sort_order'   => 'ASC',
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
 				foreach ( $pages as $page ) {
207 207
 					$options[ $page->ID ] = ! empty( $page->post_title ) ? $page->post_title : '#' . $page->ID;
208 208
 				}
209
-				$setting['type']    = 'select';
210
-				$setting['options'] = $options;
209
+				$setting[ 'type' ]    = 'select';
210
+				$setting[ 'options' ] = $options;
211 211
 			}
212 212
 
213
-			$filtered_settings[] = $setting;
213
+			$filtered_settings[ ] = $setting;
214 214
 		}
215 215
 
216 216
 		return $filtered_settings;
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 			return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
268 268
 		}
269 269
 
270
-		$setting = $settings[ $array_key[0] ];
270
+		$setting = $settings[ $array_key[ 0 ] ];
271 271
 
272
-		if ( ! $this->is_setting_type_valid( $setting['type'] ) ) {
272
+		if ( ! $this->is_setting_type_valid( $setting[ 'type' ] ) ) {
273 273
 			return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
274 274
 		}
275 275
 
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 			return $setting;
278 278
 		}
279 279
 
280
-		$setting['group_id'] = $group_id;
280
+		$setting[ 'group_id' ] = $group_id;
281 281
 
282 282
 		return $setting;
283 283
 	}
@@ -319,32 +319,32 @@  discard block
 block discarded – undo
319 319
 	 * @return \WP_Error|\WP_REST_Response
320 320
 	 */
321 321
 	public function update_item( $request ) {
322
-		$setting = $this->get_setting( $request['group_id'], $request['id'] );
322
+		$setting = $this->get_setting( $request[ 'group_id' ], $request[ 'id' ] );
323 323
 
324 324
 		if ( is_wp_error( $setting ) ) {
325 325
 			return $setting;
326 326
 		}
327 327
 
328
-		if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) {
329
-			$value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting );
328
+		if ( is_callable( array( $this, 'validate_setting_' . $setting[ 'type' ] . '_field' ) ) ) {
329
+			$value = $this->{'validate_setting_' . $setting[ 'type' ] . '_field'}( $request[ 'value' ], $setting );
330 330
 		} else {
331
-			$value = $this->validate_setting_text_field( $request['value'], $setting );
331
+			$value = $this->validate_setting_text_field( $request[ 'value' ], $setting );
332 332
 		}
333 333
 
334 334
 		if ( is_wp_error( $value ) ) {
335 335
 			return $value;
336 336
 		}
337 337
 
338
-		if ( is_array( $setting['option_key'] ) ) {
339
-			$setting['value']       = $value;
340
-			$option_key             = $setting['option_key'];
341
-			$prev                   = get_option( $option_key[0] );
342
-			$prev[ $option_key[1] ] = $request['value'];
343
-			update_option( $option_key[0], $prev );
338
+		if ( is_array( $setting[ 'option_key' ] ) ) {
339
+			$setting[ 'value' ]       = $value;
340
+			$option_key             = $setting[ 'option_key' ];
341
+			$prev                   = get_option( $option_key[ 0 ] );
342
+			$prev[ $option_key[ 1 ] ] = $request[ 'value' ];
343
+			update_option( $option_key[ 0 ], $prev );
344 344
 		} else {
345 345
 			$update_data                           = array();
346
-			$update_data[ $setting['option_key'] ] = $value;
347
-			$setting['value']                      = $value;
346
+			$update_data[ $setting[ 'option_key' ] ] = $value;
347
+			$setting[ 'value' ]                      = $value;
348 348
 			\WC_Admin_Settings::save_fields( array( $setting ), $update_data );
349 349
 		}
350 350
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 	 * @return array Array of data in the correct format.
362 362
 	 */
363 363
 	protected function get_data_for_response( $object, $request ) {
364
-		unset( $object['option_key'] );
364
+		unset( $object[ 'option_key' ] );
365 365
 		return $this->filter_setting( $object );
366 366
 	}
367 367
 
@@ -373,10 +373,10 @@  discard block
 block discarded – undo
373 373
 	 * @return array
374 374
 	 */
375 375
 	protected function prepare_links( $item, $request ) {
376
-		$base  = str_replace( '(?P<group_id>[\w-]+)', $request['group_id'], $this->rest_base );
376
+		$base  = str_replace( '(?P<group_id>[\w-]+)', $request[ 'group_id' ], $this->rest_base );
377 377
 		$links = array(
378 378
 			'self'       => array(
379
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $item['id'] ) ),
379
+				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $item[ 'id' ] ) ),
380 380
 			),
381 381
 			'collection' => array(
382 382
 				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 			array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) )
401 401
 		);
402 402
 
403
-		if ( empty( $setting['options'] ) ) {
404
-			unset( $setting['options'] );
403
+		if ( empty( $setting[ 'options' ] ) ) {
404
+			unset( $setting[ 'options' ] );
405 405
 		}
406 406
 
407
-		if ( 'image_width' === $setting['type'] ) {
407
+		if ( 'image_width' === $setting[ 'type' ] ) {
408 408
 			$setting = $this->cast_image_width( $setting );
409 409
 		}
410 410
 
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
 	public function cast_image_width( $setting ) {
424 424
 		foreach ( array( 'default', 'value' ) as $key ) {
425 425
 			if ( isset( $setting[ $key ] ) ) {
426
-				$setting[ $key ]['width']  = intval( $setting[ $key ]['width'] );
427
-				$setting[ $key ]['height'] = intval( $setting[ $key ]['height'] );
428
-				$setting[ $key ]['crop']   = (bool) $setting[ $key ]['crop'];
426
+				$setting[ $key ][ 'width' ]  = intval( $setting[ $key ][ 'width' ] );
427
+				$setting[ $key ][ 'height' ] = intval( $setting[ $key ][ 'height' ] );
428
+				$setting[ $key ][ 'crop' ]   = (bool) $setting[ $key ][ 'crop' ];
429 429
 			}
430 430
 		}
431 431
 		return $setting;
@@ -465,17 +465,17 @@  discard block
 block discarded – undo
465 465
 	public function is_setting_type_valid( $type ) {
466 466
 		return in_array(
467 467
 			$type, array(
468
-				'text',         // Validates with validate_setting_text_field.
469
-				'email',        // Validates with validate_setting_text_field.
470
-				'number',       // Validates with validate_setting_text_field.
471
-				'color',        // Validates with validate_setting_text_field.
472
-				'password',     // Validates with validate_setting_text_field.
473
-				'textarea',     // Validates with validate_setting_textarea_field.
474
-				'select',       // Validates with validate_setting_select_field.
475
-				'multiselect',  // Validates with validate_setting_multiselect_field.
476
-				'radio',        // Validates with validate_setting_radio_field (-> validate_setting_select_field).
477
-				'checkbox',     // Validates with validate_setting_checkbox_field.
478
-				'image_width',  // Validates with validate_setting_image_width_field.
468
+				'text', // Validates with validate_setting_text_field.
469
+				'email', // Validates with validate_setting_text_field.
470
+				'number', // Validates with validate_setting_text_field.
471
+				'color', // Validates with validate_setting_text_field.
472
+				'password', // Validates with validate_setting_text_field.
473
+				'textarea', // Validates with validate_setting_textarea_field.
474
+				'select', // Validates with validate_setting_select_field.
475
+				'multiselect', // Validates with validate_setting_multiselect_field.
476
+				'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field).
477
+				'checkbox', // Validates with validate_setting_checkbox_field.
478
+				'image_width', // Validates with validate_setting_image_width_field.
479 479
 				'thumbnail_cropping', // Validates with validate_setting_text_field.
480 480
 			)
481 481
 		);
Please login to merge, or discard this patch.
src/Controllers/Version4/AbstractController.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 	 * @param array $methods Supported methods. read, create.
56 56
 	 */
57 57
 	protected function register_items_route( $methods = [ 'read', 'create' ] ) {
58
-		$routes           = [];
59
-		$routes['schema'] = [ $this, 'get_public_item_schema' ];
58
+		$routes           = [ ];
59
+		$routes[ 'schema' ] = [ $this, 'get_public_item_schema' ];
60 60
 
61 61
 		if ( in_array( 'read', $methods, true ) ) {
62
-			$routes[] = array(
62
+			$routes[ ] = array(
63 63
 				'methods'             => \WP_REST_Server::READABLE,
64 64
 				'callback'            => array( $this, 'get_items' ),
65 65
 				'permission_callback' => array( $this, 'get_items_permissions_check' ),
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		}
69 69
 
70 70
 		if ( in_array( 'create', $methods, true ) ) {
71
-			$routes[] = array(
71
+			$routes[ ] = array(
72 72
 				'methods'             => \WP_REST_Server::CREATABLE,
73 73
 				'callback'            => array( $this, 'create_item' ),
74 74
 				'permission_callback' => array( $this, 'create_item_permissions_check' ),
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 	 * @param array $methods Supported methods. read, create.
91 91
 	 */
92 92
 	protected function register_item_route( $methods = [ 'read', 'edit', 'delete' ] ) {
93
-		$routes           = [];
94
-		$routes['schema'] = [ $this, 'get_public_item_schema' ];
95
-		$routes['args']   = [
93
+		$routes           = [ ];
94
+		$routes[ 'schema' ] = [ $this, 'get_public_item_schema' ];
95
+		$routes[ 'args' ]   = [
96 96
 			'id' => [
97 97
 				'description' => __( 'Unique identifier for the resource.', 'woocommerce-rest-api' ),
98 98
 				'type'        => 'integer',
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		];
101 101
 
102 102
 		if ( in_array( 'read', $methods, true ) ) {
103
-			$routes[] = array(
103
+			$routes[ ] = array(
104 104
 				'methods'             => \WP_REST_Server::READABLE,
105 105
 				'callback'            => array( $this, 'get_item' ),
106 106
 				'permission_callback' => array( $this, 'get_item_permissions_check' ),
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 		}
116 116
 
117 117
 		if ( in_array( 'edit', $methods, true ) ) {
118
-			$routes[] = array(
118
+			$routes[ ] = array(
119 119
 				'methods'             => \WP_REST_Server::EDITABLE,
120 120
 				'callback'            => array( $this, 'update_item' ),
121 121
 				'permission_callback' => array( $this, 'update_item_permissions_check' ),
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		}
125 125
 
126 126
 		if ( in_array( 'delete', $methods, true ) ) {
127
-			$routes[] = array(
127
+			$routes[ ] = array(
128 128
 				'methods'             => \WP_REST_Server::DELETABLE,
129 129
 				'callback'            => array( $this, 'delete_item' ),
130 130
 				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
 	 */
155 155
 	protected function add_additional_fields_schema( $schema ) {
156 156
 		$schema               = parent::add_additional_fields_schema( $schema );
157
-		$object_type          = $schema['title'];
158
-		$schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] );
157
+		$object_type          = $schema[ 'title' ];
158
+		$schema[ 'properties' ] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema[ 'properties' ] );
159 159
 		return $schema;
160 160
 	}
161 161
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	 * @return string
272 272
 	 */
273 273
 	protected function get_request_context( $request ) {
274
-		return ! empty( $request['context'] ) ? $request['context'] : 'view';
274
+		return ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view';
275 275
 	}
276 276
 
277 277
 	/**
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	 */
313 313
 	protected function get_item_title() {
314 314
 		$schema = $this->get_item_schema();
315
-		return $schema['title'];
315
+		return $schema[ 'title' ];
316 316
 	}
317 317
 
318 318
 	/**
Please login to merge, or discard this patch.
src/Controllers/Version4/Requests/OrderRequest.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		];
52 52
 
53 53
 		$request_props = array_intersect_key( $this->request, array_flip( $props ) );
54
-		$prop_values   = [];
54
+		$prop_values   = [ ];
55 55
 
56 56
 		foreach ( $request_props as $prop => $value ) {
57 57
 			switch ( $prop ) {
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 				if ( ! is_array( $item ) ) {
96 96
 					continue;
97 97
 				}
98
-				if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
99
-					$object->remove_item( $item['id'] );
98
+				if ( $this->item_is_null( $item ) || ( isset( $item[ 'quantity' ] ) && 0 === $item[ 'quantity' ] ) ) {
99
+					$object->remove_item( $item[ 'id' ] );
100 100
 				} else {
101 101
 					$this->set_item( $object, $type, $item );
102 102
 				}
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
 	 * @param array          $posted Request data.
157 157
 	 */
158 158
 	protected function maybe_set_item_meta_data( $item, $posted ) {
159
-		if ( ! empty( $posted['meta_data'] ) && is_array( $posted['meta_data'] ) ) {
160
-			foreach ( $posted['meta_data'] as $meta ) {
161
-				if ( isset( $meta['key'] ) ) {
162
-					$value = isset( $meta['value'] ) ? $meta['value'] : null;
163
-					$item->update_meta_data( $meta['key'], $value, isset( $meta['id'] ) ? $meta['id'] : '' );
159
+		if ( ! empty( $posted[ 'meta_data' ] ) && is_array( $posted[ 'meta_data' ] ) ) {
160
+			foreach ( $posted[ 'meta_data' ] as $meta ) {
161
+				if ( isset( $meta[ 'key' ] ) ) {
162
+					$value = isset( $meta[ 'value' ] ) ? $meta[ 'value' ] : null;
163
+					$item->update_meta_data( $meta[ 'key' ], $value, isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' );
164 164
 				}
165 165
 			}
166 166
 		}
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 	 * @throws \WC_REST_Exception When SKU or ID is not valid.
175 175
 	 */
176 176
 	protected function get_product_id_from_line_item( $posted ) {
177
-		if ( ! empty( $posted['sku'] ) ) {
178
-			$product_id = (int) wc_get_product_id_by_sku( $posted['sku'] );
179
-		} elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) {
180
-			$product_id = (int) $posted['product_id'];
181
-		} elseif ( ! empty( $posted['variation_id'] ) ) {
182
-			$product_id = (int) $posted['variation_id'];
177
+		if ( ! empty( $posted[ 'sku' ] ) ) {
178
+			$product_id = (int) wc_get_product_id_by_sku( $posted[ 'sku' ] );
179
+		} elseif ( ! empty( $posted[ 'product_id' ] ) && empty( $posted[ 'variation_id' ] ) ) {
180
+			$product_id = (int) $posted[ 'product_id' ];
181
+		} elseif ( ! empty( $posted[ 'variation_id' ] ) ) {
182
+			$product_id = (int) $posted[ 'variation_id' ];
183 183
 		} else {
184 184
 			throw new \WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce-rest-api' ), 400 );
185 185
 		}
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
 	 * @throws \WC_REST_Exception Invalid data, server error.
197 197
 	 */
198 198
 	protected function prepare_line_items( $posted, $action = 'create', $item = null ) {
199
-		$item    = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
199
+		$item    = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item;
200 200
 		$product = wc_get_product( $this->get_product_id_from_line_item( $posted ) );
201 201
 
202 202
 		if ( $product !== $item->get_product() ) {
203 203
 			$item->set_product( $product );
204 204
 
205 205
 			if ( 'create' === $action ) {
206
-				$quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1;
206
+				$quantity = isset( $posted[ 'quantity' ] ) ? $posted[ 'quantity' ] : 1;
207 207
 				$total    = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) );
208 208
 				$item->set_total( $total );
209 209
 				$item->set_subtotal( $total );
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
 	 * @throws \WC_REST_Exception Invalid data, server error.
227 227
 	 */
228 228
 	protected function prepare_shipping_lines( $posted, $action = 'create', $item = null ) {
229
-		$item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
229
+		$item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item;
230 230
 
231 231
 		if ( 'create' === $action ) {
232
-			if ( empty( $posted['method_id'] ) ) {
232
+			if ( empty( $posted[ 'method_id' ] ) ) {
233 233
 				throw new \WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce-rest-api' ), 400 );
234 234
 			}
235 235
 		}
@@ -250,10 +250,10 @@  discard block
 block discarded – undo
250 250
 	 * @throws \WC_REST_Exception Invalid data, server error.
251 251
 	 */
252 252
 	protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) {
253
-		$item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
253
+		$item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item;
254 254
 
255 255
 		if ( 'create' === $action ) {
256
-			if ( empty( $posted['name'] ) ) {
256
+			if ( empty( $posted[ 'name' ] ) ) {
257 257
 				throw new \WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce-rest-api' ), 400 );
258 258
 			}
259 259
 		}
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 * @throws \WC_REST_Exception If item ID is not associated with order.
276 276
 	 */
277 277
 	protected function set_item( &$order, $item_type, $posted ) {
278
-		if ( ! empty( $posted['id'] ) ) {
278
+		if ( ! empty( $posted[ 'id' ] ) ) {
279 279
 			$action = 'update';
280 280
 		} else {
281 281
 			$action = 'create';
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 
287 287
 		// Verify provided line item ID is associated with order.
288 288
 		if ( 'update' === $action ) {
289
-			$item = $order->get_item( absint( $posted['id'] ), false );
289
+			$item = $order->get_item( absint( $posted[ 'id' ] ), false );
290 290
 
291 291
 			if ( ! $item ) {
292 292
 				throw new \WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce-rest-api' ), 400 );
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 * @return array
316 316
 	 */
317 317
 	protected function parse_address_field( $data, $object, $type = 'billing' ) {
318
-		$address = [];
318
+		$address = [ ];
319 319
 		foreach ( $data as $key => $value ) {
320 320
 			if ( is_callable( array( $object, "set_{$type}_{$key}" ) ) ) {
321 321
 				$address[ "{$type}_{$key}" ] = $value;
@@ -368,12 +368,12 @@  discard block
 block discarded – undo
368 368
 
369 369
 		foreach ( $coupon_lines as $item ) {
370 370
 			if ( is_array( $item ) ) {
371
-				if ( empty( $item['id'] ) ) {
372
-					if ( empty( $item['code'] ) ) {
371
+				if ( empty( $item[ 'id' ] ) ) {
372
+					if ( empty( $item[ 'code' ] ) ) {
373 373
 						throw new \WC_REST_Exception( 'woocommerce_rest_invalid_coupon', __( 'Coupon code is required.', 'woocommerce-rest-api' ), 400 );
374 374
 					}
375 375
 
376
-					$results = $order->apply_coupon( wc_clean( $item['code'] ) );
376
+					$results = $order->apply_coupon( wc_clean( $item[ 'code' ] ) );
377 377
 
378 378
 					if ( is_wp_error( $results ) ) {
379 379
 						throw new \WC_REST_Exception( 'woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400 );
Please login to merge, or discard this patch.
src/Controllers/Version4/ShippingMethods.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) {
85 85
 			$method     = $this->prepare_item_for_response( $shipping_method, $request );
86 86
 			$method     = $this->prepare_response_for_collection( $method );
87
-			$response[] = $method;
87
+			$response[ ] = $method;
88 88
 		}
89 89
 		return rest_ensure_response( $response );
90 90
 	}
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
 	public function get_item( $request ) {
99 99
 		$wc_shipping = \WC_Shipping::instance();
100 100
 		$methods     = $wc_shipping->get_shipping_methods();
101
-		if ( empty( $methods[ $request['id'] ] ) ) {
101
+		if ( empty( $methods[ $request[ 'id' ] ] ) ) {
102 102
 			return new \WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
103 103
 		}
104 104
 
105
-		$method   = $methods[ $request['id'] ];
105
+		$method   = $methods[ $request[ 'id' ] ];
106 106
 		$response = $this->prepare_item_for_response( $method, $request );
107 107
 
108 108
 		return rest_ensure_response( $response );
Please login to merge, or discard this patch.
src/Controllers/Version4/OrderNotes.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @return \WP_Error|boolean
120 120
 	 */
121 121
 	public function get_item_permissions_check( $request ) {
122
-		$order = wc_get_order( (int) $request['order_id'] );
122
+		$order = wc_get_order( (int) $request[ 'order_id' ] );
123 123
 
124 124
 		if ( $order && ! Permissions::user_can_read( $this->post_type, $order->get_id() ) ) {
125 125
 			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce-rest-api' ), array( 'status' => rest_authorization_required_code() ) );
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	 * @return bool|\WP_Error
137 137
 	 */
138 138
 	public function delete_item_permissions_check( $request ) {
139
-		$order = wc_get_order( (int) $request['order_id'] );
139
+		$order = wc_get_order( (int) $request[ 'order_id' ] );
140 140
 
141 141
 		if ( $order && ! Permissions::user_can_delete( $this->post_type, $order->get_id() ) ) {
142 142
 			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce-rest-api' ), array( 'status' => rest_authorization_required_code() ) );
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @return array|\WP_Error
154 154
 	 */
155 155
 	public function get_items( $request ) {
156
-		$order = wc_get_order( (int) $request['order_id'] );
156
+		$order = wc_get_order( (int) $request[ 'order_id' ] );
157 157
 
158 158
 		if ( ! $order || $this->post_type !== $order->get_type() ) {
159 159
 			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
@@ -166,16 +166,16 @@  discard block
 block discarded – undo
166 166
 		);
167 167
 
168 168
 		// Allow filter by order note type.
169
-		if ( 'customer' === $request['type'] ) {
170
-			$args['meta_query'] = array( // WPCS: slow query ok.
169
+		if ( 'customer' === $request[ 'type' ] ) {
170
+			$args[ 'meta_query' ] = array( // WPCS: slow query ok.
171 171
 				array(
172 172
 					'key'     => 'is_customer_note',
173 173
 					'value'   => 1,
174 174
 					'compare' => '=',
175 175
 				),
176 176
 			);
177
-		} elseif ( 'internal' === $request['type'] ) {
178
-			$args['meta_query'] = array( // WPCS: slow query ok.
177
+		} elseif ( 'internal' === $request[ 'type' ] ) {
178
+			$args[ 'meta_query' ] = array( // WPCS: slow query ok.
179 179
 				array(
180 180
 					'key'     => 'is_customer_note',
181 181
 					'compare' => 'NOT EXISTS',
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		foreach ( $notes as $note ) {
194 194
 			$order_note = $this->prepare_item_for_response( $note, $request );
195 195
 			$order_note = $this->prepare_response_for_collection( $order_note );
196
-			$data[]     = $order_note;
196
+			$data[ ]     = $order_note;
197 197
 		}
198 198
 
199 199
 		return rest_ensure_response( $data );
@@ -206,19 +206,19 @@  discard block
 block discarded – undo
206 206
 	 * @return \WP_Error|\WP_REST_Response
207 207
 	 */
208 208
 	public function create_item( $request ) {
209
-		if ( ! empty( $request['id'] ) ) {
209
+		if ( ! empty( $request[ 'id' ] ) ) {
210 210
 			/* translators: %s: post type */
211 211
 			return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce-rest-api' ), $this->post_type ), array( 'status' => 400 ) );
212 212
 		}
213 213
 
214
-		$order = wc_get_order( (int) $request['order_id'] );
214
+		$order = wc_get_order( (int) $request[ 'order_id' ] );
215 215
 
216 216
 		if ( ! $order || $this->post_type !== $order->get_type() ) {
217 217
 			return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
218 218
 		}
219 219
 
220 220
 		// Create the note.
221
-		$note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] );
221
+		$note_id = $order->add_order_note( $request[ 'note' ], $request[ 'customer_note' ], $request[ 'added_by_user' ] );
222 222
 
223 223
 		if ( ! $note_id ) {
224 224
 			return new \WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce-rest-api' ), array( 'status' => 500 ) );
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 * @return \WP_Error|\WP_REST_Response
253 253
 	 */
254 254
 	public function get_item( $request ) {
255
-		$id    = (int) $request['id'];
256
-		$order = wc_get_order( (int) $request['order_id'] );
255
+		$id    = (int) $request[ 'id' ];
256
+		$order = wc_get_order( (int) $request[ 'order_id' ] );
257 257
 
258 258
 		if ( ! $order || $this->post_type !== $order->get_type() ) {
259 259
 			return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
 	 * @return \WP_REST_Response|\WP_Error
279 279
 	 */
280 280
 	public function delete_item( $request ) {
281
-		$id    = (int) $request['id'];
282
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
281
+		$id    = (int) $request[ 'id' ];
282
+		$force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false;
283 283
 
284 284
 		// We don't support trashing for this type, error out.
285 285
 		if ( ! $force ) {
286 286
 			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce-rest-api' ), array( 'status' => 501 ) );
287 287
 		}
288 288
 
289
-		$order = wc_get_order( (int) $request['order_id'] );
289
+		$order = wc_get_order( (int) $request[ 'order_id' ] );
290 290
 
291 291
 		if ( ! $order || $this->post_type !== $order->get_type() ) {
292 292
 			return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
 	 */
435 435
 	public function get_collection_params() {
436 436
 		$params            = array();
437
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
438
-		$params['type']    = array(
437
+		$params[ 'context' ] = $this->get_context_param( array( 'default' => 'view' ) );
438
+		$params[ 'type' ]    = array(
439 439
 			'default'           => 'any',
440 440
 			'description'       => __( 'Limit result to customers or internal notes.', 'woocommerce-rest-api' ),
441 441
 			'type'              => 'string',
Please login to merge, or discard this patch.
src/Controllers/Version4/ProductReviews.php 1 patch
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -176,29 +176,29 @@  discard block
 block discarded – undo
176 176
 			}
177 177
 		}
178 178
 
179
-		if ( isset( $registered['orderby'] ) ) {
180
-			$prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] );
179
+		if ( isset( $registered[ 'orderby' ] ) ) {
180
+			$prepared_args[ 'orderby' ] = $this->normalize_query_param( $request[ 'orderby' ] );
181 181
 		}
182 182
 
183
-		if ( isset( $prepared_args['status'] ) ) {
184
-			$prepared_args['status'] = 'approved' === $prepared_args['status'] ? 'approve' : $prepared_args['status'];
183
+		if ( isset( $prepared_args[ 'status' ] ) ) {
184
+			$prepared_args[ 'status' ] = 'approved' === $prepared_args[ 'status' ] ? 'approve' : $prepared_args[ 'status' ];
185 185
 		}
186 186
 
187
-		$prepared_args['no_found_rows'] = false;
188
-		$prepared_args['date_query']    = array();
187
+		$prepared_args[ 'no_found_rows' ] = false;
188
+		$prepared_args[ 'date_query' ]    = array();
189 189
 
190 190
 		// Set before into date query. Date query must be specified as an array of an array.
191
-		if ( isset( $registered['before'], $request['before'] ) ) {
192
-			$prepared_args['date_query'][0]['before'] = $request['before'];
191
+		if ( isset( $registered[ 'before' ], $request[ 'before' ] ) ) {
192
+			$prepared_args[ 'date_query' ][ 0 ][ 'before' ] = $request[ 'before' ];
193 193
 		}
194 194
 
195 195
 		// Set after into date query. Date query must be specified as an array of an array.
196
-		if ( isset( $registered['after'], $request['after'] ) ) {
197
-			$prepared_args['date_query'][0]['after'] = $request['after'];
196
+		if ( isset( $registered[ 'after' ], $request[ 'after' ] ) ) {
197
+			$prepared_args[ 'date_query' ][ 0 ][ 'after' ] = $request[ 'after' ];
198 198
 		}
199 199
 
200
-		if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) {
201
-			$prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 );
200
+		if ( isset( $registered[ 'page' ] ) && empty( $request[ 'offset' ] ) ) {
201
+			$prepared_args[ 'offset' ] = $prepared_args[ 'number' ] * ( absint( $request[ 'page' ] ) - 1 );
202 202
 		}
203 203
 
204 204
 		/**
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 		$prepared_args = apply_filters( 'woocommerce_rest_product_review_query', $prepared_args, $request );
213 213
 
214 214
 		// Make sure that returns only reviews.
215
-		$prepared_args['type'] = 'review';
215
+		$prepared_args[ 'type' ] = 'review';
216 216
 
217 217
 		// Query reviews.
218 218
 		$query        = new \WP_Comment_Query();
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 			}
226 226
 
227 227
 			$data      = $this->prepare_item_for_response( $review, $request );
228
-			$reviews[] = $this->prepare_response_for_collection( $data );
228
+			$reviews[ ] = $this->prepare_response_for_collection( $data );
229 229
 		}
230 230
 
231 231
 		$total_reviews = (int) $query->found_comments;
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 
234 234
 		if ( $total_reviews < 1 ) {
235 235
 			// Out-of-bounds, run the query again without LIMIT for total count.
236
-			unset( $prepared_args['number'], $prepared_args['offset'] );
236
+			unset( $prepared_args[ 'number' ], $prepared_args[ 'offset' ] );
237 237
 
238 238
 			$query                  = new \WP_Comment_Query();
239
-			$prepared_args['count'] = true;
239
+			$prepared_args[ 'count' ] = true;
240 240
 
241 241
 			$total_reviews = $query->query( $prepared_args );
242
-			$max_pages     = ceil( $total_reviews / $request['per_page'] );
242
+			$max_pages     = ceil( $total_reviews / $request[ 'per_page' ] );
243 243
 		}
244 244
 
245 245
 		$response = rest_ensure_response( $reviews );
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
 	 * @return \WP_Error|\WP_REST_Response
256 256
 	 */
257 257
 	public function create_item( $request ) {
258
-		if ( ! empty( $request['id'] ) ) {
258
+		if ( ! empty( $request[ 'id' ] ) ) {
259 259
 			return new \WP_Error( 'woocommerce_rest_review_exists', __( 'Cannot create existing product review.', 'woocommerce-rest-api' ), array( 'status' => 400 ) );
260 260
 		}
261 261
 
262
-		$product_id = (int) $request['product_id'];
262
+		$product_id = (int) $request[ 'product_id' ];
263 263
 
264 264
 		if ( 'product' !== get_post_type( $product_id ) ) {
265 265
 			return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
@@ -270,32 +270,32 @@  discard block
 block discarded – undo
270 270
 			return $prepared_review;
271 271
 		}
272 272
 
273
-		$prepared_review['comment_type'] = 'review';
273
+		$prepared_review[ 'comment_type' ] = 'review';
274 274
 
275 275
 		/*
276 276
 		 * Do not allow a comment to be created with missing or empty comment_content. See wp_handle_comment_submission().
277 277
 		 */
278
-		if ( empty( $prepared_review['comment_content'] ) ) {
278
+		if ( empty( $prepared_review[ 'comment_content' ] ) ) {
279 279
 			return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce-rest-api' ), array( 'status' => 400 ) );
280 280
 		}
281 281
 
282 282
 		// Setting remaining values before wp_insert_comment so we can use wp_allow_comment().
283
-		if ( ! isset( $prepared_review['comment_date_gmt'] ) ) {
284
-			$prepared_review['comment_date_gmt'] = current_time( 'mysql', true );
283
+		if ( ! isset( $prepared_review[ 'comment_date_gmt' ] ) ) {
284
+			$prepared_review[ 'comment_date_gmt' ] = current_time( 'mysql', true );
285 285
 		}
286 286
 
287
-		if ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) { // WPCS: input var ok, sanitization ok.
288
-			$prepared_review['comment_author_IP'] = wc_clean( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // WPCS: input var ok.
287
+		if ( ! empty( $_SERVER[ 'REMOTE_ADDR' ] ) && rest_is_ip_address( wp_unslash( $_SERVER[ 'REMOTE_ADDR' ] ) ) ) { // WPCS: input var ok, sanitization ok.
288
+			$prepared_review[ 'comment_author_IP' ] = wc_clean( wp_unslash( $_SERVER[ 'REMOTE_ADDR' ] ) ); // WPCS: input var ok.
289 289
 		} else {
290
-			$prepared_review['comment_author_IP'] = '127.0.0.1';
290
+			$prepared_review[ 'comment_author_IP' ] = '127.0.0.1';
291 291
 		}
292 292
 
293
-		if ( ! empty( $request['author_user_agent'] ) ) {
294
-			$prepared_review['comment_agent'] = $request['author_user_agent'];
293
+		if ( ! empty( $request[ 'author_user_agent' ] ) ) {
294
+			$prepared_review[ 'comment_agent' ] = $request[ 'author_user_agent' ];
295 295
 		} elseif ( $request->get_header( 'user_agent' ) ) {
296
-			$prepared_review['comment_agent'] = $request->get_header( 'user_agent' );
296
+			$prepared_review[ 'comment_agent' ] = $request->get_header( 'user_agent' );
297 297
 		} else {
298
-			$prepared_review['comment_agent'] = '';
298
+			$prepared_review[ 'comment_agent' ] = '';
299 299
 		}
300 300
 
301 301
 		$check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_review );
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
 			return new \WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce-rest-api' ), array( 'status' => 400 ) );
305 305
 		}
306 306
 
307
-		$prepared_review['comment_parent']     = 0;
308
-		$prepared_review['comment_author_url'] = '';
309
-		$prepared_review['comment_approved']   = wp_allow_comment( $prepared_review, true );
307
+		$prepared_review[ 'comment_parent' ]     = 0;
308
+		$prepared_review[ 'comment_author_url' ] = '';
309
+		$prepared_review[ 'comment_approved' ]   = wp_allow_comment( $prepared_review, true );
310 310
 
311
-		if ( is_wp_error( $prepared_review['comment_approved'] ) ) {
312
-			$error_code    = $prepared_review['comment_approved']->get_error_code();
313
-			$error_message = $prepared_review['comment_approved']->get_error_message();
311
+		if ( is_wp_error( $prepared_review[ 'comment_approved' ] ) ) {
312
+			$error_code    = $prepared_review[ 'comment_approved' ]->get_error_code();
313
+			$error_message = $prepared_review[ 'comment_approved' ]->get_error_message();
314 314
 
315 315
 			if ( 'comment_duplicate' === $error_code ) {
316 316
 				return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 409 ) );
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 				return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 400 ) );
321 321
 			}
322 322
 
323
-			return $prepared_review['comment_approved'];
323
+			return $prepared_review[ 'comment_approved' ];
324 324
 		}
325 325
 
326 326
 		/**
@@ -345,11 +345,11 @@  discard block
 block discarded – undo
345 345
 			return new \WP_Error( 'woocommerce_rest_review_failed_create', __( 'Creating product review failed.', 'woocommerce-rest-api' ), array( 'status' => 500 ) );
346 346
 		}
347 347
 
348
-		if ( isset( $request['status'] ) ) {
349
-			$this->handle_status_param( $request['status'], $review_id );
348
+		if ( isset( $request[ 'status' ] ) ) {
349
+			$this->handle_status_param( $request[ 'status' ], $review_id );
350 350
 		}
351 351
 
352
-		update_comment_meta( $review_id, 'rating', ! empty( $request['rating'] ) ? $request['rating'] : '0' );
352
+		update_comment_meta( $review_id, 'rating', ! empty( $request[ 'rating' ] ) ? $request[ 'rating' ] : '0' );
353 353
 
354 354
 		$review = get_comment( $review_id );
355 355
 
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 	 * @return \WP_Error|\WP_REST_Response
386 386
 	 */
387 387
 	public function get_item( $request ) {
388
-		$review = $this->get_review( $request['id'] );
388
+		$review = $this->get_review( $request[ 'id' ] );
389 389
 		if ( is_wp_error( $review ) ) {
390 390
 			return $review;
391 391
 		}
@@ -400,14 +400,14 @@  discard block
 block discarded – undo
400 400
 	 * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure.
401 401
 	 */
402 402
 	public function update_item( $request ) {
403
-		$review = $this->get_review( $request['id'] );
403
+		$review = $this->get_review( $request[ 'id' ] );
404 404
 		if ( is_wp_error( $review ) ) {
405 405
 			return $review;
406 406
 		}
407 407
 
408 408
 		$id = (int) $review->comment_ID;
409 409
 
410
-		if ( isset( $request['type'] ) && 'review' !== get_comment_type( $id ) ) {
410
+		if ( isset( $request[ 'type' ] ) && 'review' !== get_comment_type( $id ) ) {
411 411
 			return new \WP_Error( 'woocommerce_rest_review_invalid_type', __( 'Sorry, you are not allowed to change the comment type.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
412 412
 		}
413 413
 
@@ -416,15 +416,15 @@  discard block
 block discarded – undo
416 416
 			return $prepared_args;
417 417
 		}
418 418
 
419
-		if ( ! empty( $prepared_args['comment_post_ID'] ) ) {
420
-			if ( 'product' !== get_post_type( (int) $prepared_args['comment_post_ID'] ) ) {
419
+		if ( ! empty( $prepared_args[ 'comment_post_ID' ] ) ) {
420
+			if ( 'product' !== get_post_type( (int) $prepared_args[ 'comment_post_ID' ] ) ) {
421 421
 				return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) );
422 422
 			}
423 423
 		}
424 424
 
425
-		if ( empty( $prepared_args ) && isset( $request['status'] ) ) {
425
+		if ( empty( $prepared_args ) && isset( $request[ 'status' ] ) ) {
426 426
 			// Only the comment status is being changed.
427
-			$change = $this->handle_status_param( $request['status'], $id );
427
+			$change = $this->handle_status_param( $request[ 'status' ], $id );
428 428
 
429 429
 			if ( ! $change ) {
430 430
 				return new \WP_Error( 'woocommerce_rest_review_failed_edit', __( 'Updating review status failed.', 'woocommerce-rest-api' ), array( 'status' => 500 ) );
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
 				return $prepared_args;
435 435
 			}
436 436
 
437
-			if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) {
437
+			if ( isset( $prepared_args[ 'comment_content' ] ) && empty( $prepared_args[ 'comment_content' ] ) ) {
438 438
 				return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce-rest-api' ), array( 'status' => 400 ) );
439 439
 			}
440 440
 
441
-			$prepared_args['comment_ID'] = $id;
441
+			$prepared_args[ 'comment_ID' ] = $id;
442 442
 
443 443
 			$check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args );
444 444
 			if ( is_wp_error( $check_comment_lengths ) ) {
@@ -452,13 +452,13 @@  discard block
 block discarded – undo
452 452
 				return new \WP_Error( 'woocommerce_rest_comment_failed_edit', __( 'Updating review failed.', 'woocommerce-rest-api' ), array( 'status' => 500 ) );
453 453
 			}
454 454
 
455
-			if ( isset( $request['status'] ) ) {
456
-				$this->handle_status_param( $request['status'], $id );
455
+			if ( isset( $request[ 'status' ] ) ) {
456
+				$this->handle_status_param( $request[ 'status' ], $id );
457 457
 			}
458 458
 		}
459 459
 
460
-		if ( ! empty( $request['rating'] ) ) {
461
-			update_comment_meta( $id, 'rating', $request['rating'] );
460
+		if ( ! empty( $request[ 'rating' ] ) ) {
461
+			update_comment_meta( $id, 'rating', $request[ 'rating' ] );
462 462
 		}
463 463
 
464 464
 		$review = get_comment( $id );
@@ -484,12 +484,12 @@  discard block
 block discarded – undo
484 484
 	 * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure.
485 485
 	 */
486 486
 	public function delete_item( $request ) {
487
-		$review = $this->get_review( $request['id'] );
487
+		$review = $this->get_review( $request[ 'id' ] );
488 488
 		if ( is_wp_error( $review ) ) {
489 489
 			return $review;
490 490
 		}
491 491
 
492
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
492
+		$force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false;
493 493
 
494 494
 		/**
495 495
 		 * Filters whether a review can be trashed.
@@ -566,37 +566,37 @@  discard block
 block discarded – undo
566 566
 	 * @return array|\WP_Error  $prepared_review
567 567
 	 */
568 568
 	protected function prepare_item_for_database( $request ) {
569
-		if ( isset( $request['id'] ) ) {
570
-			$prepared_review['comment_ID'] = (int) $request['id'];
569
+		if ( isset( $request[ 'id' ] ) ) {
570
+			$prepared_review[ 'comment_ID' ] = (int) $request[ 'id' ];
571 571
 		}
572 572
 
573
-		if ( isset( $request['review'] ) ) {
574
-			$prepared_review['comment_content'] = $request['review'];
573
+		if ( isset( $request[ 'review' ] ) ) {
574
+			$prepared_review[ 'comment_content' ] = $request[ 'review' ];
575 575
 		}
576 576
 
577
-		if ( isset( $request['product_id'] ) ) {
578
-			$prepared_review['comment_post_ID'] = (int) $request['product_id'];
577
+		if ( isset( $request[ 'product_id' ] ) ) {
578
+			$prepared_review[ 'comment_post_ID' ] = (int) $request[ 'product_id' ];
579 579
 		}
580 580
 
581
-		if ( isset( $request['reviewer'] ) ) {
582
-			$prepared_review['comment_author'] = $request['reviewer'];
581
+		if ( isset( $request[ 'reviewer' ] ) ) {
582
+			$prepared_review[ 'comment_author' ] = $request[ 'reviewer' ];
583 583
 		}
584 584
 
585
-		if ( isset( $request['reviewer_email'] ) ) {
586
-			$prepared_review['comment_author_email'] = $request['reviewer_email'];
585
+		if ( isset( $request[ 'reviewer_email' ] ) ) {
586
+			$prepared_review[ 'comment_author_email' ] = $request[ 'reviewer_email' ];
587 587
 		}
588 588
 
589
-		if ( ! empty( $request['date_created'] ) ) {
590
-			$date_data = rest_get_date_with_gmt( $request['date_created'] );
589
+		if ( ! empty( $request[ 'date_created' ] ) ) {
590
+			$date_data = rest_get_date_with_gmt( $request[ 'date_created' ] );
591 591
 
592 592
 			if ( ! empty( $date_data ) ) {
593
-				list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data;
593
+				list( $prepared_review[ 'comment_date' ], $prepared_review[ 'comment_date_gmt' ] ) = $date_data;
594 594
 			}
595
-		} elseif ( ! empty( $request['date_created_gmt'] ) ) {
596
-			$date_data = rest_get_date_with_gmt( $request['date_created_gmt'], true );
595
+		} elseif ( ! empty( $request[ 'date_created_gmt' ] ) ) {
596
+			$date_data = rest_get_date_with_gmt( $request[ 'date_created_gmt' ], true );
597 597
 
598 598
 			if ( ! empty( $date_data ) ) {
599
-				list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data;
599
+				list( $prepared_review[ 'comment_date' ], $prepared_review[ 'comment_date_gmt' ] ) = $date_data;
600 600
 			}
601 601
 		}
602 602
 
@@ -629,13 +629,13 @@  discard block
 block discarded – undo
629 629
 			),
630 630
 		);
631 631
 		if ( 0 !== (int) $item->comment_post_ID ) {
632
-			$links['up'] = array(
632
+			$links[ 'up' ] = array(
633 633
 				'href'       => rest_url( sprintf( '/%s/products/%d', $this->namespace, $item->comment_post_ID ) ),
634 634
 				'embeddable' => true,
635 635
 			);
636 636
 		}
637 637
 		if ( 0 !== (int) $item->user_id ) {
638
-			$links['reviewer'] = array(
638
+			$links[ 'reviewer' ] = array(
639 639
 				'href'       => rest_url( 'wp/v2/users/' . $item->user_id ),
640 640
 				'embeddable' => true,
641 641
 			);
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
 					'context'     => array( 'embed', 'view', 'edit' ),
731 731
 				);
732 732
 			}
733
-			$schema['properties']['reviewer_avatar_urls'] = array(
733
+			$schema[ 'properties' ][ 'reviewer_avatar_urls' ] = array(
734 734
 				'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce-rest-api' ),
735 735
 				'type'        => 'object',
736 736
 				'context'     => array( 'view', 'edit' ),
@@ -750,19 +750,19 @@  discard block
 block discarded – undo
750 750
 	public function get_collection_params() {
751 751
 		$params = parent::get_collection_params();
752 752
 
753
-		$params['context']['default'] = 'view';
753
+		$params[ 'context' ][ 'default' ] = 'view';
754 754
 
755
-		$params['after']            = array(
755
+		$params[ 'after' ] = array(
756 756
 			'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce-rest-api' ),
757 757
 			'type'        => 'string',
758 758
 			'format'      => 'date-time',
759 759
 		);
760
-		$params['before']           = array(
760
+		$params[ 'before' ] = array(
761 761
 			'description' => __( 'Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce-rest-api' ),
762 762
 			'type'        => 'string',
763 763
 			'format'      => 'date-time',
764 764
 		);
765
-		$params['exclude']          = array(
765
+		$params[ 'exclude' ] = array(
766 766
 			'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce-rest-api' ),
767 767
 			'type'        => 'array',
768 768
 			'items'       => array(
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
 			),
771 771
 			'default'     => array(),
772 772
 		);
773
-		$params['include']          = array(
773
+		$params[ 'include' ] = array(
774 774
 			'description' => __( 'Limit result set to specific IDs.', 'woocommerce-rest-api' ),
775 775
 			'type'        => 'array',
776 776
 			'items'       => array(
@@ -778,11 +778,11 @@  discard block
 block discarded – undo
778 778
 			),
779 779
 			'default'     => array(),
780 780
 		);
781
-		$params['offset']           = array(
781
+		$params[ 'offset' ] = array(
782 782
 			'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce-rest-api' ),
783 783
 			'type'        => 'integer',
784 784
 		);
785
-		$params['order']            = array(
785
+		$params[ 'order' ] = array(
786 786
 			'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce-rest-api' ),
787 787
 			'type'        => 'string',
788 788
 			'default'     => 'desc',
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 				'desc',
792 792
 			),
793 793
 		);
794
-		$params['orderby']          = array(
794
+		$params[ 'orderby' ] = array(
795 795
 			'description' => __( 'Sort collection by object attribute.', 'woocommerce-rest-api' ),
796 796
 			'type'        => 'string',
797 797
 			'default'     => 'date_gmt',
@@ -803,27 +803,27 @@  discard block
 block discarded – undo
803 803
 				'product',
804 804
 			),
805 805
 		);
806
-		$params['reviewer']         = array(
806
+		$params[ 'reviewer' ] = array(
807 807
 			'description' => __( 'Limit result set to reviews assigned to specific user IDs.', 'woocommerce-rest-api' ),
808 808
 			'type'        => 'array',
809 809
 			'items'       => array(
810 810
 				'type' => 'integer',
811 811
 			),
812 812
 		);
813
-		$params['reviewer_exclude'] = array(
813
+		$params[ 'reviewer_exclude' ] = array(
814 814
 			'description' => __( 'Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce-rest-api' ),
815 815
 			'type'        => 'array',
816 816
 			'items'       => array(
817 817
 				'type' => 'integer',
818 818
 			),
819 819
 		);
820
-		$params['reviewer_email']   = array(
820
+		$params[ 'reviewer_email' ] = array(
821 821
 			'default'     => null,
822 822
 			'description' => __( 'Limit result set to that from a specific author email.', 'woocommerce-rest-api' ),
823 823
 			'format'      => 'email',
824 824
 			'type'        => 'string',
825 825
 		);
826
-		$params['product']          = array(
826
+		$params[ 'product' ] = array(
827 827
 			'default'     => array(),
828 828
 			'description' => __( 'Limit result set to reviews assigned to specific product IDs.', 'woocommerce-rest-api' ),
829 829
 			'type'        => 'array',
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 				'type' => 'integer',
832 832
 			),
833 833
 		);
834
-		$params['status']           = array(
834
+		$params[ 'status' ] = array(
835 835
 			'default'           => 'approved',
836 836
 			'description'       => __( 'Limit result set to reviews assigned a specific status.', 'woocommerce-rest-api' ),
837 837
 			'sanitize_callback' => 'sanitize_key',
Please login to merge, or discard this patch.