Completed
Push — master ( 3be021...a518b9 )
by Mike
04:08
created
src/Controllers/Version4/Customers.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -136,16 +136,16 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	public function get_items( $request ) {
138 138
 		$prepared_args = array(
139
-			'exclude' => $request['exclude'],
140
-			'include' => $request['include'],
141
-			'order'   => $request['order'],
142
-			'number'  => $request['per_page'],
139
+			'exclude' => $request[ 'exclude' ],
140
+			'include' => $request[ 'include' ],
141
+			'order'   => $request[ 'order' ],
142
+			'number'  => $request[ 'per_page' ],
143 143
 		);
144 144
 
145
-		if ( ! empty( $request['offset'] ) ) {
146
-			$prepared_args['offset'] = $request['offset'];
145
+		if ( ! empty( $request[ 'offset' ] ) ) {
146
+			$prepared_args[ 'offset' ] = $request[ 'offset' ];
147 147
 		} else {
148
-			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
148
+			$prepared_args[ 'offset' ] = ( $request[ 'page' ] - 1 ) * $prepared_args[ 'number' ];
149 149
 		}
150 150
 
151 151
 		$orderby_possibles = array(
@@ -154,22 +154,22 @@  discard block
 block discarded – undo
154 154
 			'name'            => 'display_name',
155 155
 			'registered_date' => 'registered',
156 156
 		);
157
-		$prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ];
158
-		$prepared_args['search']  = $request['search'];
157
+		$prepared_args[ 'orderby' ] = $orderby_possibles[ $request[ 'orderby' ] ];
158
+		$prepared_args[ 'search' ]  = $request[ 'search' ];
159 159
 
160
-		if ( '' !== $prepared_args['search'] ) {
161
-			$prepared_args['search'] = '*' . $prepared_args['search'] . '*';
160
+		if ( '' !== $prepared_args[ 'search' ] ) {
161
+			$prepared_args[ 'search' ] = '*' . $prepared_args[ 'search' ] . '*';
162 162
 		}
163 163
 
164 164
 		// Filter by email.
165
-		if ( ! empty( $request['email'] ) ) {
166
-			$prepared_args['search']         = $request['email'];
167
-			$prepared_args['search_columns'] = array( 'user_email' );
165
+		if ( ! empty( $request[ 'email' ] ) ) {
166
+			$prepared_args[ 'search' ]         = $request[ 'email' ];
167
+			$prepared_args[ 'search_columns' ] = array( 'user_email' );
168 168
 		}
169 169
 
170 170
 		// Filter by role.
171
-		if ( 'all' !== $request['role'] ) {
172
-			$prepared_args['role'] = $request['role'];
171
+		if ( 'all' !== $request[ 'role' ] ) {
172
+			$prepared_args[ 'role' ] = $request[ 'role' ];
173 173
 		}
174 174
 
175 175
 		/**
@@ -188,21 +188,21 @@  discard block
 block discarded – undo
188 188
 		foreach ( $query->results as $user ) {
189 189
 			$customer = new \WC_Customer( $user->ID );
190 190
 			$data     = $this->prepare_item_for_response( $customer, $request );
191
-			$users[]  = $this->prepare_response_for_collection( $data );
191
+			$users[ ]  = $this->prepare_response_for_collection( $data );
192 192
 		}
193 193
 
194 194
 		// Store pagination values for headers then unset for count query.
195
-		$per_page = (int) $prepared_args['number'];
196
-		$page     = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
195
+		$per_page = (int) $prepared_args[ 'number' ];
196
+		$page     = ceil( ( ( (int) $prepared_args[ 'offset' ] ) / $per_page ) + 1 );
197 197
 
198
-		$prepared_args['fields'] = 'ID';
198
+		$prepared_args[ 'fields' ] = 'ID';
199 199
 
200 200
 		$total_users = $query->get_total();
201 201
 
202 202
 		if ( $total_users < 1 ) {
203 203
 			// Out-of-bounds, run the query again without LIMIT for total count.
204
-			unset( $prepared_args['number'] );
205
-			unset( $prepared_args['offset'] );
204
+			unset( $prepared_args[ 'number' ] );
205
+			unset( $prepared_args[ 'offset' ] );
206 206
 			$count_query = new \ WP_User_Query( $prepared_args );
207 207
 			$total_users = $count_query->get_total();
208 208
 		}
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 */
223 223
 	public function create_item( $request ) {
224 224
 		try {
225
-			if ( ! empty( $request['id'] ) ) {
225
+			if ( ! empty( $request[ 'id' ] ) ) {
226 226
 				throw new \WC_REST_Exception( 'woocommerce_rest_customer_exists', __( 'Cannot create existing resource.', 'woocommerce' ), 400 );
227 227
 			}
228 228
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	 * @return \WP_Error|\WP_REST_Response
265 265
 	 */
266 266
 	public function get_item( $request ) {
267
-		$id       = (int) $request['id'];
267
+		$id       = (int) $request[ 'id' ];
268 268
 		$customer = new \WC_Customer( $id );
269 269
 
270 270
 		if ( empty( $id ) || ! $customer->get_id() ) {
@@ -322,9 +322,9 @@  discard block
 block discarded – undo
322 322
 	 * @return \WP_Error|\WP_REST_Response
323 323
 	 */
324 324
 	public function delete_item( $request ) {
325
-		$id       = (int) $request['id'];
326
-		$reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null;
327
-		$force    = isset( $request['force'] ) ? (bool) $request['force'] : false;
325
+		$id       = (int) $request[ 'id' ];
326
+		$reassign = isset( $request[ 'reassign' ] ) ? absint( $request[ 'reassign' ] ) : null;
327
+		$force    = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false;
328 328
 
329 329
 		// We don't support trashing for this type, error out.
330 330
 		if ( ! $force ) {
@@ -663,9 +663,9 @@  discard block
 block discarded – undo
663 663
 	public function get_collection_params() {
664 664
 		$params = parent::get_collection_params();
665 665
 
666
-		$params['context']['default'] = 'view';
666
+		$params[ 'context' ][ 'default' ] = 'view';
667 667
 
668
-		$params['exclude'] = array(
668
+		$params[ 'exclude' ] = array(
669 669
 			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
670 670
 			'type'              => 'array',
671 671
 			'items'             => array(
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
 			'default'           => array(),
675 675
 			'sanitize_callback' => 'wp_parse_id_list',
676 676
 		);
677
-		$params['include'] = array(
677
+		$params[ 'include' ] = array(
678 678
 			'description'       => __( 'Limit result set to specific IDs.', 'woocommerce' ),
679 679
 			'type'              => 'array',
680 680
 			'items'             => array(
@@ -683,13 +683,13 @@  discard block
 block discarded – undo
683 683
 			'default'           => array(),
684 684
 			'sanitize_callback' => 'wp_parse_id_list',
685 685
 		);
686
-		$params['offset'] = array(
686
+		$params[ 'offset' ] = array(
687 687
 			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
688 688
 			'type'               => 'integer',
689 689
 			'sanitize_callback'  => 'absint',
690 690
 			'validate_callback'  => 'rest_validate_request_arg',
691 691
 		);
692
-		$params['order'] = array(
692
+		$params[ 'order' ] = array(
693 693
 			'default'            => 'asc',
694 694
 			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
695 695
 			'enum'               => array( 'asc', 'desc' ),
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 			'type'               => 'string',
698 698
 			'validate_callback'  => 'rest_validate_request_arg',
699 699
 		);
700
-		$params['orderby'] = array(
700
+		$params[ 'orderby' ] = array(
701 701
 			'default'            => 'name',
702 702
 			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
703 703
 			'enum'               => array(
@@ -710,13 +710,13 @@  discard block
 block discarded – undo
710 710
 			'type'               => 'string',
711 711
 			'validate_callback'  => 'rest_validate_request_arg',
712 712
 		);
713
-		$params['email'] = array(
713
+		$params[ 'email' ] = array(
714 714
 			'description'        => __( 'Limit result set to resources with a specific email.', 'woocommerce' ),
715 715
 			'type'               => 'string',
716 716
 			'format'             => 'email',
717 717
 			'validate_callback'  => 'rest_validate_request_arg',
718 718
 		);
719
-		$params['role'] = array(
719
+		$params[ 'role' ] = array(
720 720
 			'description'        => __( 'Limit result set to resources with a specific role.', 'woocommerce' ),
721 721
 			'type'               => 'string',
722 722
 			'default'            => 'customer',
Please login to merge, or discard this patch.
src/Controllers/Version4/ProductCategories.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		if ( $image_id ) {
57 57
 			$attachment = get_post( $image_id );
58 58
 
59
-			$data['image'] = array(
59
+			$data[ 'image' ] = array(
60 60
 				'id'                => (int) $image_id,
61 61
 				'date_created'      => wc_rest_prepare_date_response( $attachment->post_date ),
62 62
 				'date_created_gmt'  => wc_rest_prepare_date_response( $attachment->post_date_gmt ),
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
 	protected function update_term_meta_fields( $term, $request ) {
83 83
 		$id = (int) $term->term_id;
84 84
 
85
-		if ( isset( $request['display'] ) ) {
86
-			update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] );
85
+		if ( isset( $request[ 'display' ] ) ) {
86
+			update_term_meta( $id, 'display_type', 'default' === $request[ 'display' ] ? '' : $request[ 'display' ] );
87 87
 		}
88 88
 
89
-		if ( isset( $request['menu_order'] ) ) {
90
-			update_term_meta( $id, 'order', $request['menu_order'] );
89
+		if ( isset( $request[ 'menu_order' ] ) ) {
90
+			update_term_meta( $id, 'order', $request[ 'menu_order' ] );
91 91
 		}
92 92
 
93
-		if ( isset( $request['image'] ) ) {
94
-			if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) {
95
-				$upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) );
93
+		if ( isset( $request[ 'image' ] ) ) {
94
+			if ( empty( $request[ 'image' ][ 'id' ] ) && ! empty( $request[ 'image' ][ 'src' ] ) ) {
95
+				$upload = wc_rest_upload_image_from_url( esc_url_raw( $request[ 'image' ][ 'src' ] ) );
96 96
 
97 97
 				if ( is_wp_error( $upload ) ) {
98 98
 					return $upload;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 
101 101
 				$image_id = wc_rest_set_uploaded_image_as_attachment( $upload );
102 102
 			} else {
103
-				$image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0;
103
+				$image_id = isset( $request[ 'image' ][ 'id' ] ) ? absint( $request[ 'image' ][ 'id' ] ) : 0;
104 104
 			}
105 105
 
106 106
 			// Check if image_id is a valid image attachment before updating the term meta.
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
 				update_term_meta( $id, 'thumbnail_id', $image_id );
109 109
 
110 110
 				// Set the image alt.
111
-				if ( ! empty( $request['image']['alt'] ) ) {
112
-					update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) );
111
+				if ( ! empty( $request[ 'image' ][ 'alt' ] ) ) {
112
+					update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request[ 'image' ][ 'alt' ] ) );
113 113
 				}
114 114
 
115 115
 				// Set the image title.
116
-				if ( ! empty( $request['image']['name'] ) ) {
116
+				if ( ! empty( $request[ 'image' ][ 'name' ] ) ) {
117 117
 					wp_update_post(
118 118
 						array(
119 119
 							'ID'         => $image_id,
120
-							'post_title' => wc_clean( $request['image']['name'] ),
120
+							'post_title' => wc_clean( $request[ 'image' ][ 'name' ] ),
121 121
 						)
122 122
 					);
123 123
 				}
Please login to merge, or discard this patch.
src/Controllers/Version4/Coupons.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -74,32 +74,32 @@  discard block
 block discarded – undo
74 74
 
75 75
 		return array(
76 76
 			'id'                          => $object->get_id(),
77
-			'code'                        => $data['code'],
78
-			'amount'                      => $data['amount'],
79
-			'date_created'                => $data['date_created'],
80
-			'date_created_gmt'            => $data['date_created_gmt'],
81
-			'date_modified'               => $data['date_modified'],
82
-			'date_modified_gmt'           => $data['date_modified_gmt'],
83
-			'discount_type'               => $data['discount_type'],
84
-			'description'                 => $data['description'],
85
-			'date_expires'                => $data['date_expires'],
86
-			'date_expires_gmt'            => $data['date_expires_gmt'],
87
-			'usage_count'                 => $data['usage_count'],
88
-			'individual_use'              => $data['individual_use'],
89
-			'product_ids'                 => $data['product_ids'],
90
-			'excluded_product_ids'        => $data['excluded_product_ids'],
91
-			'usage_limit'                 => $data['usage_limit'],
92
-			'usage_limit_per_user'        => $data['usage_limit_per_user'],
93
-			'limit_usage_to_x_items'      => $data['limit_usage_to_x_items'],
94
-			'free_shipping'               => $data['free_shipping'],
95
-			'product_categories'          => $data['product_categories'],
96
-			'excluded_product_categories' => $data['excluded_product_categories'],
97
-			'exclude_sale_items'          => $data['exclude_sale_items'],
98
-			'minimum_amount'              => $data['minimum_amount'],
99
-			'maximum_amount'              => $data['maximum_amount'],
100
-			'email_restrictions'          => $data['email_restrictions'],
101
-			'used_by'                     => $data['used_by'],
102
-			'meta_data'                   => $data['meta_data'],
77
+			'code'                        => $data[ 'code' ],
78
+			'amount'                      => $data[ 'amount' ],
79
+			'date_created'                => $data[ 'date_created' ],
80
+			'date_created_gmt'            => $data[ 'date_created_gmt' ],
81
+			'date_modified'               => $data[ 'date_modified' ],
82
+			'date_modified_gmt'           => $data[ 'date_modified_gmt' ],
83
+			'discount_type'               => $data[ 'discount_type' ],
84
+			'description'                 => $data[ 'description' ],
85
+			'date_expires'                => $data[ 'date_expires' ],
86
+			'date_expires_gmt'            => $data[ 'date_expires_gmt' ],
87
+			'usage_count'                 => $data[ 'usage_count' ],
88
+			'individual_use'              => $data[ 'individual_use' ],
89
+			'product_ids'                 => $data[ 'product_ids' ],
90
+			'excluded_product_ids'        => $data[ 'excluded_product_ids' ],
91
+			'usage_limit'                 => $data[ 'usage_limit' ],
92
+			'usage_limit_per_user'        => $data[ 'usage_limit_per_user' ],
93
+			'limit_usage_to_x_items'      => $data[ 'limit_usage_to_x_items' ],
94
+			'free_shipping'               => $data[ 'free_shipping' ],
95
+			'product_categories'          => $data[ 'product_categories' ],
96
+			'excluded_product_categories' => $data[ 'excluded_product_categories' ],
97
+			'exclude_sale_items'          => $data[ 'exclude_sale_items' ],
98
+			'minimum_amount'              => $data[ 'minimum_amount' ],
99
+			'maximum_amount'              => $data[ 'maximum_amount' ],
100
+			'email_restrictions'          => $data[ 'email_restrictions' ],
101
+			'used_by'                     => $data[ 'used_by' ],
102
+			'meta_data'                   => $data[ 'meta_data' ],
103 103
 		);
104 104
 	}
105 105
 
@@ -113,14 +113,14 @@  discard block
 block discarded – undo
113 113
 	protected function prepare_objects_query( $request ) {
114 114
 		$args = parent::prepare_objects_query( $request );
115 115
 
116
-		if ( ! empty( $request['code'] ) ) {
117
-			$id               = wc_get_coupon_id_by_code( $request['code'] );
118
-			$args['post__in'] = array( $id );
116
+		if ( ! empty( $request[ 'code' ] ) ) {
117
+			$id               = wc_get_coupon_id_by_code( $request[ 'code' ] );
118
+			$args[ 'post__in' ] = array( $id );
119 119
 		}
120 120
 
121
-		if ( ! empty( $request['search'] ) ) {
122
-			$args['search'] = $request['search'];
123
-			$args['s']      = false;
121
+		if ( ! empty( $request[ 'search' ] ) ) {
122
+			$args[ 'search' ] = $request[ 'search' ];
123
+			$args[ 's' ]      = false;
124 124
 		}
125 125
 
126 126
 		return $args;
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
 	 * @return \WP_Error|\WC_Data
135 135
 	 */
136 136
 	protected function prepare_object_for_database( $request, $creating = false ) {
137
-		$id        = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
137
+		$id        = isset( $request[ 'id' ] ) ? absint( $request[ 'id' ] ) : 0;
138 138
 		$coupon    = new \WC_Coupon( $id );
139 139
 		$schema    = $this->get_item_schema();
140
-		$data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
140
+		$data_keys = array_keys( array_filter( $schema[ 'properties' ], array( $this, 'filter_writable_props' ) ) );
141 141
 
142 142
 		// Validate required POST fields.
143
-		if ( $creating && empty( $request['code'] ) ) {
143
+		if ( $creating && empty( $request[ 'code' ] ) ) {
144 144
 			return new \WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) );
145 145
 		}
146 146
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 					case 'meta_data':
165 165
 						if ( is_array( $value ) ) {
166 166
 							foreach ( $value as $meta ) {
167
-								$coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : 0 );
167
+								$coupon->update_meta_data( $meta[ 'key' ], $meta[ 'value' ], isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : 0 );
168 168
 							}
169 169
 						}
170 170
 						break;
@@ -404,14 +404,14 @@  discard block
 block discarded – undo
404 404
 	public function get_collection_params() {
405 405
 		$params = parent::get_collection_params();
406 406
 
407
-		$params['code'] = array(
407
+		$params[ 'code' ] = array(
408 408
 			'description'       => __( 'Limit result set to resources with a specific code.', 'woocommerce' ),
409 409
 			'type'              => 'string',
410 410
 			'sanitize_callback' => 'sanitize_text_field',
411 411
 			'validate_callback' => 'rest_validate_request_arg',
412 412
 		);
413 413
 
414
-		$params['search'] = array(
414
+		$params[ 'search' ] = array(
415 415
 			'description'       => __( 'Limit results to coupons with codes matching a given string.', 'woocommerce' ),
416 416
 			'type'              => 'string',
417 417
 			'validate_callback' => 'rest_validate_request_arg',
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 	 * @return bool
428 428
 	 */
429 429
 	protected function filter_writable_props( $schema ) {
430
-		return empty( $schema['readonly'] );
430
+		return empty( $schema[ 'readonly' ] );
431 431
 	}
432 432
 
433 433
 	/**
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' ), 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' ), 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' ), 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' ), $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' ), 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' ), 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' ), 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' ), 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' ), 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' ),
441 441
 			'type'              => 'string',
Please login to merge, or discard this patch.
src/Controllers/Version4/CustomerDownloads.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 * @return \WP_Error|boolean
47 47
 	 */
48 48
 	public function get_items_permissions_check( $request ) {
49
-		$customer = get_user_by( 'id', (int) $request['customer_id'] );
49
+		$customer = get_user_by( 'id', (int) $request[ 'customer_id' ] );
50 50
 
51 51
 		if ( ! $customer ) {
52 52
 			return new \WP_Error( 'woocommerce_rest_customer_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
 	 * @return array
67 67
 	 */
68 68
 	public function get_items( $request ) {
69
-		$downloads = wc_get_customer_available_downloads( (int) $request['customer_id'] );
69
+		$downloads = wc_get_customer_available_downloads( (int) $request[ 'customer_id' ] );
70 70
 
71 71
 		$data = array();
72 72
 		foreach ( $downloads as $download_data ) {
73 73
 			$download = $this->prepare_item_for_response( (object) $download_data, $request );
74 74
 			$download = $this->prepare_response_for_collection( $download );
75
-			$data[]   = $download;
75
+			$data[ ]   = $download;
76 76
 		}
77 77
 
78 78
 		return rest_ensure_response( $data );
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @return array
110 110
 	 */
111 111
 	protected function prepare_links( $item, $request ) {
112
-		$base  = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base );
112
+		$base  = str_replace( '(?P<customer_id>[\d]+)', $request[ 'customer_id' ], $this->rest_base );
113 113
 		$links = array(
114 114
 			'collection' => array(
115 115
 				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
Please login to merge, or discard this patch.
src/Controllers/Version4/Settings.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -83,19 +83,19 @@  discard block
 block discarded – undo
83 83
 		foreach ( $groups as $group ) {
84 84
 			$sub_groups = array();
85 85
 			foreach ( $groups as $_group ) {
86
-				if ( ! empty( $_group['parent_id'] ) && $group['id'] === $_group['parent_id'] ) {
87
-					$sub_groups[] = $_group['id'];
86
+				if ( ! empty( $_group[ 'parent_id' ] ) && $group[ 'id' ] === $_group[ 'parent_id' ] ) {
87
+					$sub_groups[ ] = $_group[ 'id' ];
88 88
 				}
89 89
 			}
90
-			$group['sub_groups'] = $sub_groups;
90
+			$group[ 'sub_groups' ] = $sub_groups;
91 91
 
92 92
 			$group = wp_parse_args( $group, $defaults );
93
-			if ( ! is_null( $group['id'] ) && ! is_null( $group['label'] ) ) {
93
+			if ( ! is_null( $group[ 'id' ] ) && ! is_null( $group[ 'label' ] ) ) {
94 94
 				$group_obj  = $this->filter_group( $group );
95 95
 				$group_data = $this->prepare_item_for_response( $group_obj, $request );
96 96
 				$group_data = $this->prepare_response_for_collection( $group_data );
97 97
 
98
-				$filtered_groups[] = $group_data;
98
+				$filtered_groups[ ] = $group_data;
99 99
 			}
100 100
 		}
101 101
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 		$base  = '/' . $this->namespace . '/' . $this->rest_base;
115 115
 		$links = array(
116 116
 			'options' => array(
117
-				'href' => rest_url( trailingslashit( $base ) . $item['id'] ),
117
+				'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] ),
118 118
 			),
119 119
 		);
120 120
 
Please login to merge, or discard this patch.
src/Controllers/Version4/ShippingZoneLocations.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @return \WP_REST_Response|\WP_Error
55 55
 	 */
56 56
 	public function get_items( $request ) {
57
-		$zone = $this->get_zone( (int) $request['id'] );
57
+		$zone = $this->get_zone( (int) $request[ 'id' ] );
58 58
 
59 59
 		if ( is_wp_error( $zone ) ) {
60 60
 			return $zone;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		foreach ( $locations as $location_obj ) {
67 67
 			$location = $this->prepare_item_for_response( (array) $location_obj, $request );
68 68
 			$location = $this->prepare_response_for_collection( $location );
69
-			$data[]   = $location;
69
+			$data[ ]   = $location;
70 70
 		}
71 71
 
72 72
 		return rest_ensure_response( $data );
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @return \WP_REST_Response|\WP_Error
80 80
 	 */
81 81
 	public function update_items( $request ) {
82
-		$zone = $this->get_zone( (int) $request['id'] );
82
+		$zone = $this->get_zone( (int) $request[ 'id' ] );
83 83
 
84 84
 		if ( is_wp_error( $zone ) ) {
85 85
 			return $zone;
@@ -93,18 +93,18 @@  discard block
 block discarded – undo
93 93
 		$locations     = array();
94 94
 
95 95
 		foreach ( (array) $raw_locations as $raw_location ) {
96
-			if ( empty( $raw_location['code'] ) ) {
96
+			if ( empty( $raw_location[ 'code' ] ) ) {
97 97
 				continue;
98 98
 			}
99 99
 
100
-			$type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country';
100
+			$type = ! empty( $raw_location[ 'type' ] ) ? sanitize_text_field( $raw_location[ 'type' ] ) : 'country';
101 101
 
102 102
 			if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) {
103 103
 				continue;
104 104
 			}
105 105
 
106
-			$locations[] = array(
107
-				'code' => sanitize_text_field( $raw_location['code'] ),
106
+			$locations[ ] = array(
107
+				'code' => sanitize_text_field( $raw_location[ 'code' ] ),
108 108
 				'type' => sanitize_text_field( $type ),
109 109
 			);
110 110
 		}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 * @return array
124 124
 	 */
125 125
 	protected function prepare_links( $item, $request ) {
126
-		$base  = '/' . $this->namespace . '/' . $this->rest_base . '/' . $request['id'];
126
+		$base  = '/' . $this->namespace . '/' . $this->rest_base . '/' . $request[ 'id' ];
127 127
 		$links = array(
128 128
 			'collection' => array(
129 129
 				'href' => rest_url( $base . '/locations' ),
Please login to merge, or discard this patch.
src/Controllers/Version4/ShippingZones.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		foreach ( $zones as $zone_obj ) {
125 125
 			$zone   = $this->prepare_item_for_response( $zone_obj, $request );
126 126
 			$zone   = $this->prepare_response_for_collection( $zone );
127
-			$data[] = $zone;
127
+			$data[ ] = $zone;
128 128
 		}
129 129
 
130 130
 		return rest_ensure_response( $data );
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 			return $zone;
210 210
 		}
211 211
 
212
-		$force = $request['force'];
212
+		$force = $request[ 'force' ];
213 213
 
214 214
 		// We don't support trashing for this type, error out.
215 215
 		if ( ! $force ) {
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	 */
239 239
 	protected function get_data_for_response( $object, $request ) {
240 240
 		return array(
241
-			'id'    => (int) $object['id'],
242
-			'name'  => $object['zone_name'],
243
-			'order' => (int) $object['zone_order'],
241
+			'id'    => (int) $object[ 'id' ],
242
+			'name'  => $object[ 'zone_name' ],
243
+			'order' => (int) $object[ 'zone_order' ],
244 244
 		);
245 245
 	}
246 246
 
@@ -255,13 +255,13 @@  discard block
 block discarded – undo
255 255
 		$base  = '/' . $this->namespace . '/' . $this->rest_base;
256 256
 		$links = array(
257 257
 			'self'        => array(
258
-				'href' => rest_url( trailingslashit( $base ) . $item['id'] ),
258
+				'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] ),
259 259
 			),
260 260
 			'collection'  => array(
261 261
 				'href' => rest_url( $base ),
262 262
 			),
263 263
 			'describedby' => array(
264
-				'href' => rest_url( trailingslashit( $base ) . $item['id'] . '/locations' ),
264
+				'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] . '/locations' ),
265 265
 			),
266 266
 		);
267 267
 
Please login to merge, or discard this patch.
src/Controllers/Version4/TaxClasses.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		$tax_classes = array();
94 94
 
95 95
 		// Add standard class.
96
-		$tax_classes[] = array(
96
+		$tax_classes[ ] = array(
97 97
 			'slug' => 'standard',
98 98
 			'name' => __( 'Standard rate', 'woocommerce' ),
99 99
 		);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 		$classes = \WC_Tax::get_tax_classes();
102 102
 
103 103
 		foreach ( $classes as $class ) {
104
-			$tax_classes[] = array(
104
+			$tax_classes[ ] = array(
105 105
 				'slug' => sanitize_title( $class ),
106 106
 				'name' => $class,
107 107
 			);
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		foreach ( $tax_classes as $tax_class ) {
112 112
 			$class  = $this->prepare_item_for_response( $tax_class, $request );
113 113
 			$class  = $this->prepare_response_for_collection( $class );
114
-			$data[] = $class;
114
+			$data[ ] = $class;
115 115
 		}
116 116
 
117 117
 		return rest_ensure_response( $data );
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 		$exists    = false;
128 128
 		$classes   = \WC_Tax::get_tax_classes();
129 129
 		$tax_class = array(
130
-			'slug' => sanitize_title( $request['name'] ),
131
-			'name' => $request['name'],
130
+			'slug' => sanitize_title( $request[ 'name' ] ),
131
+			'name' => $request[ 'name' ],
132 132
 		);
133 133
 
134 134
 		// Check if class exists.
135 135
 		foreach ( $classes as $key => $class ) {
136
-			if ( sanitize_title( $class ) === $tax_class['slug'] ) {
136
+			if ( sanitize_title( $class ) === $tax_class[ 'slug' ] ) {
137 137
 				$exists = true;
138 138
 				break;
139 139
 			}
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		}
146 146
 
147 147
 		// Add the new class.
148
-		$classes[] = $tax_class['name'];
148
+		$classes[ ] = $tax_class[ 'name' ];
149 149
 
150 150
 		update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) );
151 151
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 		$response = $this->prepare_item_for_response( $tax_class, $request );
165 165
 		$response = rest_ensure_response( $response );
166 166
 		$response->set_status( 201 );
167
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'] ) ) );
167
+		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class[ 'slug' ] ) ) );
168 168
 
169 169
 		return $response;
170 170
 	}
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	public function delete_item( $request ) {
179 179
 		global $wpdb;
180 180
 
181
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
181
+		$force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false;
182 182
 
183 183
 		// We don't support trashing for this type, error out.
184 184
 		if ( ! $force ) {
@@ -186,15 +186,15 @@  discard block
 block discarded – undo
186 186
 		}
187 187
 
188 188
 		$tax_class = array(
189
-			'slug' => sanitize_title( $request['slug'] ),
189
+			'slug' => sanitize_title( $request[ 'slug' ] ),
190 190
 			'name' => '',
191 191
 		);
192 192
 		$classes = \WC_Tax::get_tax_classes();
193 193
 		$deleted = false;
194 194
 
195 195
 		foreach ( $classes as $key => $class ) {
196
-			if ( sanitize_title( $class ) === $tax_class['slug'] ) {
197
-				$tax_class['name'] = $class;
196
+			if ( sanitize_title( $class ) === $tax_class[ 'slug' ] ) {
197
+				$tax_class[ 'name' ] = $class;
198 198
 				unset( $classes[ $key ] );
199 199
 				$deleted = true;
200 200
 				break;
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
 					ON rates.tax_rate_id = locations.tax_rate_id
222 222
 				WHERE rates.tax_rate_class = %s
223 223
 				",
224
-				$tax_class['slug']
224
+				$tax_class[ 'slug' ]
225 225
 			)
226 226
 		);
227 227
 
228 228
 		// Delete tax rates in the selected class.
229
-		$wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) );
229
+		$wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class[ 'slug' ] ), array( '%s' ) );
230 230
 
231 231
 		$response = new \WP_REST_Response();
232 232
 		$response->set_data(
Please login to merge, or discard this patch.