Passed
Push — master ( 2785bd...f2bf98 )
by Claudio
05:59
created
src/Controllers/Version4/Data/DownloadIPs.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
 	public function get_items( $request ) {
56 56
 		global $wpdb;
57 57
 
58
-		if ( isset( $request['match'] ) ) {
58
+		if ( isset( $request[ 'match' ] ) ) {
59 59
 			$downloads = $wpdb->get_results(
60 60
 				$wpdb->prepare(
61 61
 					"SELECT DISTINCT( user_ip_address ) FROM {$wpdb->prefix}wc_download_log
62 62
 					WHERE user_ip_address LIKE %s
63 63
 					LIMIT 10",
64
-					$request['match'] . '%'
64
+					$request[ 'match' ] . '%'
65 65
 				)
66 66
 			);
67 67
 		} else {
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		if ( ! empty( $downloads ) ) {
74 74
 			foreach ( $downloads as $download ) {
75 75
 				$response = $this->prepare_item_for_response( (array) $download, $request );
76
-				$data[]   = $this->prepare_response_for_collection( $response );
76
+				$data[ ]   = $this->prepare_response_for_collection( $response );
77 77
 			}
78 78
 		}
79 79
 
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 */
115 115
 	public function get_collection_params() {
116 116
 		$params            = array();
117
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
118
-		$params['match']   = array(
117
+		$params[ 'context' ] = $this->get_context_param( array( 'default' => 'view' ) );
118
+		$params[ 'match' ]   = array(
119 119
 			'description'       => __( 'A partial IP address can be passed and matching results will be returned.', 'woocommerce-rest-api' ),
120 120
 			'type'              => 'string',
121 121
 			'validate_callback' => 'rest_validate_request_arg',
Please login to merge, or discard this patch.
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.