Completed
Push — master ( ceae39...0753e3 )
by Mike
254:22 queued 209:15
created
src/RestApi/Version4/Controllers/Data.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Coupons controller class.
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 			array(
36 36
 				array(
37 37
 					'methods'             => \WP_REST_Server::READABLE,
38
-					'callback'            => array( $this, 'get_items' ),
39
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
38
+					'callback'            => array($this, 'get_items'),
39
+					'permission_callback' => array($this, 'get_items_permissions_check'),
40 40
 				),
41
-				'schema' => array( $this, 'get_public_item_schema' ),
41
+				'schema' => array($this, 'get_public_item_schema'),
42 42
 			),
43 43
 			true
44 44
 		);
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 	 * @param  \WP_REST_Request $request Full details about the request.
51 51
 	 * @return \WP_Error|boolean
52 52
 	 */
53
-	public function get_items_permissions_check( $request ) {
54
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
55
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
53
+	public function get_items_permissions_check($request) {
54
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
55
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
56 56
 		}
57 57
 
58 58
 		return true;
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 * @param  \WP_REST_Request $request Full details about the request.
65 65
 	 * @return \WP_Error|boolean
66 66
 	 */
67
-	public function get_item_permissions_check( $request ) {
68
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
69
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
67
+	public function get_item_permissions_check($request) {
68
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
69
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
70 70
 		}
71 71
 
72 72
 		return true;
@@ -79,33 +79,33 @@  discard block
 block discarded – undo
79 79
 	 * @param  \WP_REST_Request $request Request data.
80 80
 	 * @return \WP_Error\WP_REST_Response
81 81
 	 */
82
-	public function get_items( $request ) {
82
+	public function get_items($request) {
83 83
 		$data      = array();
84 84
 		$resources = array(
85 85
 			array(
86 86
 				'slug'        => 'continents',
87
-				'description' => __( 'List of supported continents, countries, and states.', 'woocommerce' ),
87
+				'description' => __('List of supported continents, countries, and states.', 'woocommerce'),
88 88
 			),
89 89
 			array(
90 90
 				'slug'        => 'countries',
91
-				'description' => __( 'List of supported states in a given country.', 'woocommerce' ),
91
+				'description' => __('List of supported states in a given country.', 'woocommerce'),
92 92
 			),
93 93
 			array(
94 94
 				'slug'        => 'currencies',
95
-				'description' => __( 'List of supported currencies.', 'woocommerce' ),
95
+				'description' => __('List of supported currencies.', 'woocommerce'),
96 96
 			),
97 97
 			array(
98 98
 				'slug'        => 'download-ips',
99
-				'description' => __( 'An endpoint used for searching download logs for a specific IP address.', 'woocommerce' ),
99
+				'description' => __('An endpoint used for searching download logs for a specific IP address.', 'woocommerce'),
100 100
 			),
101 101
 		);
102 102
 
103
-		foreach ( $resources as $resource ) {
104
-			$item   = $this->prepare_item_for_response( (object) $resource, $request );
105
-			$data[] = $this->prepare_response_for_collection( $item );
103
+		foreach ($resources as $resource) {
104
+			$item   = $this->prepare_item_for_response((object) $resource, $request);
105
+			$data[] = $this->prepare_response_for_collection($item);
106 106
 		}
107 107
 
108
-		return rest_ensure_response( $data );
108
+		return rest_ensure_response($data);
109 109
 	}
110 110
 
111 111
 	/**
@@ -115,18 +115,18 @@  discard block
 block discarded – undo
115 115
 	 * @param \WP_REST_Request $request  Request object.
116 116
 	 * @return \WP_REST_Response $response Response data.
117 117
 	 */
118
-	public function prepare_item_for_response( $resource, $request ) {
118
+	public function prepare_item_for_response($resource, $request) {
119 119
 		$data = array(
120 120
 			'slug'        => $resource->slug,
121 121
 			'description' => $resource->description,
122 122
 		);
123 123
 
124
-		$data = $this->add_additional_fields_to_object( $data, $request );
125
-		$data = $this->filter_response_by_context( $data, 'view' );
124
+		$data = $this->add_additional_fields_to_object($data, $request);
125
+		$data = $this->filter_response_by_context($data, 'view');
126 126
 
127 127
 		// Wrap the data in a response object.
128
-		$response = rest_ensure_response( $data );
129
-		$response->add_links( $this->prepare_links( $resource ) );
128
+		$response = rest_ensure_response($data);
129
+		$response->add_links($this->prepare_links($resource));
130 130
 
131 131
 		return $response;
132 132
 	}
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
 	 * @param object $item Data object.
138 138
 	 * @return array Links for the given country.
139 139
 	 */
140
-	protected function prepare_links( $item ) {
140
+	protected function prepare_links($item) {
141 141
 		$links = array(
142 142
 			'self'       => array(
143
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug ) ),
143
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug)),
144 144
 			),
145 145
 			'collection' => array(
146
-				'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
146
+				'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)),
147 147
 			),
148 148
 		);
149 149
 
@@ -163,20 +163,20 @@  discard block
 block discarded – undo
163 163
 			'type'       => 'object',
164 164
 			'properties' => array(
165 165
 				'slug'        => array(
166
-					'description' => __( 'Data resource ID.', 'woocommerce' ),
166
+					'description' => __('Data resource ID.', 'woocommerce'),
167 167
 					'type'        => 'string',
168
-					'context'     => array( 'view' ),
168
+					'context'     => array('view'),
169 169
 					'readonly'    => true,
170 170
 				),
171 171
 				'description' => array(
172
-					'description' => __( 'Data resource description.', 'woocommerce' ),
172
+					'description' => __('Data resource description.', 'woocommerce'),
173 173
 					'type'        => 'string',
174
-					'context'     => array( 'view' ),
174
+					'context'     => array('view'),
175 175
 					'readonly'    => true,
176 176
 				),
177 177
 			),
178 178
 		);
179 179
 
180
-		return $this->add_additional_fields_schema( $schema );
180
+		return $this->add_additional_fields_schema($schema);
181 181
 	}
182 182
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/ProductAttributeTerms.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Product Attribute Terms controller class.
@@ -33,32 +33,32 @@  discard block
 block discarded – undo
33 33
 			array(
34 34
 				'args' => array(
35 35
 					'attribute_id' => array(
36
-						'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
36
+						'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'),
37 37
 						'type'        => 'integer',
38 38
 					),
39 39
 				),
40 40
 				array(
41 41
 					'methods'             => \WP_REST_Server::READABLE,
42
-					'callback'            => array( $this, 'get_items' ),
43
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
42
+					'callback'            => array($this, 'get_items'),
43
+					'permission_callback' => array($this, 'get_items_permissions_check'),
44 44
 					'args'                => $this->get_collection_params(),
45 45
 				),
46 46
 				array(
47 47
 					'methods'             => \WP_REST_Server::CREATABLE,
48
-					'callback'            => array( $this, 'create_item' ),
49
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
48
+					'callback'            => array($this, 'create_item'),
49
+					'permission_callback' => array($this, 'create_item_permissions_check'),
50 50
 					'args'                => array_merge(
51
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
51
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
52 52
 						array(
53 53
 							'name' => array(
54 54
 								'type'        => 'string',
55
-								'description' => __( 'Name for the resource.', 'woocommerce' ),
55
+								'description' => __('Name for the resource.', 'woocommerce'),
56 56
 								'required'    => true,
57 57
 							),
58 58
 						)
59 59
 					),
60 60
 				),
61
-				'schema' => array( $this, 'get_public_item_schema' ),
61
+				'schema' => array($this, 'get_public_item_schema'),
62 62
 			),
63 63
 			true
64 64
 		);
@@ -69,41 +69,41 @@  discard block
 block discarded – undo
69 69
 			array(
70 70
 				'args' => array(
71 71
 					'id' => array(
72
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
72
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
73 73
 						'type'        => 'integer',
74 74
 					),
75 75
 					'attribute_id' => array(
76
-						'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
76
+						'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'),
77 77
 						'type'        => 'integer',
78 78
 					),
79 79
 				),
80 80
 				array(
81 81
 					'methods'             => \WP_REST_Server::READABLE,
82
-					'callback'            => array( $this, 'get_item' ),
83
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
82
+					'callback'            => array($this, 'get_item'),
83
+					'permission_callback' => array($this, 'get_item_permissions_check'),
84 84
 					'args'                => array(
85
-						'context'         => $this->get_context_param( array( 'default' => 'view' ) ),
85
+						'context'         => $this->get_context_param(array('default' => 'view')),
86 86
 					),
87 87
 				),
88 88
 				array(
89 89
 					'methods'             => \WP_REST_Server::EDITABLE,
90
-					'callback'            => array( $this, 'update_item' ),
91
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
92
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
90
+					'callback'            => array($this, 'update_item'),
91
+					'permission_callback' => array($this, 'update_item_permissions_check'),
92
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
93 93
 				),
94 94
 				array(
95 95
 					'methods'             => \WP_REST_Server::DELETABLE,
96
-					'callback'            => array( $this, 'delete_item' ),
97
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
96
+					'callback'            => array($this, 'delete_item'),
97
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
98 98
 					'args'                => array(
99 99
 						'force' => array(
100 100
 							'default'     => false,
101 101
 							'type'        => 'boolean',
102
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
102
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
103 103
 						),
104 104
 					),
105 105
 				),
106
-				'schema' => array( $this, 'get_public_item_schema' ),
106
+				'schema' => array($this, 'get_public_item_schema'),
107 107
 			),
108 108
 			true
109 109
 		);
@@ -114,17 +114,17 @@  discard block
 block discarded – undo
114 114
 			array(
115 115
 				'args' => array(
116 116
 					'attribute_id' => array(
117
-						'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
117
+						'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'),
118 118
 						'type'        => 'integer',
119 119
 					),
120 120
 				),
121 121
 				array(
122 122
 					'methods'             => \WP_REST_Server::EDITABLE,
123
-					'callback'            => array( $this, 'batch_items' ),
124
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
125
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
123
+					'callback'            => array($this, 'batch_items'),
124
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
125
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
126 126
 				),
127
-				'schema' => array( $this, 'get_public_batch_schema' ),
127
+				'schema' => array($this, 'get_public_batch_schema'),
128 128
 			),
129 129
 			true
130 130
 		);
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
 	 * @param \WP_REST_Request $request Request params.
138 138
 	 * @return \WP_REST_Response $response
139 139
 	 */
140
-	public function prepare_item_for_response( $item, $request ) {
140
+	public function prepare_item_for_response($item, $request) {
141 141
 		// Get term order.
142
-		$menu_order = get_term_meta( $item->term_id, 'order_' . $this->taxonomy, true );
142
+		$menu_order = get_term_meta($item->term_id, 'order_' . $this->taxonomy, true);
143 143
 
144 144
 		$data = array(
145 145
 			'id'          => (int) $item->term_id,
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 			'count'       => (int) $item->count,
151 151
 		);
152 152
 
153
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
154
-		$data    = $this->add_additional_fields_to_object( $data, $request );
155
-		$data    = $this->filter_response_by_context( $data, $context );
153
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
154
+		$data    = $this->add_additional_fields_to_object($data, $request);
155
+		$data    = $this->filter_response_by_context($data, $context);
156 156
 
157
-		$response = rest_ensure_response( $data );
157
+		$response = rest_ensure_response($data);
158 158
 
159
-		$response->add_links( $this->prepare_links( $item, $request ) );
159
+		$response->add_links($this->prepare_links($item, $request));
160 160
 
161 161
 		/**
162 162
 		 * Filter a term item returned from the API.
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 		 * @param object            $item      The original term object.
168 168
 		 * @param \WP_REST_Request   $request   Request used to generate the response.
169 169
 		 */
170
-		return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request );
170
+		return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
171 171
 	}
172 172
 
173 173
 	/**
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
 	 * @param \WP_REST_Request $request Request params.
178 178
 	 * @return bool|\WP_Error
179 179
 	 */
180
-	protected function update_term_meta_fields( $term, $request ) {
180
+	protected function update_term_meta_fields($term, $request) {
181 181
 		$id = (int) $term->term_id;
182 182
 
183
-		update_term_meta( $id, 'order_' . $this->taxonomy, $request['menu_order'] );
183
+		update_term_meta($id, 'order_' . $this->taxonomy, $request['menu_order']);
184 184
 
185 185
 		return true;
186 186
 	}
@@ -197,49 +197,49 @@  discard block
 block discarded – undo
197 197
 			'type'                 => 'object',
198 198
 			'properties'           => array(
199 199
 				'id' => array(
200
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
200
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
201 201
 					'type'        => 'integer',
202
-					'context'     => array( 'view', 'edit' ),
202
+					'context'     => array('view', 'edit'),
203 203
 					'readonly'    => true,
204 204
 				),
205 205
 				'name' => array(
206
-					'description' => __( 'Term name.', 'woocommerce' ),
206
+					'description' => __('Term name.', 'woocommerce'),
207 207
 					'type'        => 'string',
208
-					'context'     => array( 'view', 'edit' ),
208
+					'context'     => array('view', 'edit'),
209 209
 					'arg_options' => array(
210 210
 						'sanitize_callback' => 'sanitize_text_field',
211 211
 					),
212 212
 				),
213 213
 				'slug' => array(
214
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
214
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
215 215
 					'type'        => 'string',
216
-					'context'     => array( 'view', 'edit' ),
216
+					'context'     => array('view', 'edit'),
217 217
 					'arg_options' => array(
218 218
 						'sanitize_callback' => 'sanitize_title',
219 219
 					),
220 220
 				),
221 221
 				'description' => array(
222
-					'description' => __( 'HTML description of the resource.', 'woocommerce' ),
222
+					'description' => __('HTML description of the resource.', 'woocommerce'),
223 223
 					'type'        => 'string',
224
-					'context'     => array( 'view', 'edit' ),
224
+					'context'     => array('view', 'edit'),
225 225
 					'arg_options' => array(
226 226
 						'sanitize_callback' => 'wp_filter_post_kses',
227 227
 					),
228 228
 				),
229 229
 				'menu_order' => array(
230
-					'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ),
230
+					'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'),
231 231
 					'type'        => 'integer',
232
-					'context'     => array( 'view', 'edit' ),
232
+					'context'     => array('view', 'edit'),
233 233
 				),
234 234
 				'count' => array(
235
-					'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
235
+					'description' => __('Number of published products for the resource.', 'woocommerce'),
236 236
 					'type'        => 'integer',
237
-					'context'     => array( 'view', 'edit' ),
237
+					'context'     => array('view', 'edit'),
238 238
 					'readonly'    => true,
239 239
 				),
240 240
 			),
241 241
 		);
242 242
 
243
-		return $this->add_additional_fields_schema( $schema );
243
+		return $this->add_additional_fields_schema($schema);
244 244
 	}
245 245
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/SettingsOptions.php 1 patch
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Setting Options controller class.
@@ -35,16 +35,16 @@  discard block
 block discarded – undo
35 35
 			array(
36 36
 				'args'   => array(
37 37
 					'group' => array(
38
-						'description' => __( 'Settings group ID.', 'woocommerce' ),
38
+						'description' => __('Settings group ID.', 'woocommerce'),
39 39
 						'type'        => 'string',
40 40
 					),
41 41
 				),
42 42
 				array(
43 43
 					'methods'             => \WP_REST_Server::READABLE,
44
-					'callback'            => array( $this, 'get_items' ),
45
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
44
+					'callback'            => array($this, 'get_items'),
45
+					'permission_callback' => array($this, 'get_items_permissions_check'),
46 46
 				),
47
-				'schema' => array( $this, 'get_public_item_schema' ),
47
+				'schema' => array($this, 'get_public_item_schema'),
48 48
 			),
49 49
 			true
50 50
 		);
@@ -55,17 +55,17 @@  discard block
 block discarded – undo
55 55
 			array(
56 56
 				'args'   => array(
57 57
 					'group' => array(
58
-						'description' => __( 'Settings group ID.', 'woocommerce' ),
58
+						'description' => __('Settings group ID.', 'woocommerce'),
59 59
 						'type'        => 'string',
60 60
 					),
61 61
 				),
62 62
 				array(
63 63
 					'methods'             => \WP_REST_Server::EDITABLE,
64
-					'callback'            => array( $this, 'batch_items' ),
65
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
66
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
64
+					'callback'            => array($this, 'batch_items'),
65
+					'permission_callback' => array($this, 'update_items_permissions_check'),
66
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
67 67
 				),
68
-				'schema' => array( $this, 'get_public_batch_schema' ),
68
+				'schema' => array($this, 'get_public_batch_schema'),
69 69
 			),
70 70
 			true
71 71
 		);
@@ -76,26 +76,26 @@  discard block
 block discarded – undo
76 76
 			array(
77 77
 				'args'   => array(
78 78
 					'group' => array(
79
-						'description' => __( 'Settings group ID.', 'woocommerce' ),
79
+						'description' => __('Settings group ID.', 'woocommerce'),
80 80
 						'type'        => 'string',
81 81
 					),
82 82
 					'id'    => array(
83
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
83
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
84 84
 						'type'        => 'string',
85 85
 					),
86 86
 				),
87 87
 				array(
88 88
 					'methods'             => \WP_REST_Server::READABLE,
89
-					'callback'            => array( $this, 'get_item' ),
90
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
89
+					'callback'            => array($this, 'get_item'),
90
+					'permission_callback' => array($this, 'get_items_permissions_check'),
91 91
 				),
92 92
 				array(
93 93
 					'methods'             => \WP_REST_Server::EDITABLE,
94
-					'callback'            => array( $this, 'update_item' ),
95
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
96
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
94
+					'callback'            => array($this, 'update_item'),
95
+					'permission_callback' => array($this, 'update_items_permissions_check'),
96
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
97 97
 				),
98
-				'schema' => array( $this, 'get_public_item_schema' ),
98
+				'schema' => array($this, 'get_public_item_schema'),
99 99
 			),
100 100
 			true
101 101
 		);
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
 	 * @param  \WP_REST_Request $request Request data.
109 109
 	 * @return \WP_Error\WP_REST_Response
110 110
 	 */
111
-	public function get_item( $request ) {
112
-		$setting = $this->get_setting( $request['group_id'], $request['id'] );
111
+	public function get_item($request) {
112
+		$setting = $this->get_setting($request['group_id'], $request['id']);
113 113
 
114
-		if ( is_wp_error( $setting ) ) {
114
+		if (is_wp_error($setting)) {
115 115
 			return $setting;
116 116
 		}
117 117
 
118
-		$response = $this->prepare_item_for_response( $setting, $request );
118
+		$response = $this->prepare_item_for_response($setting, $request);
119 119
 
120
-		return rest_ensure_response( $response );
120
+		return rest_ensure_response($response);
121 121
 	}
122 122
 
123 123
 	/**
@@ -127,24 +127,24 @@  discard block
 block discarded – undo
127 127
 	 * @param  \WP_REST_Request $request Request data.
128 128
 	 * @return \WP_Error\WP_REST_Response
129 129
 	 */
130
-	public function get_items( $request ) {
131
-		$settings = $this->get_group_settings( $request['group_id'] );
130
+	public function get_items($request) {
131
+		$settings = $this->get_group_settings($request['group_id']);
132 132
 
133
-		if ( is_wp_error( $settings ) ) {
133
+		if (is_wp_error($settings)) {
134 134
 			return $settings;
135 135
 		}
136 136
 
137 137
 		$data = array();
138 138
 
139
-		foreach ( $settings as $setting_obj ) {
140
-			$setting = $this->prepare_item_for_response( $setting_obj, $request );
141
-			$setting = $this->prepare_response_for_collection( $setting );
142
-			if ( $this->is_setting_type_valid( $setting['type'] ) ) {
139
+		foreach ($settings as $setting_obj) {
140
+			$setting = $this->prepare_item_for_response($setting_obj, $request);
141
+			$setting = $this->prepare_response_for_collection($setting);
142
+			if ($this->is_setting_type_valid($setting['type'])) {
143 143
 				$data[] = $setting;
144 144
 			}
145 145
 		}
146 146
 
147
-		return rest_ensure_response( $data );
147
+		return rest_ensure_response($data);
148 148
 	}
149 149
 
150 150
 	/**
@@ -153,39 +153,39 @@  discard block
 block discarded – undo
153 153
 	 * @param string $group_id Group ID.
154 154
 	 * @return array|\WP_Error
155 155
 	 */
156
-	public function get_group_settings( $group_id ) {
157
-		if ( empty( $group_id ) ) {
158
-			return new \WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
156
+	public function get_group_settings($group_id) {
157
+		if (empty($group_id)) {
158
+			return new \WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404));
159 159
 		}
160 160
 
161
-		$settings = apply_filters( 'woocommerce_settings-' . $group_id, array() ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
161
+		$settings = apply_filters('woocommerce_settings-' . $group_id, array()); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
162 162
 
163
-		if ( empty( $settings ) ) {
164
-			return new \WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
163
+		if (empty($settings)) {
164
+			return new \WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404));
165 165
 		}
166 166
 
167 167
 		$filtered_settings = array();
168
-		foreach ( $settings as $setting ) {
168
+		foreach ($settings as $setting) {
169 169
 			$option_key = $setting['option_key'];
170
-			$setting    = $this->filter_setting( $setting );
171
-			$default    = isset( $setting['default'] ) ? $setting['default'] : '';
170
+			$setting    = $this->filter_setting($setting);
171
+			$default    = isset($setting['default']) ? $setting['default'] : '';
172 172
 			// Get the option value.
173
-			if ( is_array( $option_key ) ) {
174
-				$option           = get_option( $option_key[0] );
175
-				$setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default;
173
+			if (is_array($option_key)) {
174
+				$option           = get_option($option_key[0]);
175
+				$setting['value'] = isset($option[$option_key[1]]) ? $option[$option_key[1]] : $default;
176 176
 			} else {
177
-				$admin_setting_value = \WC_Admin_Settings::get_option( $option_key, $default );
177
+				$admin_setting_value = \WC_Admin_Settings::get_option($option_key, $default);
178 178
 				$setting['value']    = $admin_setting_value;
179 179
 			}
180 180
 
181
-			if ( 'multi_select_countries' === $setting['type'] ) {
181
+			if ('multi_select_countries' === $setting['type']) {
182 182
 				$setting['options'] = WC()->countries->get_countries();
183 183
 				$setting['type']    = 'multiselect';
184
-			} elseif ( 'single_select_country' === $setting['type'] ) {
184
+			} elseif ('single_select_country' === $setting['type']) {
185 185
 				$setting['type']    = 'select';
186 186
 				$setting['options'] = $this->get_countries_and_states();
187
-			} elseif ( 'single_select_page' === $setting['type'] ) {
188
-				$pages   = get_pages(
187
+			} elseif ('single_select_page' === $setting['type']) {
188
+				$pages = get_pages(
189 189
 					array(
190 190
 						'sort_column'  => 'menu_order',
191 191
 						'sort_order'   => 'ASC',
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 					)
194 194
 				);
195 195
 				$options = array();
196
-				foreach ( $pages as $page ) {
197
-					$options[ $page->ID ] = ! empty( $page->post_title ) ? $page->post_title : '#' . $page->ID;
196
+				foreach ($pages as $page) {
197
+					$options[$page->ID] = ! empty($page->post_title) ? $page->post_title : '#' . $page->ID;
198 198
 				}
199 199
 				$setting['type']    = 'select';
200 200
 				$setting['options'] = $options;
@@ -214,19 +214,19 @@  discard block
 block discarded – undo
214 214
 	 */
215 215
 	private function get_countries_and_states() {
216 216
 		$countries = WC()->countries->get_countries();
217
-		if ( ! $countries ) {
217
+		if ( ! $countries) {
218 218
 			return array();
219 219
 		}
220 220
 		$output = array();
221
-		foreach ( $countries as $key => $value ) {
222
-			$states = WC()->countries->get_states( $key );
221
+		foreach ($countries as $key => $value) {
222
+			$states = WC()->countries->get_states($key);
223 223
 
224
-			if ( $states ) {
225
-				foreach ( $states as $state_key => $state_value ) {
226
-					$output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value;
224
+			if ($states) {
225
+				foreach ($states as $state_key => $state_value) {
226
+					$output[$key . ':' . $state_key] = $value . ' - ' . $state_value;
227 227
 				}
228 228
 			} else {
229
-				$output[ $key ] = $value;
229
+				$output[$key] = $value;
230 230
 			}
231 231
 		}
232 232
 		return $output;
@@ -240,30 +240,30 @@  discard block
 block discarded – undo
240 240
 	 * @param string $setting_id Setting ID.
241 241
 	 * @return stdClass|\WP_Error
242 242
 	 */
243
-	public function get_setting( $group_id, $setting_id ) {
244
-		if ( empty( $setting_id ) ) {
245
-			return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) );
243
+	public function get_setting($group_id, $setting_id) {
244
+		if (empty($setting_id)) {
245
+			return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404));
246 246
 		}
247 247
 
248
-		$settings = $this->get_group_settings( $group_id );
248
+		$settings = $this->get_group_settings($group_id);
249 249
 
250
-		if ( is_wp_error( $settings ) ) {
250
+		if (is_wp_error($settings)) {
251 251
 			return $settings;
252 252
 		}
253 253
 
254
-		$array_key = array_keys( wp_list_pluck( $settings, 'id' ), $setting_id );
254
+		$array_key = array_keys(wp_list_pluck($settings, 'id'), $setting_id);
255 255
 
256
-		if ( empty( $array_key ) ) {
257
-			return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) );
256
+		if (empty($array_key)) {
257
+			return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404));
258 258
 		}
259 259
 
260
-		$setting = $settings[ $array_key[0] ];
260
+		$setting = $settings[$array_key[0]];
261 261
 
262
-		if ( ! $this->is_setting_type_valid( $setting['type'] ) ) {
263
-			return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) );
262
+		if ( ! $this->is_setting_type_valid($setting['type'])) {
263
+			return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404));
264 264
 		}
265 265
 
266
-		if ( is_wp_error( $setting ) ) {
266
+		if (is_wp_error($setting)) {
267 267
 			return $setting;
268 268
 		}
269 269
 
@@ -279,24 +279,24 @@  discard block
 block discarded – undo
279 279
 	 * @param \WP_REST_Request $request Full details about the request.
280 280
 	 * @return array Of \WP_Error or \WP_REST_Response.
281 281
 	 */
282
-	public function batch_items( $request ) {
282
+	public function batch_items($request) {
283 283
 		// Get the request params.
284
-		$items = array_filter( $request->get_params() );
284
+		$items = array_filter($request->get_params());
285 285
 
286 286
 		/*
287 287
 		 * Since our batch settings update is group-specific and matches based on the route,
288 288
 		 * we inject the URL parameters (containing group) into the batch items
289 289
 		 */
290
-		if ( ! empty( $items['update'] ) ) {
290
+		if ( ! empty($items['update'])) {
291 291
 			$to_update = array();
292
-			foreach ( $items['update'] as $item ) {
293
-				$to_update[] = array_merge( $request->get_url_params(), $item );
292
+			foreach ($items['update'] as $item) {
293
+				$to_update[] = array_merge($request->get_url_params(), $item);
294 294
 			}
295
-			$request = new \WP_REST_Request( $request->get_method() );
296
-			$request->set_body_params( array( 'update' => $to_update ) );
295
+			$request = new \WP_REST_Request($request->get_method());
296
+			$request->set_body_params(array('update' => $to_update));
297 297
 		}
298 298
 
299
-		return parent::batch_items( $request );
299
+		return parent::batch_items($request);
300 300
 	}
301 301
 
302 302
 	/**
@@ -306,39 +306,39 @@  discard block
 block discarded – undo
306 306
 	 * @param  \WP_REST_Request $request Request data.
307 307
 	 * @return \WP_Error\WP_REST_Response
308 308
 	 */
309
-	public function update_item( $request ) {
310
-		$setting = $this->get_setting( $request['group_id'], $request['id'] );
309
+	public function update_item($request) {
310
+		$setting = $this->get_setting($request['group_id'], $request['id']);
311 311
 
312
-		if ( is_wp_error( $setting ) ) {
312
+		if (is_wp_error($setting)) {
313 313
 			return $setting;
314 314
 		}
315 315
 
316
-		if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) {
317
-			$value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting );
316
+		if (is_callable(array($this, 'validate_setting_' . $setting['type'] . '_field'))) {
317
+			$value = $this->{'validate_setting_' . $setting['type'] . '_field'}($request['value'], $setting);
318 318
 		} else {
319
-			$value = $this->validate_setting_text_field( $request['value'], $setting );
319
+			$value = $this->validate_setting_text_field($request['value'], $setting);
320 320
 		}
321 321
 
322
-		if ( is_wp_error( $value ) ) {
322
+		if (is_wp_error($value)) {
323 323
 			return $value;
324 324
 		}
325 325
 
326
-		if ( is_array( $setting['option_key'] ) ) {
326
+		if (is_array($setting['option_key'])) {
327 327
 			$setting['value']       = $value;
328 328
 			$option_key             = $setting['option_key'];
329
-			$prev                   = get_option( $option_key[0] );
330
-			$prev[ $option_key[1] ] = $request['value'];
331
-			update_option( $option_key[0], $prev );
329
+			$prev                   = get_option($option_key[0]);
330
+			$prev[$option_key[1]] = $request['value'];
331
+			update_option($option_key[0], $prev);
332 332
 		} else {
333 333
 			$update_data                           = array();
334
-			$update_data[ $setting['option_key'] ] = $value;
334
+			$update_data[$setting['option_key']] = $value;
335 335
 			$setting['value']                      = $value;
336
-			\WC_Admin_Settings::save_fields( array( $setting ), $update_data );
336
+			\WC_Admin_Settings::save_fields(array($setting), $update_data);
337 337
 		}
338 338
 
339
-		$response = $this->prepare_item_for_response( $setting, $request );
339
+		$response = $this->prepare_item_for_response($setting, $request);
340 340
 
341
-		return rest_ensure_response( $response );
341
+		return rest_ensure_response($response);
342 342
 	}
343 343
 
344 344
 	/**
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 	 * @param \WP_REST_Request $request Request object.
350 350
 	 * @return \WP_REST_Response $response Response data.
351 351
 	 */
352
-	public function prepare_item_for_response( $item, $request ) {
353
-		unset( $item['option_key'] );
354
-		$data     = $this->filter_setting( $item );
355
-		$data     = $this->add_additional_fields_to_object( $data, $request );
356
-		$data     = $this->filter_response_by_context( $data, empty( $request['context'] ) ? 'view' : $request['context'] );
357
-		$response = rest_ensure_response( $data );
358
-		$response->add_links( $this->prepare_links( $data['id'], $request['group_id'] ) );
352
+	public function prepare_item_for_response($item, $request) {
353
+		unset($item['option_key']);
354
+		$data     = $this->filter_setting($item);
355
+		$data     = $this->add_additional_fields_to_object($data, $request);
356
+		$data     = $this->filter_response_by_context($data, empty($request['context']) ? 'view' : $request['context']);
357
+		$response = rest_ensure_response($data);
358
+		$response->add_links($this->prepare_links($data['id'], $request['group_id']));
359 359
 		return $response;
360 360
 	}
361 361
 
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
 	 * @param string $group_id Group ID.
368 368
 	 * @return array Links for the given setting.
369 369
 	 */
370
-	protected function prepare_links( $setting_id, $group_id ) {
371
-		$base  = str_replace( '(?P<group_id>[\w-]+)', $group_id, $this->rest_base );
370
+	protected function prepare_links($setting_id, $group_id) {
371
+		$base  = str_replace('(?P<group_id>[\w-]+)', $group_id, $this->rest_base);
372 372
 		$links = array(
373 373
 			'self'       => array(
374
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $setting_id ) ),
374
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $base, $setting_id)),
375 375
 			),
376 376
 			'collection' => array(
377
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
377
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)),
378 378
 			),
379 379
 		);
380 380
 
@@ -388,9 +388,9 @@  discard block
 block discarded – undo
388 388
 	 * @param \WP_REST_Request $request Full data about the request.
389 389
 	 * @return \WP_Error|boolean
390 390
 	 */
391
-	public function get_items_permissions_check( $request ) {
392
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
393
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
391
+	public function get_items_permissions_check($request) {
392
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
393
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
394 394
 		}
395 395
 
396 396
 		return true;
@@ -403,9 +403,9 @@  discard block
 block discarded – undo
403 403
 	 * @param \WP_REST_Request $request Full data about the request.
404 404
 	 * @return \WP_Error|boolean
405 405
 	 */
406
-	public function update_items_permissions_check( $request ) {
407
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
408
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
406
+	public function update_items_permissions_check($request) {
407
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
408
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
409 409
 		}
410 410
 
411 411
 		return true;
@@ -419,18 +419,18 @@  discard block
 block discarded – undo
419 419
 	 * @param  array $setting Settings.
420 420
 	 * @return array
421 421
 	 */
422
-	public function filter_setting( $setting ) {
422
+	public function filter_setting($setting) {
423 423
 		$setting = array_intersect_key(
424 424
 			$setting,
425
-			array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) )
425
+			array_flip(array_filter(array_keys($setting), array($this, 'allowed_setting_keys')))
426 426
 		);
427 427
 
428
-		if ( empty( $setting['options'] ) ) {
429
-			unset( $setting['options'] );
428
+		if (empty($setting['options'])) {
429
+			unset($setting['options']);
430 430
 		}
431 431
 
432
-		if ( 'image_width' === $setting['type'] ) {
433
-			$setting = $this->cast_image_width( $setting );
432
+		if ('image_width' === $setting['type']) {
433
+			$setting = $this->cast_image_width($setting);
434 434
 		}
435 435
 
436 436
 		return $setting;
@@ -445,12 +445,12 @@  discard block
 block discarded – undo
445 445
 	 * @param  array $setting Settings.
446 446
 	 * @return array
447 447
 	 */
448
-	public function cast_image_width( $setting ) {
449
-		foreach ( array( 'default', 'value' ) as $key ) {
450
-			if ( isset( $setting[ $key ] ) ) {
451
-				$setting[ $key ]['width']  = intval( $setting[ $key ]['width'] );
452
-				$setting[ $key ]['height'] = intval( $setting[ $key ]['height'] );
453
-				$setting[ $key ]['crop']   = (bool) $setting[ $key ]['crop'];
448
+	public function cast_image_width($setting) {
449
+		foreach (array('default', 'value') as $key) {
450
+			if (isset($setting[$key])) {
451
+				$setting[$key]['width']  = intval($setting[$key]['width']);
452
+				$setting[$key]['height'] = intval($setting[$key]['height']);
453
+				$setting[$key]['crop']   = (bool) $setting[$key]['crop'];
454 454
 			}
455 455
 		}
456 456
 		return $setting;
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 	 * @param  string $key Key to check.
463 463
 	 * @return boolean
464 464
 	 */
465
-	public function allowed_setting_keys( $key ) {
465
+	public function allowed_setting_keys($key) {
466 466
 		return in_array(
467 467
 			$key, array(
468 468
 				'id',
@@ -487,20 +487,20 @@  discard block
 block discarded – undo
487 487
 	 * @param  string $type Type.
488 488
 	 * @return bool
489 489
 	 */
490
-	public function is_setting_type_valid( $type ) {
490
+	public function is_setting_type_valid($type) {
491 491
 		return in_array(
492 492
 			$type, array(
493
-				'text',         // Validates with validate_setting_text_field.
494
-				'email',        // Validates with validate_setting_text_field.
495
-				'number',       // Validates with validate_setting_text_field.
496
-				'color',        // Validates with validate_setting_text_field.
497
-				'password',     // Validates with validate_setting_text_field.
498
-				'textarea',     // Validates with validate_setting_textarea_field.
499
-				'select',       // Validates with validate_setting_select_field.
500
-				'multiselect',  // Validates with validate_setting_multiselect_field.
501
-				'radio',        // Validates with validate_setting_radio_field (-> validate_setting_select_field).
502
-				'checkbox',     // Validates with validate_setting_checkbox_field.
503
-				'image_width',  // Validates with validate_setting_image_width_field.
493
+				'text', // Validates with validate_setting_text_field.
494
+				'email', // Validates with validate_setting_text_field.
495
+				'number', // Validates with validate_setting_text_field.
496
+				'color', // Validates with validate_setting_text_field.
497
+				'password', // Validates with validate_setting_text_field.
498
+				'textarea', // Validates with validate_setting_textarea_field.
499
+				'select', // Validates with validate_setting_select_field.
500
+				'multiselect', // Validates with validate_setting_multiselect_field.
501
+				'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field).
502
+				'checkbox', // Validates with validate_setting_checkbox_field.
503
+				'image_width', // Validates with validate_setting_image_width_field.
504 504
 				'thumbnail_cropping', // Validates with validate_setting_text_field.
505 505
 			)
506 506
 		);
@@ -518,89 +518,89 @@  discard block
 block discarded – undo
518 518
 			'type'       => 'object',
519 519
 			'properties' => array(
520 520
 				'id'          => array(
521
-					'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
521
+					'description' => __('A unique identifier for the setting.', 'woocommerce'),
522 522
 					'type'        => 'string',
523 523
 					'arg_options' => array(
524 524
 						'sanitize_callback' => 'sanitize_title',
525 525
 					),
526
-					'context'     => array( 'view', 'edit' ),
526
+					'context'     => array('view', 'edit'),
527 527
 					'readonly'    => true,
528 528
 				),
529 529
 				'group_id'    => array(
530
-					'description' => __( 'An identifier for the group this setting belongs to.', 'woocommerce' ),
530
+					'description' => __('An identifier for the group this setting belongs to.', 'woocommerce'),
531 531
 					'type'        => 'string',
532 532
 					'arg_options' => array(
533 533
 						'sanitize_callback' => 'sanitize_title',
534 534
 					),
535
-					'context'     => array( 'view', 'edit' ),
535
+					'context'     => array('view', 'edit'),
536 536
 					'readonly'    => true,
537 537
 				),
538 538
 				'label'       => array(
539
-					'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
539
+					'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'),
540 540
 					'type'        => 'string',
541 541
 					'arg_options' => array(
542 542
 						'sanitize_callback' => 'sanitize_text_field',
543 543
 					),
544
-					'context'     => array( 'view', 'edit' ),
544
+					'context'     => array('view', 'edit'),
545 545
 					'readonly'    => true,
546 546
 				),
547 547
 				'description' => array(
548
-					'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
548
+					'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'),
549 549
 					'type'        => 'string',
550 550
 					'arg_options' => array(
551 551
 						'sanitize_callback' => 'sanitize_text_field',
552 552
 					),
553
-					'context'     => array( 'view', 'edit' ),
553
+					'context'     => array('view', 'edit'),
554 554
 					'readonly'    => true,
555 555
 				),
556 556
 				'value'       => array(
557
-					'description' => __( 'Setting value.', 'woocommerce' ),
557
+					'description' => __('Setting value.', 'woocommerce'),
558 558
 					'type'        => 'mixed',
559
-					'context'     => array( 'view', 'edit' ),
559
+					'context'     => array('view', 'edit'),
560 560
 				),
561 561
 				'default'     => array(
562
-					'description' => __( 'Default value for the setting.', 'woocommerce' ),
562
+					'description' => __('Default value for the setting.', 'woocommerce'),
563 563
 					'type'        => 'mixed',
564
-					'context'     => array( 'view', 'edit' ),
564
+					'context'     => array('view', 'edit'),
565 565
 					'readonly'    => true,
566 566
 				),
567 567
 				'tip'         => array(
568
-					'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
568
+					'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'),
569 569
 					'type'        => 'string',
570 570
 					'arg_options' => array(
571 571
 						'sanitize_callback' => 'sanitize_text_field',
572 572
 					),
573
-					'context'     => array( 'view', 'edit' ),
573
+					'context'     => array('view', 'edit'),
574 574
 					'readonly'    => true,
575 575
 				),
576 576
 				'placeholder' => array(
577
-					'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
577
+					'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'),
578 578
 					'type'        => 'string',
579 579
 					'arg_options' => array(
580 580
 						'sanitize_callback' => 'sanitize_text_field',
581 581
 					),
582
-					'context'     => array( 'view', 'edit' ),
582
+					'context'     => array('view', 'edit'),
583 583
 					'readonly'    => true,
584 584
 				),
585 585
 				'type'        => array(
586
-					'description' => __( 'Type of setting.', 'woocommerce' ),
586
+					'description' => __('Type of setting.', 'woocommerce'),
587 587
 					'type'        => 'string',
588 588
 					'arg_options' => array(
589 589
 						'sanitize_callback' => 'sanitize_text_field',
590 590
 					),
591
-					'context'     => array( 'view', 'edit' ),
592
-					'enum'        => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
591
+					'context'     => array('view', 'edit'),
592
+					'enum'        => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'),
593 593
 					'readonly'    => true,
594 594
 				),
595 595
 				'options'     => array(
596
-					'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ),
596
+					'description' => __('Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce'),
597 597
 					'type'        => 'object',
598
-					'context'     => array( 'view', 'edit' ),
598
+					'context'     => array('view', 'edit'),
599 599
 					'readonly'    => true,
600 600
 				),
601 601
 			),
602 602
 		);
603 603
 
604
-		return $this->add_additional_fields_schema( $schema );
604
+		return $this->add_additional_fields_schema($schema);
605 605
 	}
606 606
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/ShippingZoneLocations.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Shipping Zone Locations class.
@@ -26,22 +26,22 @@  discard block
 block discarded – undo
26 26
 			array(
27 27
 				'args'   => array(
28 28
 					'id' => array(
29
-						'description' => __( 'Unique ID for the resource.', 'woocommerce' ),
29
+						'description' => __('Unique ID for the resource.', 'woocommerce'),
30 30
 						'type'        => 'integer',
31 31
 					),
32 32
 				),
33 33
 				array(
34 34
 					'methods'             => \WP_REST_Server::READABLE,
35
-					'callback'            => array( $this, 'get_items' ),
36
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
35
+					'callback'            => array($this, 'get_items'),
36
+					'permission_callback' => array($this, 'get_items_permissions_check'),
37 37
 				),
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::EDITABLE,
40
-					'callback'            => array( $this, 'update_items' ),
41
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
42
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
40
+					'callback'            => array($this, 'update_items'),
41
+					'permission_callback' => array($this, 'update_items_permissions_check'),
42
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
43 43
 				),
44
-				'schema' => array( $this, 'get_public_item_schema' ),
44
+				'schema' => array($this, 'get_public_item_schema'),
45 45
 			),
46 46
 			true
47 47
 		);
@@ -53,23 +53,23 @@  discard block
 block discarded – undo
53 53
 	 * @param \WP_REST_Request $request Request data.
54 54
 	 * @return \WP_REST_Response|\WP_Error
55 55
 	 */
56
-	public function get_items( $request ) {
57
-		$zone = $this->get_zone( (int) $request['id'] );
56
+	public function get_items($request) {
57
+		$zone = $this->get_zone((int) $request['id']);
58 58
 
59
-		if ( is_wp_error( $zone ) ) {
59
+		if (is_wp_error($zone)) {
60 60
 			return $zone;
61 61
 		}
62 62
 
63 63
 		$locations = $zone->get_zone_locations();
64 64
 		$data      = array();
65 65
 
66
-		foreach ( $locations as $location_obj ) {
67
-			$location = $this->prepare_item_for_response( $location_obj, $request );
68
-			$location = $this->prepare_response_for_collection( $location );
66
+		foreach ($locations as $location_obj) {
67
+			$location = $this->prepare_item_for_response($location_obj, $request);
68
+			$location = $this->prepare_response_for_collection($location);
69 69
 			$data[]   = $location;
70 70
 		}
71 71
 
72
-		return rest_ensure_response( $data );
72
+		return rest_ensure_response($data);
73 73
 	}
74 74
 
75 75
 	/**
@@ -78,41 +78,41 @@  discard block
 block discarded – undo
78 78
 	 * @param \WP_REST_Request $request Request data.
79 79
 	 * @return \WP_REST_Response|\WP_Error
80 80
 	 */
81
-	public function update_items( $request ) {
82
-		$zone = $this->get_zone( (int) $request['id'] );
81
+	public function update_items($request) {
82
+		$zone = $this->get_zone((int) $request['id']);
83 83
 
84
-		if ( is_wp_error( $zone ) ) {
84
+		if (is_wp_error($zone)) {
85 85
 			return $zone;
86 86
 		}
87 87
 
88
-		if ( 0 === $zone->get_id() ) {
89
-			return new \WP_Error( 'woocommerce_rest_shipping_zone_locations_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) );
88
+		if (0 === $zone->get_id()) {
89
+			return new \WP_Error('woocommerce_rest_shipping_zone_locations_invalid_zone', __('The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce'), array('status' => 403));
90 90
 		}
91 91
 
92 92
 		$raw_locations = $request->get_json_params();
93 93
 		$locations     = array();
94 94
 
95
-		foreach ( (array) $raw_locations as $raw_location ) {
96
-			if ( empty( $raw_location['code'] ) ) {
95
+		foreach ((array) $raw_locations as $raw_location) {
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
-			if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) {
102
+			if ( ! in_array($type, array('postcode', 'state', 'country', 'continent'), true)) {
103 103
 				continue;
104 104
 			}
105 105
 
106 106
 			$locations[] = array(
107
-				'code' => sanitize_text_field( $raw_location['code'] ),
108
-				'type' => sanitize_text_field( $type ),
107
+				'code' => sanitize_text_field($raw_location['code']),
108
+				'type' => sanitize_text_field($type),
109 109
 			);
110 110
 		}
111 111
 
112
-		$zone->set_locations( $locations );
112
+		$zone->set_locations($locations);
113 113
 		$zone->save();
114 114
 
115
-		return $this->get_items( $request );
115
+		return $this->get_items($request);
116 116
 	}
117 117
 
118 118
 	/**
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 	 * @param \WP_REST_Request $request Request object.
123 123
 	 * @return \WP_REST_Response $response
124 124
 	 */
125
-	public function prepare_item_for_response( $item, $request ) {
126
-		$context = empty( $request['context'] ) ? 'view' : $request['context'];
127
-		$data    = $this->add_additional_fields_to_object( $item, $request );
128
-		$data    = $this->filter_response_by_context( $data, $context );
125
+	public function prepare_item_for_response($item, $request) {
126
+		$context = empty($request['context']) ? 'view' : $request['context'];
127
+		$data    = $this->add_additional_fields_to_object($item, $request);
128
+		$data    = $this->filter_response_by_context($data, $context);
129 129
 
130 130
 		// Wrap the data in a response object.
131
-		$response = rest_ensure_response( $data );
131
+		$response = rest_ensure_response($data);
132 132
 
133
-		$response->add_links( $this->prepare_links( (int) $request['id'] ) );
133
+		$response->add_links($this->prepare_links((int) $request['id']));
134 134
 
135 135
 		return $response;
136 136
 	}
@@ -141,14 +141,14 @@  discard block
 block discarded – undo
141 141
 	 * @param int $zone_id Given Shipping Zone ID.
142 142
 	 * @return array Links for the given Shipping Zone Location.
143 143
 	 */
144
-	protected function prepare_links( $zone_id ) {
144
+	protected function prepare_links($zone_id) {
145 145
 		$base  = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id;
146 146
 		$links = array(
147 147
 			'collection' => array(
148
-				'href' => rest_url( $base . '/locations' ),
148
+				'href' => rest_url($base . '/locations'),
149 149
 			),
150 150
 			'describes'  => array(
151
-				'href' => rest_url( $base ),
151
+				'href' => rest_url($base),
152 152
 			),
153 153
 		);
154 154
 
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
 			'type'       => 'object',
168 168
 			'properties' => array(
169 169
 				'code' => array(
170
-					'description' => __( 'Shipping zone location code.', 'woocommerce' ),
170
+					'description' => __('Shipping zone location code.', 'woocommerce'),
171 171
 					'type'        => 'string',
172
-					'context'     => array( 'view', 'edit' ),
172
+					'context'     => array('view', 'edit'),
173 173
 				),
174 174
 				'type' => array(
175
-					'description' => __( 'Shipping zone location type.', 'woocommerce' ),
175
+					'description' => __('Shipping zone location type.', 'woocommerce'),
176 176
 					'type'        => 'string',
177 177
 					'default'     => 'country',
178 178
 					'enum'        => array(
@@ -181,11 +181,11 @@  discard block
 block discarded – undo
181 181
 						'country',
182 182
 						'continent',
183 183
 					),
184
-					'context'     => array( 'view', 'edit' ),
184
+					'context'     => array('view', 'edit'),
185 185
 				),
186 186
 			),
187 187
 		);
188 188
 
189
-		return $this->add_additional_fields_schema( $schema );
189
+		return $this->add_additional_fields_schema($schema);
190 190
 	}
191 191
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Reports.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API reports controller class.
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 			array(
34 34
 				array(
35 35
 					'methods'             => \WP_REST_Server::READABLE,
36
-					'callback'            => array( $this, 'get_items' ),
37
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
36
+					'callback'            => array($this, 'get_items'),
37
+					'permission_callback' => array($this, 'get_items_permissions_check'),
38 38
 					'args'                => $this->get_collection_params(),
39 39
 				),
40
-				'schema' => array( $this, 'get_public_item_schema' ),
40
+				'schema' => array($this, 'get_public_item_schema'),
41 41
 			),
42 42
 			true
43 43
 		);
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	 * @param  \WP_REST_Request $request Full details about the request.
50 50
 	 * @return \WP_Error|boolean
51 51
 	 */
52
-	public function get_items_permissions_check( $request ) {
53
-		if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) {
54
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
52
+	public function get_items_permissions_check($request) {
53
+		if ( ! wc_rest_check_manager_permissions('reports', 'read')) {
54
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
55 55
 		}
56 56
 
57 57
 		return true;
@@ -64,66 +64,66 @@  discard block
 block discarded – undo
64 64
 	 * @param \WP_REST_Request $request Request data.
65 65
 	 * @return array|\WP_Error
66 66
 	 */
67
-	public function get_items( $request ) {
67
+	public function get_items($request) {
68 68
 		$data    = [];
69 69
 		$reports = [];
70
-		if ( class_exists( 'WC_Admin_Reports_Sync' ) ) {
70
+		if (class_exists('WC_Admin_Reports_Sync')) {
71 71
 			$reports = array(
72 72
 				array(
73 73
 					'slug'        => 'performance-indicators',
74
-					'description' => __( 'Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce' ),
74
+					'description' => __('Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce'),
75 75
 				),
76 76
 				array(
77 77
 					'slug'        => 'revenue/stats',
78
-					'description' => __( 'Stats about revenue.', 'woocommerce' ),
78
+					'description' => __('Stats about revenue.', 'woocommerce'),
79 79
 				),
80 80
 				array(
81 81
 					'slug'        => 'orders/stats',
82
-					'description' => __( 'Stats about orders.', 'woocommerce' ),
82
+					'description' => __('Stats about orders.', 'woocommerce'),
83 83
 				),
84 84
 				array(
85 85
 					'slug'        => 'products',
86
-					'description' => __( 'Products detailed reports.', 'woocommerce' ),
86
+					'description' => __('Products detailed reports.', 'woocommerce'),
87 87
 				),
88 88
 				array(
89 89
 					'slug'        => 'products/stats',
90
-					'description' => __( 'Stats about products.', 'woocommerce' ),
90
+					'description' => __('Stats about products.', 'woocommerce'),
91 91
 				),
92 92
 				array(
93 93
 					'slug'        => 'categories',
94
-					'description' => __( 'Product categories detailed reports.', 'woocommerce' ),
94
+					'description' => __('Product categories detailed reports.', 'woocommerce'),
95 95
 				),
96 96
 				array(
97 97
 					'slug'        => 'categories/stats',
98
-					'description' => __( 'Stats about product categories.', 'woocommerce' ),
98
+					'description' => __('Stats about product categories.', 'woocommerce'),
99 99
 				),
100 100
 				array(
101 101
 					'slug'        => 'coupons',
102
-					'description' => __( 'Coupons detailed reports.', 'woocommerce' ),
102
+					'description' => __('Coupons detailed reports.', 'woocommerce'),
103 103
 				),
104 104
 				array(
105 105
 					'slug'        => 'coupons/stats',
106
-					'description' => __( 'Stats about coupons.', 'woocommerce' ),
106
+					'description' => __('Stats about coupons.', 'woocommerce'),
107 107
 				),
108 108
 				array(
109 109
 					'slug'        => 'taxes',
110
-					'description' => __( 'Taxes detailed reports.', 'woocommerce' ),
110
+					'description' => __('Taxes detailed reports.', 'woocommerce'),
111 111
 				),
112 112
 				array(
113 113
 					'slug'        => 'taxes/stats',
114
-					'description' => __( 'Stats about taxes.', 'woocommerce' ),
114
+					'description' => __('Stats about taxes.', 'woocommerce'),
115 115
 				),
116 116
 				array(
117 117
 					'slug'        => 'downloads',
118
-					'description' => __( 'Product downloads detailed reports.', 'woocommerce' ),
118
+					'description' => __('Product downloads detailed reports.', 'woocommerce'),
119 119
 				),
120 120
 				array(
121 121
 					'slug'        => 'downloads/stats',
122
-					'description' => __( 'Stats about product downloads.', 'woocommerce' ),
122
+					'description' => __('Stats about product downloads.', 'woocommerce'),
123 123
 				),
124 124
 				array(
125 125
 					'slug'        => 'customers',
126
-					'description' => __( 'Customers detailed reports.', 'woocommerce' ),
126
+					'description' => __('Customers detailed reports.', 'woocommerce'),
127 127
 				),
128 128
 			);
129 129
 		}
@@ -135,22 +135,22 @@  discard block
 block discarded – undo
135 135
 		 *
136 136
 		 * @param array $endpoints The list of allowed reports..
137 137
 		 */
138
-		$reports = apply_filters( 'woocommerce_admin_reports', $reports );
138
+		$reports = apply_filters('woocommerce_admin_reports', $reports);
139 139
 
140
-		foreach ( $reports as $report ) {
141
-			if ( empty( $report['slug'] ) ) {
140
+		foreach ($reports as $report) {
141
+			if (empty($report['slug'])) {
142 142
 				continue;
143 143
 			}
144 144
 
145
-			if ( empty( $report['path'] ) ) {
145
+			if (empty($report['path'])) {
146 146
 				$report['path'] = '/' . $this->namespace . '/reports/' . $report['slug'];
147 147
 			}
148 148
 
149 149
 			// Allows a different admin page to be loaded here,
150 150
 			// or allows an empty url if no report exists for a set of performance indicators.
151
-			if ( ! isset( $report['url'] ) ) {
152
-				if ( '/stats' === substr( $report['slug'], -6 ) ) {
153
-					$url_slug = substr( $report['slug'], 0, -6 );
151
+			if ( ! isset($report['url'])) {
152
+				if ('/stats' === substr($report['slug'], -6)) {
153
+					$url_slug = substr($report['slug'], 0, -6);
154 154
 				} else {
155 155
 					$url_slug = $report['slug'];
156 156
 				}
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
 				$report['url'] = '/analytics/' . $url_slug;
159 159
 			}
160 160
 
161
-			$item   = $this->prepare_item_for_response( (object) $report, $request );
162
-			$data[] = $this->prepare_response_for_collection( $item );
161
+			$item   = $this->prepare_item_for_response((object) $report, $request);
162
+			$data[] = $this->prepare_response_for_collection($item);
163 163
 		}
164 164
 
165
-		return rest_ensure_response( $data );
165
+		return rest_ensure_response($data);
166 166
 	}
167 167
 
168 168
 	/**
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 	 * @param  int $order_id Order ID.
173 173
 	 * @return string
174 174
 	 */
175
-	public function get_order_number( $order_id ) {
176
-		$order = wc_get_order( $order_id );
175
+	public function get_order_number($order_id) {
176
+		$order = wc_get_order($order_id);
177 177
 
178
-		if ( 'shop_order_refund' === $order->get_type() ) {
179
-			$order = wc_get_order( $order->get_parent_id() );
178
+		if ('shop_order_refund' === $order->get_type()) {
179
+			$order = wc_get_order($order->get_parent_id());
180 180
 		}
181 181
 
182
-		if ( ! has_filter( 'woocommerce_order_number' ) ) {
182
+		if ( ! has_filter('woocommerce_order_number')) {
183 183
 			return $order->get_id();
184 184
 		}
185 185
 
@@ -193,29 +193,29 @@  discard block
 block discarded – undo
193 193
 	 * @param \WP_REST_Request $request Request object.
194 194
 	 * @return \WP_REST_Response
195 195
 	 */
196
-	public function prepare_item_for_response( $report, $request ) {
196
+	public function prepare_item_for_response($report, $request) {
197 197
 		$data = array(
198 198
 			'slug'        => $report->slug,
199 199
 			'description' => $report->description,
200 200
 			'path'        => $report->path,
201 201
 		);
202 202
 
203
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
204
-		$data    = $this->add_additional_fields_to_object( $data, $request );
205
-		$data    = $this->filter_response_by_context( $data, $context );
203
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
204
+		$data    = $this->add_additional_fields_to_object($data, $request);
205
+		$data    = $this->filter_response_by_context($data, $context);
206 206
 
207 207
 		// Wrap the data in a response object.
208
-		$response = rest_ensure_response( $data );
208
+		$response = rest_ensure_response($data);
209 209
 		$response->add_links(
210 210
 			array(
211 211
 				'self'       => array(
212
-					'href' => rest_url( $report->path ),
212
+					'href' => rest_url($report->path),
213 213
 				),
214 214
 				'report'     => array(
215 215
 					'href' => $report->url,
216 216
 				),
217 217
 				'collection' => array(
218
-					'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
218
+					'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)),
219 219
 				),
220 220
 			)
221 221
 		);
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		 * @param object           $report   The original report object.
230 230
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
231 231
 		 */
232
-		return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request );
232
+		return apply_filters('woocommerce_rest_prepare_report', $response, $report, $request);
233 233
 	}
234 234
 
235 235
 	/**
@@ -244,27 +244,27 @@  discard block
 block discarded – undo
244 244
 			'type'       => 'object',
245 245
 			'properties' => array(
246 246
 				'slug'        => array(
247
-					'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
247
+					'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'),
248 248
 					'type'        => 'string',
249
-					'context'     => array( 'view' ),
249
+					'context'     => array('view'),
250 250
 					'readonly'    => true,
251 251
 				),
252 252
 				'description' => array(
253
-					'description' => __( 'A human-readable description of the resource.', 'woocommerce' ),
253
+					'description' => __('A human-readable description of the resource.', 'woocommerce'),
254 254
 					'type'        => 'string',
255
-					'context'     => array( 'view' ),
255
+					'context'     => array('view'),
256 256
 					'readonly'    => true,
257 257
 				),
258 258
 				'path'        => array(
259
-					'description' => __( 'API path.', 'woocommerce' ),
259
+					'description' => __('API path.', 'woocommerce'),
260 260
 					'type'        => 'string',
261
-					'context'     => array( 'view' ),
261
+					'context'     => array('view'),
262 262
 					'readonly'    => true,
263 263
 				),
264 264
 			),
265 265
 		);
266 266
 
267
-		return $this->add_additional_fields_schema( $schema );
267
+		return $this->add_additional_fields_schema($schema);
268 268
 	}
269 269
 
270 270
 	/**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 */
275 275
 	public function get_collection_params() {
276 276
 		return array(
277
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
277
+			'context' => $this->get_context_param(array('default' => 'view')),
278 278
 		);
279 279
 	}
280 280
 
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 	public function get_order_statuses() {
287 287
 		$order_statuses = array();
288 288
 
289
-		foreach ( array_keys( wc_get_order_statuses() ) as $status ) {
290
-			$order_statuses[] = str_replace( 'wc-', '', $status );
289
+		foreach (array_keys(wc_get_order_statuses()) as $status) {
290
+			$order_statuses[] = str_replace('wc-', '', $status);
291 291
 		}
292 292
 
293 293
 		return $order_statuses;
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/AbstractShippingZonesController.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
 namespace WooCommerce\RestApi\Version4\Controllers;
12 12
 
13
-defined( 'ABSPATH' ) || exit;
13
+defined('ABSPATH') || exit;
14 14
 
15 15
 /**
16 16
  * REST API Shipping Zones base class.
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * @param int $zone_id Shipping Zone ID.
34 34
 	 * @return WC_Shipping_Zone|\WP_Error
35 35
 	 */
36
-	protected function get_zone( $zone_id ) {
37
-		$zone = \WC_Shipping_Zones::get_zone_by( 'zone_id', $zone_id );
36
+	protected function get_zone($zone_id) {
37
+		$zone = \WC_Shipping_Zones::get_zone_by('zone_id', $zone_id);
38 38
 
39
-		if ( false === $zone ) {
40
-			return new \WP_Error( 'woocommerce_rest_shipping_zone_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
39
+		if (false === $zone) {
40
+			return new \WP_Error('woocommerce_rest_shipping_zone_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
41 41
 		}
42 42
 
43 43
 		return $zone;
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
 	 * @param  \WP_REST_Request $request Full details about the request.
50 50
 	 * @return \WP_Error|boolean
51 51
 	 */
52
-	public function get_items_permissions_check( $request ) {
53
-		if ( ! wc_shipping_enabled() ) {
54
-			return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) );
52
+	public function get_items_permissions_check($request) {
53
+		if ( ! wc_shipping_enabled()) {
54
+			return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404));
55 55
 		}
56 56
 
57
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
58
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
57
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
58
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
59 59
 		}
60 60
 
61 61
 		return true;
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
 	 * @param  \WP_REST_Request $request Full details about the request.
68 68
 	 * @return \WP_Error|boolean
69 69
 	 */
70
-	public function create_item_permissions_check( $request ) {
71
-		if ( ! wc_shipping_enabled() ) {
72
-			return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) );
70
+	public function create_item_permissions_check($request) {
71
+		if ( ! wc_shipping_enabled()) {
72
+			return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404));
73 73
 		}
74 74
 
75
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
76
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
75
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
76
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
77 77
 		}
78 78
 
79 79
 		return true;
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
 	 * @param  \WP_REST_Request $request Full details about the request.
86 86
 	 * @return \WP_Error|boolean
87 87
 	 */
88
-	public function update_items_permissions_check( $request ) {
89
-		if ( ! wc_shipping_enabled() ) {
90
-			return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) );
88
+	public function update_items_permissions_check($request) {
89
+		if ( ! wc_shipping_enabled()) {
90
+			return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404));
91 91
 		}
92 92
 
93
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
94
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
93
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
94
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
95 95
 		}
96 96
 
97 97
 		return true;
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
 	 * @param  \WP_REST_Request $request Full details about the request.
104 104
 	 * @return \WP_Error|boolean
105 105
 	 */
106
-	public function delete_items_permissions_check( $request ) {
107
-		if ( ! wc_shipping_enabled() ) {
108
-			return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) );
106
+	public function delete_items_permissions_check($request) {
107
+		if ( ! wc_shipping_enabled()) {
108
+			return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404));
109 109
 		}
110 110
 
111
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
112
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
111
+		if ( ! wc_rest_check_manager_permissions('settings', 'delete')) {
112
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
113 113
 		}
114 114
 
115 115
 		return true;
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/AbstractController.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 namespace WooCommerce\RestApi\Version4\Controllers;
17 17
 
18
-defined( 'ABSPATH' ) || exit;
18
+defined('ABSPATH') || exit;
19 19
 
20 20
 use \WP_REST_Controller;
21 21
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @return array
53 53
 	 */
54
-	protected function add_additional_fields_schema( $schema ) {
55
-		if ( empty( $schema['title'] ) ) {
54
+	protected function add_additional_fields_schema($schema) {
55
+		if (empty($schema['title'])) {
56 56
 			return $schema;
57 57
 		}
58 58
 
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
 		 */
62 62
 		$object_type = $schema['title'];
63 63
 
64
-		$additional_fields = $this->get_additional_fields( $object_type );
64
+		$additional_fields = $this->get_additional_fields($object_type);
65 65
 
66
-		foreach ( $additional_fields as $field_name => $field_options ) {
67
-			if ( ! $field_options['schema'] ) {
66
+		foreach ($additional_fields as $field_name => $field_options) {
67
+			if ( ! $field_options['schema']) {
68 68
 				continue;
69 69
 			}
70 70
 
71
-			$schema['properties'][ $field_name ] = $field_options['schema'];
71
+			$schema['properties'][$field_name] = $field_options['schema'];
72 72
 		}
73 73
 
74
-		$schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] );
74
+		$schema['properties'] = apply_filters('woocommerce_rest_' . $object_type . '_schema', $schema['properties']);
75 75
 
76 76
 		return $schema;
77 77
 	}
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 * @return string
83 83
 	 */
84 84
 	protected function get_normalized_rest_base() {
85
-		return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
85
+		return preg_replace('/\(.*\)\//i', '', $this->rest_base);
86 86
 	}
87 87
 
88 88
 	/**
@@ -91,25 +91,25 @@  discard block
 block discarded – undo
91 91
 	 * @param array $items Request items.
92 92
 	 * @return bool|\WP_Error
93 93
 	 */
94
-	protected function check_batch_limit( $items ) {
95
-		$limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
94
+	protected function check_batch_limit($items) {
95
+		$limit = apply_filters('woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base());
96 96
 		$total = 0;
97 97
 
98
-		if ( ! empty( $items['create'] ) ) {
99
-			$total += count( $items['create'] );
98
+		if ( ! empty($items['create'])) {
99
+			$total += count($items['create']);
100 100
 		}
101 101
 
102
-		if ( ! empty( $items['update'] ) ) {
103
-			$total += count( $items['update'] );
102
+		if ( ! empty($items['update'])) {
103
+			$total += count($items['update']);
104 104
 		}
105 105
 
106
-		if ( ! empty( $items['delete'] ) ) {
107
-			$total += count( $items['delete'] );
106
+		if ( ! empty($items['delete'])) {
107
+			$total += count($items['delete']);
108 108
 		}
109 109
 
110
-		if ( $total > $limit ) {
110
+		if ($total > $limit) {
111 111
 			/* translators: %s: items limit */
112
-			return new \WP_Error( 'woocommerce_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), array( 'status' => 413 ) );
112
+			return new \WP_Error('woocommerce_rest_request_entity_too_large', sprintf(__('Unable to accept more than %s items for this request.', 'woocommerce'), $limit), array('status' => 413));
113 113
 		}
114 114
 
115 115
 		return true;
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @param \WP_REST_Request $request Full details about the request.
122 122
 	 * @return array Of \WP_Error or \WP_REST_Response.
123 123
 	 */
124
-	public function batch_items( $request ) {
124
+	public function batch_items($request) {
125 125
 		/**
126 126
 		 * REST Server
127 127
 		 *
@@ -130,34 +130,34 @@  discard block
 block discarded – undo
130 130
 		global $wp_rest_server;
131 131
 
132 132
 		// Get the request params.
133
-		$items    = array_filter( $request->get_params() );
133
+		$items    = array_filter($request->get_params());
134 134
 		$response = array();
135 135
 
136 136
 		// Check batch limit.
137
-		$limit = $this->check_batch_limit( $items );
138
-		if ( is_wp_error( $limit ) ) {
137
+		$limit = $this->check_batch_limit($items);
138
+		if (is_wp_error($limit)) {
139 139
 			return $limit;
140 140
 		}
141 141
 
142
-		if ( ! empty( $items['create'] ) ) {
143
-			foreach ( $items['create'] as $item ) {
144
-				$_item = new \WP_REST_Request( 'POST' );
142
+		if ( ! empty($items['create'])) {
143
+			foreach ($items['create'] as $item) {
144
+				$_item = new \WP_REST_Request('POST');
145 145
 
146 146
 				// Default parameters.
147 147
 				$defaults = array();
148 148
 				$schema   = $this->get_public_item_schema();
149
-				foreach ( $schema['properties'] as $arg => $options ) {
150
-					if ( isset( $options['default'] ) ) {
151
-						$defaults[ $arg ] = $options['default'];
149
+				foreach ($schema['properties'] as $arg => $options) {
150
+					if (isset($options['default'])) {
151
+						$defaults[$arg] = $options['default'];
152 152
 					}
153 153
 				}
154
-				$_item->set_default_params( $defaults );
154
+				$_item->set_default_params($defaults);
155 155
 
156 156
 				// Set request parameters.
157
-				$_item->set_body_params( $item );
158
-				$_response = $this->create_item( $_item );
157
+				$_item->set_body_params($item);
158
+				$_response = $this->create_item($_item);
159 159
 
160
-				if ( is_wp_error( $_response ) ) {
160
+				if (is_wp_error($_response)) {
161 161
 					$response['create'][] = array(
162 162
 						'id'    => 0,
163 163
 						'error' => array(
@@ -167,18 +167,18 @@  discard block
 block discarded – undo
167 167
 						),
168 168
 					);
169 169
 				} else {
170
-					$response['create'][] = $wp_rest_server->response_to_data( $_response, '' );
170
+					$response['create'][] = $wp_rest_server->response_to_data($_response, '');
171 171
 				}
172 172
 			}
173 173
 		}
174 174
 
175
-		if ( ! empty( $items['update'] ) ) {
176
-			foreach ( $items['update'] as $item ) {
177
-				$_item = new \WP_REST_Request( 'PUT' );
178
-				$_item->set_body_params( $item );
179
-				$_response = $this->update_item( $_item );
175
+		if ( ! empty($items['update'])) {
176
+			foreach ($items['update'] as $item) {
177
+				$_item = new \WP_REST_Request('PUT');
178
+				$_item->set_body_params($item);
179
+				$_response = $this->update_item($_item);
180 180
 
181
-				if ( is_wp_error( $_response ) ) {
181
+				if (is_wp_error($_response)) {
182 182
 					$response['update'][] = array(
183 183
 						'id'    => $item['id'],
184 184
 						'error' => array(
@@ -188,29 +188,29 @@  discard block
 block discarded – undo
188 188
 						),
189 189
 					);
190 190
 				} else {
191
-					$response['update'][] = $wp_rest_server->response_to_data( $_response, '' );
191
+					$response['update'][] = $wp_rest_server->response_to_data($_response, '');
192 192
 				}
193 193
 			}
194 194
 		}
195 195
 
196
-		if ( ! empty( $items['delete'] ) ) {
197
-			foreach ( $items['delete'] as $id ) {
196
+		if ( ! empty($items['delete'])) {
197
+			foreach ($items['delete'] as $id) {
198 198
 				$id = (int) $id;
199 199
 
200
-				if ( 0 === $id ) {
200
+				if (0 === $id) {
201 201
 					continue;
202 202
 				}
203 203
 
204
-				$_item = new \WP_REST_Request( 'DELETE' );
204
+				$_item = new \WP_REST_Request('DELETE');
205 205
 				$_item->set_query_params(
206 206
 					array(
207 207
 						'id'    => $id,
208 208
 						'force' => true,
209 209
 					)
210 210
 				);
211
-				$_response = $this->delete_item( $_item );
211
+				$_response = $this->delete_item($_item);
212 212
 
213
-				if ( is_wp_error( $_response ) ) {
213
+				if (is_wp_error($_response)) {
214 214
 					$response['delete'][] = array(
215 215
 						'id'    => $id,
216 216
 						'error' => array(
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 						),
221 221
 					);
222 222
 				} else {
223
-					$response['delete'][] = $wp_rest_server->response_to_data( $_response, '' );
223
+					$response['delete'][] = $wp_rest_server->response_to_data($_response, '');
224 224
 				}
225 225
 			}
226 226
 		}
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
 	 * @param array  $setting Setting.
237 237
 	 * @return string
238 238
 	 */
239
-	public function validate_setting_text_field( $value, $setting ) {
240
-		$value = is_null( $value ) ? '' : $value;
241
-		return wp_kses_post( trim( stripslashes( $value ) ) );
239
+	public function validate_setting_text_field($value, $setting) {
240
+		$value = is_null($value) ? '' : $value;
241
+		return wp_kses_post(trim(stripslashes($value)));
242 242
 	}
243 243
 
244 244
 	/**
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
 	 * @param array  $setting Setting.
250 250
 	 * @return string|\WP_Error
251 251
 	 */
252
-	public function validate_setting_select_field( $value, $setting ) {
253
-		if ( array_key_exists( $value, $setting['options'] ) ) {
252
+	public function validate_setting_select_field($value, $setting) {
253
+		if (array_key_exists($value, $setting['options'])) {
254 254
 			return $value;
255 255
 		} else {
256
-			return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
256
+			return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
257 257
 		}
258 258
 	}
259 259
 
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 	 * @param array $setting Setting.
266 266
 	 * @return array|\WP_Error
267 267
 	 */
268
-	public function validate_setting_multiselect_field( $values, $setting ) {
269
-		if ( empty( $values ) ) {
268
+	public function validate_setting_multiselect_field($values, $setting) {
269
+		if (empty($values)) {
270 270
 			return array();
271 271
 		}
272 272
 
273
-		if ( ! is_array( $values ) ) {
274
-			return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
273
+		if ( ! is_array($values)) {
274
+			return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
275 275
 		}
276 276
 
277 277
 		$final_values = array();
278
-		foreach ( $values as $value ) {
279
-			if ( array_key_exists( $value, $setting['options'] ) ) {
278
+		foreach ($values as $value) {
279
+			if (array_key_exists($value, $setting['options'])) {
280 280
 				$final_values[] = $value;
281 281
 			}
282 282
 		}
@@ -292,19 +292,19 @@  discard block
 block discarded – undo
292 292
 	 * @param array $setting Setting.
293 293
 	 * @return string|\WP_Error
294 294
 	 */
295
-	public function validate_setting_image_width_field( $values, $setting ) {
296
-		if ( ! is_array( $values ) ) {
297
-			return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
295
+	public function validate_setting_image_width_field($values, $setting) {
296
+		if ( ! is_array($values)) {
297
+			return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
298 298
 		}
299 299
 
300 300
 		$current = $setting['value'];
301
-		if ( isset( $values['width'] ) ) {
302
-			$current['width'] = intval( $values['width'] );
301
+		if (isset($values['width'])) {
302
+			$current['width'] = intval($values['width']);
303 303
 		}
304
-		if ( isset( $values['height'] ) ) {
305
-			$current['height'] = intval( $values['height'] );
304
+		if (isset($values['height'])) {
305
+			$current['height'] = intval($values['height']);
306 306
 		}
307
-		if ( isset( $values['crop'] ) ) {
307
+		if (isset($values['crop'])) {
308 308
 			$current['crop'] = (bool) $values['crop'];
309 309
 		}
310 310
 		return $current;
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
 	 * @param array  $setting Setting.
319 319
 	 * @return string|\WP_Error
320 320
 	 */
321
-	public function validate_setting_radio_field( $value, $setting ) {
322
-		return $this->validate_setting_select_field( $value, $setting );
321
+	public function validate_setting_radio_field($value, $setting) {
322
+		return $this->validate_setting_select_field($value, $setting);
323 323
 	}
324 324
 
325 325
 	/**
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
 	 * @param array  $setting Setting.
331 331
 	 * @return string|\WP_Error
332 332
 	 */
333
-	public function validate_setting_checkbox_field( $value, $setting ) {
334
-		if ( in_array( $value, array( 'yes', 'no' ) ) ) {
333
+	public function validate_setting_checkbox_field($value, $setting) {
334
+		if (in_array($value, array('yes', 'no'))) {
335 335
 			return $value;
336
-		} elseif ( empty( $value ) ) {
337
-			$value = isset( $setting['default'] ) ? $setting['default'] : 'no';
336
+		} elseif (empty($value)) {
337
+			$value = isset($setting['default']) ? $setting['default'] : 'no';
338 338
 			return $value;
339 339
 		} else {
340
-			return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
340
+			return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
341 341
 		}
342 342
 	}
343 343
 
@@ -349,10 +349,10 @@  discard block
 block discarded – undo
349 349
 	 * @param array  $setting Setting.
350 350
 	 * @return string
351 351
 	 */
352
-	public function validate_setting_textarea_field( $value, $setting ) {
353
-		$value = is_null( $value ) ? '' : $value;
352
+	public function validate_setting_textarea_field($value, $setting) {
353
+		$value = is_null($value) ? '' : $value;
354 354
 		return wp_kses(
355
-			trim( stripslashes( $value ) ),
355
+			trim(stripslashes($value)),
356 356
 			array_merge(
357 357
 				array(
358 358
 					'iframe' => array(
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 						'class' => true,
363 363
 					),
364 364
 				),
365
-				wp_kses_allowed_html( 'post' )
365
+				wp_kses_allowed_html('post')
366 366
 			)
367 367
 		);
368 368
 	}
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * @param array $meta_query Meta query.
376 376
 	 * @return array
377 377
 	 */
378
-	protected function add_meta_query( $args, $meta_query ) {
379
-		if ( empty( $args['meta_query'] ) ) {
378
+	protected function add_meta_query($args, $meta_query) {
379
+		if (empty($args['meta_query'])) {
380 380
 			$args['meta_query'] = array();
381 381
 		}
382 382
 
@@ -397,25 +397,25 @@  discard block
 block discarded – undo
397 397
 			'type'       => 'object',
398 398
 			'properties' => array(
399 399
 				'create' => array(
400
-					'description' => __( 'List of created resources.', 'woocommerce' ),
400
+					'description' => __('List of created resources.', 'woocommerce'),
401 401
 					'type'        => 'array',
402
-					'context'     => array( 'view', 'edit' ),
402
+					'context'     => array('view', 'edit'),
403 403
 					'items'       => array(
404 404
 						'type'    => 'object',
405 405
 					),
406 406
 				),
407 407
 				'update' => array(
408
-					'description' => __( 'List of updated resources.', 'woocommerce' ),
408
+					'description' => __('List of updated resources.', 'woocommerce'),
409 409
 					'type'        => 'array',
410
-					'context'     => array( 'view', 'edit' ),
410
+					'context'     => array('view', 'edit'),
411 411
 					'items'       => array(
412 412
 						'type'    => 'object',
413 413
 					),
414 414
 				),
415 415
 				'delete' => array(
416
-					'description' => __( 'List of delete resources.', 'woocommerce' ),
416
+					'description' => __('List of delete resources.', 'woocommerce'),
417 417
 					'type'        => 'array',
418
-					'context'     => array( 'view', 'edit' ),
418
+					'context'     => array('view', 'edit'),
419 419
 					'items'       => array(
420 420
 						'type'    => 'integer',
421 421
 					),
@@ -435,32 +435,32 @@  discard block
 block discarded – undo
435 435
 	 * @param \WP_REST_Request $request Full details about the request.
436 436
 	 * @return array Fields to be included in the response.
437 437
 	 */
438
-	public function get_fields_for_response( $request ) {
438
+	public function get_fields_for_response($request) {
439 439
 		$schema = $this->get_item_schema();
440
-		$fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array();
440
+		$fields = isset($schema['properties']) ? array_keys($schema['properties']) : array();
441 441
 
442 442
 		$additional_fields = $this->get_additional_fields();
443
-		foreach ( $additional_fields as $field_name => $field_options ) {
443
+		foreach ($additional_fields as $field_name => $field_options) {
444 444
 			// For back-compat, include any field with an empty schema
445 445
 			// because it won't be present in $this->get_item_schema().
446
-			if ( is_null( $field_options['schema'] ) ) {
446
+			if (is_null($field_options['schema'])) {
447 447
 				$fields[] = $field_name;
448 448
 			}
449 449
 		}
450 450
 
451
-		if ( ! isset( $request['_fields'] ) ) {
451
+		if ( ! isset($request['_fields'])) {
452 452
 			return $fields;
453 453
 		}
454
-		$requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
455
-		if ( 0 === count( $requested_fields ) ) {
454
+		$requested_fields = is_array($request['_fields']) ? $request['_fields'] : preg_split('/[\s,]+/', $request['_fields']);
455
+		if (0 === count($requested_fields)) {
456 456
 			return $fields;
457 457
 		}
458 458
 		// Trim off outside whitespace from the comma delimited list.
459
-		$requested_fields = array_map( 'trim', $requested_fields );
459
+		$requested_fields = array_map('trim', $requested_fields);
460 460
 		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
461
-		if ( in_array( 'id', $fields, true ) ) {
461
+		if (in_array('id', $fields, true)) {
462 462
 			$requested_fields[] = 'id';
463 463
 		}
464
-		return array_intersect( $fields, $requested_fields );
464
+		return array_intersect($fields, $requested_fields);
465 465
 	}
466 466
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Settings.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Settings controller class.
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 			array(
36 36
 				array(
37 37
 					'methods'             => \WP_REST_Server::READABLE,
38
-					'callback'            => array( $this, 'get_items' ),
39
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
38
+					'callback'            => array($this, 'get_items'),
39
+					'permission_callback' => array($this, 'get_items_permissions_check'),
40 40
 				),
41
-				'schema' => array( $this, 'get_public_item_schema' ),
41
+				'schema' => array($this, 'get_public_item_schema'),
42 42
 			),
43 43
 			true
44 44
 		);
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
 			array(
49 49
 				array(
50 50
 					'methods'             => \WP_REST_Server::EDITABLE,
51
-					'callback'            => array( $this, 'batch_items' ),
52
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
51
+					'callback'            => array($this, 'batch_items'),
52
+					'permission_callback' => array($this, 'update_items_permissions_check'),
53 53
 				),
54
-				'schema' => array( $this, 'get_public_batch_schema' ),
54
+				'schema' => array($this, 'get_public_batch_schema'),
55 55
 			),
56 56
 			true
57 57
 		);
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 	 * @param \WP_REST_Request $request Full data about the request.
64 64
 	 * @return \WP_Error|bool
65 65
 	 */
66
-	public function update_items_permissions_check( $request ) {
67
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
68
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
66
+	public function update_items_permissions_check($request) {
67
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
68
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
69 69
 		}
70 70
 
71 71
 		return true;
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 	 * @param  \WP_REST_Request $request Request data.
78 78
 	 * @return \WP_Error\WP_REST_Response
79 79
 	 */
80
-	public function update_item( $request ) {
80
+	public function update_item($request) {
81 81
 		$options_controller = new \WC_REST_Setting_Options_Controller();
82
-		$response           = $options_controller->update_item( $request );
82
+		$response           = $options_controller->update_item($request);
83 83
 
84 84
 		return $response;
85 85
 	}
@@ -91,34 +91,34 @@  discard block
 block discarded – undo
91 91
 	 * @param  \WP_REST_Request $request Request data.
92 92
 	 * @return \WP_Error\WP_REST_Response
93 93
 	 */
94
-	public function get_items( $request ) {
95
-		$groups = apply_filters( 'woocommerce_settings_groups', array() );
96
-		if ( empty( $groups ) ) {
97
-			return new \WP_Error( 'rest_setting_groups_empty', __( 'No setting groups have been registered.', 'woocommerce' ), array( 'status' => 500 ) );
94
+	public function get_items($request) {
95
+		$groups = apply_filters('woocommerce_settings_groups', array());
96
+		if (empty($groups)) {
97
+			return new \WP_Error('rest_setting_groups_empty', __('No setting groups have been registered.', 'woocommerce'), array('status' => 500));
98 98
 		}
99 99
 
100 100
 		$defaults        = $this->group_defaults();
101 101
 		$filtered_groups = array();
102
-		foreach ( $groups as $group ) {
102
+		foreach ($groups as $group) {
103 103
 			$sub_groups = array();
104
-			foreach ( $groups as $_group ) {
105
-				if ( ! empty( $_group['parent_id'] ) && $group['id'] === $_group['parent_id'] ) {
104
+			foreach ($groups as $_group) {
105
+				if ( ! empty($_group['parent_id']) && $group['id'] === $_group['parent_id']) {
106 106
 					$sub_groups[] = $_group['id'];
107 107
 				}
108 108
 			}
109 109
 			$group['sub_groups'] = $sub_groups;
110 110
 
111
-			$group = wp_parse_args( $group, $defaults );
112
-			if ( ! is_null( $group['id'] ) && ! is_null( $group['label'] ) ) {
113
-				$group_obj  = $this->filter_group( $group );
114
-				$group_data = $this->prepare_item_for_response( $group_obj, $request );
115
-				$group_data = $this->prepare_response_for_collection( $group_data );
111
+			$group = wp_parse_args($group, $defaults);
112
+			if ( ! is_null($group['id']) && ! is_null($group['label'])) {
113
+				$group_obj  = $this->filter_group($group);
114
+				$group_data = $this->prepare_item_for_response($group_obj, $request);
115
+				$group_data = $this->prepare_response_for_collection($group_data);
116 116
 
117 117
 				$filtered_groups[] = $group_data;
118 118
 			}
119 119
 		}
120 120
 
121
-		$response = rest_ensure_response( $filtered_groups );
121
+		$response = rest_ensure_response($filtered_groups);
122 122
 		return $response;
123 123
 	}
124 124
 
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
 	 * @param string $group_id Group ID.
129 129
 	 * @return array Links for the given group.
130 130
 	 */
131
-	protected function prepare_links( $group_id ) {
131
+	protected function prepare_links($group_id) {
132 132
 		$base  = '/' . $this->namespace . '/' . $this->rest_base;
133 133
 		$links = array(
134 134
 			'options' => array(
135
-				'href' => rest_url( trailingslashit( $base ) . $group_id ),
135
+				'href' => rest_url(trailingslashit($base) . $group_id),
136 136
 			),
137 137
 		);
138 138
 
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
 	 * @param \WP_REST_Request $request Request object.
148 148
 	 * @return \WP_REST_Response $response Response data.
149 149
 	 */
150
-	public function prepare_item_for_response( $item, $request ) {
151
-		$context = empty( $request['context'] ) ? 'view' : $request['context'];
152
-		$data    = $this->add_additional_fields_to_object( $item, $request );
153
-		$data    = $this->filter_response_by_context( $data, $context );
150
+	public function prepare_item_for_response($item, $request) {
151
+		$context = empty($request['context']) ? 'view' : $request['context'];
152
+		$data    = $this->add_additional_fields_to_object($item, $request);
153
+		$data    = $this->filter_response_by_context($data, $context);
154 154
 
155
-		$response = rest_ensure_response( $data );
155
+		$response = rest_ensure_response($data);
156 156
 
157
-		$response->add_links( $this->prepare_links( $item['id'] ) );
157
+		$response->add_links($this->prepare_links($item['id']));
158 158
 
159 159
 		return $response;
160 160
 	}
@@ -167,10 +167,10 @@  discard block
 block discarded – undo
167 167
 	 * @param  array $group Group.
168 168
 	 * @return array
169 169
 	 */
170
-	public function filter_group( $group ) {
170
+	public function filter_group($group) {
171 171
 		return array_intersect_key(
172 172
 			$group,
173
-			array_flip( array_filter( array_keys( $group ), array( $this, 'allowed_group_keys' ) ) )
173
+			array_flip(array_filter(array_keys($group), array($this, 'allowed_group_keys')))
174 174
 		);
175 175
 	}
176 176
 
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
 	 * @param  string $key Key to check.
182 182
 	 * @return boolean
183 183
 	 */
184
-	public function allowed_group_keys( $key ) {
185
-		return in_array( $key, array( 'id', 'label', 'description', 'parent_id', 'sub_groups' ) );
184
+	public function allowed_group_keys($key) {
185
+		return in_array($key, array('id', 'label', 'description', 'parent_id', 'sub_groups'));
186 186
 	}
187 187
 
188 188
 	/**
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
 	 * @param \WP_REST_Request $request Full data about the request.
209 209
 	 * @return \WP_Error|boolean
210 210
 	 */
211
-	public function get_items_permissions_check( $request ) {
212
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
213
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
211
+	public function get_items_permissions_check($request) {
212
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
213
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
214 214
 		}
215 215
 
216 216
 		return true;
@@ -229,33 +229,33 @@  discard block
 block discarded – undo
229 229
 			'type'       => 'object',
230 230
 			'properties' => array(
231 231
 				'id'          => array(
232
-					'description' => __( 'A unique identifier that can be used to link settings together.', 'woocommerce' ),
232
+					'description' => __('A unique identifier that can be used to link settings together.', 'woocommerce'),
233 233
 					'type'        => 'string',
234
-					'context'     => array( 'view', 'edit' ),
234
+					'context'     => array('view', 'edit'),
235 235
 				),
236 236
 				'label'       => array(
237
-					'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
237
+					'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'),
238 238
 					'type'        => 'string',
239
-					'context'     => array( 'view', 'edit' ),
239
+					'context'     => array('view', 'edit'),
240 240
 				),
241 241
 				'description' => array(
242
-					'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
242
+					'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'),
243 243
 					'type'        => 'string',
244
-					'context'     => array( 'view', 'edit' ),
244
+					'context'     => array('view', 'edit'),
245 245
 				),
246 246
 				'parent_id'   => array(
247
-					'description' => __( 'ID of parent grouping.', 'woocommerce' ),
247
+					'description' => __('ID of parent grouping.', 'woocommerce'),
248 248
 					'type'        => 'string',
249
-					'context'     => array( 'view', 'edit' ),
249
+					'context'     => array('view', 'edit'),
250 250
 				),
251 251
 				'sub_groups'  => array(
252
-					'description' => __( 'IDs for settings sub groups.', 'woocommerce' ),
252
+					'description' => __('IDs for settings sub groups.', 'woocommerce'),
253 253
 					'type'        => 'string',
254
-					'context'     => array( 'view', 'edit' ),
254
+					'context'     => array('view', 'edit'),
255 255
 				),
256 256
 			),
257 257
 		);
258 258
 
259
-		return $this->add_additional_fields_schema( $schema );
259
+		return $this->add_additional_fields_schema($schema);
260 260
 	}
261 261
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/AbstractPostsController.php 1 patch
Spacing   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\Version4\Controllers;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * POSTS Controller.
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	 * @param  \WP_REST_Request $request Full details about the request.
44 44
 	 * @return \WP_Error|boolean
45 45
 	 */
46
-	public function get_items_permissions_check( $request ) {
47
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) {
48
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
46
+	public function get_items_permissions_check($request) {
47
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) {
48
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
49 49
 		}
50 50
 
51 51
 		return true;
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 * @param  \WP_REST_Request $request Full details about the request.
58 58
 	 * @return \WP_Error|boolean
59 59
 	 */
60
-	public function create_item_permissions_check( $request ) {
61
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) {
62
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
60
+	public function create_item_permissions_check($request) {
61
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) {
62
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
63 63
 		}
64 64
 
65 65
 		return true;
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 	 * @param  \WP_REST_Request $request Full details about the request.
72 72
 	 * @return \WP_Error|boolean
73 73
 	 */
74
-	public function get_item_permissions_check( $request ) {
75
-		$post = get_post( (int) $request['id'] );
74
+	public function get_item_permissions_check($request) {
75
+		$post = get_post((int) $request['id']);
76 76
 
77
-		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
78
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
77
+		if ($post && ! wc_rest_check_post_permissions($this->post_type, 'read', $post->ID)) {
78
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
79 79
 		}
80 80
 
81 81
 		return true;
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
 	 * @param  \WP_REST_Request $request Full details about the request.
88 88
 	 * @return \WP_Error|boolean
89 89
 	 */
90
-	public function update_item_permissions_check( $request ) {
91
-		$post = get_post( (int) $request['id'] );
90
+	public function update_item_permissions_check($request) {
91
+		$post = get_post((int) $request['id']);
92 92
 
93
-		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $post->ID ) ) {
94
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
93
+		if ($post && ! wc_rest_check_post_permissions($this->post_type, 'edit', $post->ID)) {
94
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
95 95
 		}
96 96
 
97 97
 		return true;
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
 	 * @param  \WP_REST_Request $request Full details about the request.
104 104
 	 * @return bool|\WP_Error
105 105
 	 */
106
-	public function delete_item_permissions_check( $request ) {
107
-		$post = get_post( (int) $request['id'] );
106
+	public function delete_item_permissions_check($request) {
107
+		$post = get_post((int) $request['id']);
108 108
 
109
-		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) {
110
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
109
+		if ($post && ! wc_rest_check_post_permissions($this->post_type, 'delete', $post->ID)) {
110
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
111 111
 		}
112 112
 
113 113
 		return true;
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 	 *
121 121
 	 * @return boolean|\WP_Error
122 122
 	 */
123
-	public function batch_items_permissions_check( $request ) {
124
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'batch' ) ) {
125
-			return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
123
+	public function batch_items_permissions_check($request) {
124
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'batch')) {
125
+			return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
126 126
 		}
127 127
 
128 128
 		return true;
@@ -134,21 +134,21 @@  discard block
 block discarded – undo
134 134
 	 * @param \WP_REST_Request $request Full details about the request.
135 135
 	 * @return \WP_Error\WP_REST_Response
136 136
 	 */
137
-	public function get_item( $request ) {
137
+	public function get_item($request) {
138 138
 		$id   = (int) $request['id'];
139
-		$post = get_post( $id );
139
+		$post = get_post($id);
140 140
 
141
-		if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) {
142
-			return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/&lt;product_id&gt;/variations/&lt;id&gt; endpoint.', 'woocommerce' ), array( 'status' => 404 ) );
143
-		} elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
144
-			return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
141
+		if ( ! empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) {
142
+			return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/&lt;product_id&gt;/variations/&lt;id&gt; endpoint.', 'woocommerce'), array('status' => 404));
143
+		} elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) {
144
+			return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
145 145
 		}
146 146
 
147
-		$data = $this->prepare_item_for_response( $post, $request );
148
-		$response = rest_ensure_response( $data );
147
+		$data = $this->prepare_item_for_response($post, $request);
148
+		$response = rest_ensure_response($data);
149 149
 
150
-		if ( $this->public ) {
151
-			$response->link_header( 'alternate', get_permalink( $id ), array( 'type' => 'text/html' ) );
150
+		if ($this->public) {
151
+			$response->link_header('alternate', get_permalink($id), array('type' => 'text/html'));
152 152
 		}
153 153
 
154 154
 		return $response;
@@ -160,39 +160,39 @@  discard block
 block discarded – undo
160 160
 	 * @param \WP_REST_Request $request Full details about the request.
161 161
 	 * @return \WP_Error\WP_REST_Response
162 162
 	 */
163
-	public function create_item( $request ) {
164
-		if ( ! empty( $request['id'] ) ) {
163
+	public function create_item($request) {
164
+		if ( ! empty($request['id'])) {
165 165
 			/* translators: %s: post type */
166
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
166
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
167 167
 		}
168 168
 
169
-		$post = $this->prepare_item_for_database( $request );
170
-		if ( is_wp_error( $post ) ) {
169
+		$post = $this->prepare_item_for_database($request);
170
+		if (is_wp_error($post)) {
171 171
 			return $post;
172 172
 		}
173 173
 
174 174
 		$post->post_type = $this->post_type;
175
-		$post_id         = wp_insert_post( $post, true );
175
+		$post_id         = wp_insert_post($post, true);
176 176
 
177
-		if ( is_wp_error( $post_id ) ) {
177
+		if (is_wp_error($post_id)) {
178 178
 
179
-			if ( in_array( $post_id->get_error_code(), array( 'db_insert_error' ) ) ) {
180
-				$post_id->add_data( array( 'status' => 500 ) );
179
+			if (in_array($post_id->get_error_code(), array('db_insert_error'))) {
180
+				$post_id->add_data(array('status' => 500));
181 181
 			} else {
182
-				$post_id->add_data( array( 'status' => 400 ) );
182
+				$post_id->add_data(array('status' => 400));
183 183
 			}
184 184
 			return $post_id;
185 185
 		}
186 186
 		$post->ID = $post_id;
187
-		$post     = get_post( $post_id );
187
+		$post     = get_post($post_id);
188 188
 
189
-		$this->update_additional_fields_for_object( $post, $request );
189
+		$this->update_additional_fields_for_object($post, $request);
190 190
 
191 191
 		// Add meta fields.
192
-		$meta_fields = $this->add_post_meta_fields( $post, $request );
193
-		if ( is_wp_error( $meta_fields ) ) {
192
+		$meta_fields = $this->add_post_meta_fields($post, $request);
193
+		if (is_wp_error($meta_fields)) {
194 194
 			// Remove post.
195
-			$this->delete_post( $post );
195
+			$this->delete_post($post);
196 196
 
197 197
 			return $meta_fields;
198 198
 		}
@@ -204,13 +204,13 @@  discard block
 block discarded – undo
204 204
 		 * @param \WP_REST_Request $request   Request object.
205 205
 		 * @param boolean         $creating  True when creating item, false when updating.
206 206
 		 */
207
-		do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true );
207
+		do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true);
208 208
 
209
-		$request->set_param( 'context', 'edit' );
210
-		$response = $this->prepare_item_for_response( $post, $request );
211
-		$response = rest_ensure_response( $response );
212
-		$response->set_status( 201 );
213
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post_id ) ) );
209
+		$request->set_param('context', 'edit');
210
+		$response = $this->prepare_item_for_response($post, $request);
211
+		$response = rest_ensure_response($response);
212
+		$response->set_status(201);
213
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post_id)));
214 214
 
215 215
 		return $response;
216 216
 	}
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 * @param \WP_REST_Request $request \WP_REST_Request Object.
223 223
 	 * @return bool|\WP_Error
224 224
 	 */
225
-	protected function add_post_meta_fields( $post, $request ) {
225
+	protected function add_post_meta_fields($post, $request) {
226 226
 		return true;
227 227
 	}
228 228
 
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
 	 *
232 232
 	 * @param WP_Post $post Post object.
233 233
 	 */
234
-	protected function delete_post( $post ) {
235
-		wp_delete_post( $post->ID, true );
234
+	protected function delete_post($post) {
235
+		wp_delete_post($post->ID, true);
236 236
 	}
237 237
 
238 238
 	/**
@@ -241,37 +241,37 @@  discard block
 block discarded – undo
241 241
 	 * @param \WP_REST_Request $request Full details about the request.
242 242
 	 * @return \WP_Error\WP_REST_Response
243 243
 	 */
244
-	public function update_item( $request ) {
244
+	public function update_item($request) {
245 245
 		$id   = (int) $request['id'];
246
-		$post = get_post( $id );
246
+		$post = get_post($id);
247 247
 
248
-		if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) {
249
-			return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/&lt;product_id&gt;/variations/&lt;id&gt; endpoint.', 'woocommerce' ), array( 'status' => 404 ) );
250
-		} elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
251
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
248
+		if ( ! empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) {
249
+			return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/&lt;product_id&gt;/variations/&lt;id&gt; endpoint.', 'woocommerce'), array('status' => 404));
250
+		} elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) {
251
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400));
252 252
 		}
253 253
 
254
-		$post = $this->prepare_item_for_database( $request );
255
-		if ( is_wp_error( $post ) ) {
254
+		$post = $this->prepare_item_for_database($request);
255
+		if (is_wp_error($post)) {
256 256
 			return $post;
257 257
 		}
258 258
 		// Convert the post object to an array, otherwise wp_update_post will expect non-escaped input.
259
-		$post_id = wp_update_post( (array) $post, true );
260
-		if ( is_wp_error( $post_id ) ) {
261
-			if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) {
262
-				$post_id->add_data( array( 'status' => 500 ) );
259
+		$post_id = wp_update_post((array) $post, true);
260
+		if (is_wp_error($post_id)) {
261
+			if (in_array($post_id->get_error_code(), array('db_update_error'))) {
262
+				$post_id->add_data(array('status' => 500));
263 263
 			} else {
264
-				$post_id->add_data( array( 'status' => 400 ) );
264
+				$post_id->add_data(array('status' => 400));
265 265
 			}
266 266
 			return $post_id;
267 267
 		}
268 268
 
269
-		$post = get_post( $post_id );
270
-		$this->update_additional_fields_for_object( $post, $request );
269
+		$post = get_post($post_id);
270
+		$this->update_additional_fields_for_object($post, $request);
271 271
 
272 272
 		// Update meta fields.
273
-		$meta_fields = $this->update_post_meta_fields( $post, $request );
274
-		if ( is_wp_error( $meta_fields ) ) {
273
+		$meta_fields = $this->update_post_meta_fields($post, $request);
274
+		if (is_wp_error($meta_fields)) {
275 275
 			return $meta_fields;
276 276
 		}
277 277
 
@@ -282,11 +282,11 @@  discard block
 block discarded – undo
282 282
 		 * @param \WP_REST_Request $request   Request object.
283 283
 		 * @param boolean         $creating  True when creating item, false when updating.
284 284
 		 */
285
-		do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false );
285
+		do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, false);
286 286
 
287
-		$request->set_param( 'context', 'edit' );
288
-		$response = $this->prepare_item_for_response( $post, $request );
289
-		return rest_ensure_response( $response );
287
+		$request->set_param('context', 'edit');
288
+		$response = $this->prepare_item_for_response($post, $request);
289
+		return rest_ensure_response($response);
290 290
 	}
291 291
 
292 292
 	/**
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	 * @param \WP_REST_Request $request Full details about the request.
296 296
 	 * @return \WP_Error\WP_REST_Response
297 297
 	 */
298
-	public function get_items( $request ) {
298
+	public function get_items($request) {
299 299
 		$args                         = array();
300 300
 		$args['offset']               = $request['offset'];
301 301
 		$args['order']                = $request['order'];
@@ -311,19 +311,19 @@  discard block
 block discarded – undo
311 311
 
312 312
 		$args['date_query'] = array();
313 313
 		// Set before into date query. Date query must be specified as an array of an array.
314
-		if ( isset( $request['before'] ) ) {
314
+		if (isset($request['before'])) {
315 315
 			$args['date_query'][0]['before'] = $request['before'];
316 316
 		}
317 317
 
318 318
 		// Set after into date query. Date query must be specified as an array of an array.
319
-		if ( isset( $request['after'] ) ) {
319
+		if (isset($request['after'])) {
320 320
 			$args['date_query'][0]['after'] = $request['after'];
321 321
 		}
322 322
 
323
-		if ( 'wc/v1' === $this->namespace ) {
324
-			if ( is_array( $request['filter'] ) ) {
325
-				$args = array_merge( $args, $request['filter'] );
326
-				unset( $args['filter'] );
323
+		if ('wc/v1' === $this->namespace) {
324
+			if (is_array($request['filter'])) {
325
+				$args = array_merge($args, $request['filter']);
326
+				unset($args['filter']);
327 327
 			}
328 328
 		}
329 329
 
@@ -339,59 +339,59 @@  discard block
 block discarded – undo
339 339
 		 * @param array           $args    Key value array of query var to query value.
340 340
 		 * @param \WP_REST_Request $request The request used.
341 341
 		 */
342
-		$args = apply_filters( "woocommerce_rest_{$this->post_type}_query", $args, $request );
343
-		$query_args = $this->prepare_items_query( $args, $request );
342
+		$args = apply_filters("woocommerce_rest_{$this->post_type}_query", $args, $request);
343
+		$query_args = $this->prepare_items_query($args, $request);
344 344
 
345 345
 		$posts_query = new \WP_Query();
346
-		$query_result = $posts_query->query( $query_args );
346
+		$query_result = $posts_query->query($query_args);
347 347
 
348 348
 		$posts = array();
349
-		foreach ( $query_result as $post ) {
350
-			if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
349
+		foreach ($query_result as $post) {
350
+			if ( ! wc_rest_check_post_permissions($this->post_type, 'read', $post->ID)) {
351 351
 				continue;
352 352
 			}
353 353
 
354
-			$data = $this->prepare_item_for_response( $post, $request );
355
-			$posts[] = $this->prepare_response_for_collection( $data );
354
+			$data = $this->prepare_item_for_response($post, $request);
355
+			$posts[] = $this->prepare_response_for_collection($data);
356 356
 		}
357 357
 
358 358
 		$page = (int) $query_args['paged'];
359 359
 		$total_posts = $posts_query->found_posts;
360 360
 
361
-		if ( $total_posts < 1 ) {
361
+		if ($total_posts < 1) {
362 362
 			// Out-of-bounds, run the query again without LIMIT for total count.
363
-			unset( $query_args['paged'] );
363
+			unset($query_args['paged']);
364 364
 			$count_query = new \WP_Query();
365
-			$count_query->query( $query_args );
365
+			$count_query->query($query_args);
366 366
 			$total_posts = $count_query->found_posts;
367 367
 		}
368 368
 
369
-		$max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] );
369
+		$max_pages = ceil($total_posts / (int) $query_args['posts_per_page']);
370 370
 
371
-		$response = rest_ensure_response( $posts );
372
-		$response->header( 'X-WP-Total', (int) $total_posts );
373
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
371
+		$response = rest_ensure_response($posts);
372
+		$response->header('X-WP-Total', (int) $total_posts);
373
+		$response->header('X-WP-TotalPages', (int) $max_pages);
374 374
 
375 375
 		$request_params = $request->get_query_params();
376
-		if ( ! empty( $request_params['filter'] ) ) {
376
+		if ( ! empty($request_params['filter'])) {
377 377
 			// Normalize the pagination params.
378
-			unset( $request_params['filter']['posts_per_page'] );
379
-			unset( $request_params['filter']['paged'] );
378
+			unset($request_params['filter']['posts_per_page']);
379
+			unset($request_params['filter']['paged']);
380 380
 		}
381
-		$base = add_query_arg( $request_params, rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
381
+		$base = add_query_arg($request_params, rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
382 382
 
383
-		if ( $page > 1 ) {
383
+		if ($page > 1) {
384 384
 			$prev_page = $page - 1;
385
-			if ( $prev_page > $max_pages ) {
385
+			if ($prev_page > $max_pages) {
386 386
 				$prev_page = $max_pages;
387 387
 			}
388
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
389
-			$response->link_header( 'prev', $prev_link );
388
+			$prev_link = add_query_arg('page', $prev_page, $base);
389
+			$response->link_header('prev', $prev_link);
390 390
 		}
391
-		if ( $max_pages > $page ) {
391
+		if ($max_pages > $page) {
392 392
 			$next_page = $page + 1;
393
-			$next_link = add_query_arg( 'page', $next_page, $base );
394
-			$response->link_header( 'next', $next_link );
393
+			$next_link = add_query_arg('page', $next_page, $base);
394
+			$response->link_header('next', $next_link);
395 395
 		}
396 396
 
397 397
 		return $response;
@@ -403,13 +403,13 @@  discard block
 block discarded – undo
403 403
 	 * @param \WP_REST_Request $request Full details about the request.
404 404
 	 * @return \WP_REST_Response|\WP_Error
405 405
 	 */
406
-	public function delete_item( $request ) {
406
+	public function delete_item($request) {
407 407
 		$id    = (int) $request['id'];
408 408
 		$force = (bool) $request['force'];
409
-		$post  = get_post( $id );
409
+		$post  = get_post($id);
410 410
 
411
-		if ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
412
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 404 ) );
411
+		if (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) {
412
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 404));
413 413
 		}
414 414
 
415 415
 		$supports_trash = EMPTY_TRASH_DAYS > 0;
@@ -422,40 +422,40 @@  discard block
 block discarded – undo
422 422
 		 * @param boolean $supports_trash Whether the item type support trashing.
423 423
 		 * @param WP_Post $post           The Post object being considered for trashing support.
424 424
 		 */
425
-		$supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post );
425
+		$supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post);
426 426
 
427
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) {
427
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $post->ID)) {
428 428
 			/* translators: %s: post type */
429
-			return new \WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( 'status' => rest_authorization_required_code() ) );
429
+			return new \WP_Error("woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array('status' => rest_authorization_required_code()));
430 430
 		}
431 431
 
432
-		$request->set_param( 'context', 'edit' );
433
-		$response = $this->prepare_item_for_response( $post, $request );
432
+		$request->set_param('context', 'edit');
433
+		$response = $this->prepare_item_for_response($post, $request);
434 434
 
435 435
 		// If we're forcing, then delete permanently.
436
-		if ( $force ) {
437
-			$result = wp_delete_post( $id, true );
436
+		if ($force) {
437
+			$result = wp_delete_post($id, true);
438 438
 		} else {
439 439
 			// If we don't support trashing for this type, error out.
440
-			if ( ! $supports_trash ) {
440
+			if ( ! $supports_trash) {
441 441
 				/* translators: %s: post type */
442
-				return new \WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) );
442
+				return new \WP_Error('woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array('status' => 501));
443 443
 			}
444 444
 
445 445
 			// Otherwise, only trash if we haven't already.
446
-			if ( 'trash' === $post->post_status ) {
446
+			if ('trash' === $post->post_status) {
447 447
 				/* translators: %s: post type */
448
-				return new \WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) );
448
+				return new \WP_Error('woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array('status' => 410));
449 449
 			}
450 450
 
451 451
 			// (Note that internally this falls through to `wp_delete_post` if
452 452
 			// the trash is disabled.)
453
-			$result = wp_trash_post( $id );
453
+			$result = wp_trash_post($id);
454 454
 		}
455 455
 
456
-		if ( ! $result ) {
456
+		if ( ! $result) {
457 457
 			/* translators: %s: post type */
458
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
458
+			return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500));
459 459
 		}
460 460
 
461 461
 		/**
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 		 * @param \WP_REST_Response $response The response data.
466 466
 		 * @param \WP_REST_Request  $request  The request sent to the API.
467 467
 		 */
468
-		do_action( "woocommerce_rest_delete_{$this->post_type}", $post, $response, $request );
468
+		do_action("woocommerce_rest_delete_{$this->post_type}", $post, $response, $request);
469 469
 
470 470
 		return $response;
471 471
 	}
@@ -477,13 +477,13 @@  discard block
 block discarded – undo
477 477
 	 * @param \WP_REST_Request $request Request object.
478 478
 	 * @return array Links for the given post.
479 479
 	 */
480
-	protected function prepare_links( $post, $request ) {
480
+	protected function prepare_links($post, $request) {
481 481
 		$links = array(
482 482
 			'self' => array(
483
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ),
483
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID)),
484 484
 			),
485 485
 			'collection' => array(
486
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
486
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
487 487
 			),
488 488
 		);
489 489
 
@@ -498,12 +498,12 @@  discard block
 block discarded – undo
498 498
 	 * @param \WP_REST_Request $request Request object.
499 499
 	 * @return array          $query_args
500 500
 	 */
501
-	protected function prepare_items_query( $prepared_args = array(), $request = null ) {
501
+	protected function prepare_items_query($prepared_args = array(), $request = null) {
502 502
 
503
-		$valid_vars = array_flip( $this->get_allowed_query_vars() );
503
+		$valid_vars = array_flip($this->get_allowed_query_vars());
504 504
 		$query_args = array();
505
-		foreach ( $valid_vars as $var => $index ) {
506
-			if ( isset( $prepared_args[ $var ] ) ) {
505
+		foreach ($valid_vars as $var => $index) {
506
+			if (isset($prepared_args[$var])) {
507 507
 				/**
508 508
 				 * Filter the query_vars used in `get_items` for the constructed query.
509 509
 				 *
@@ -511,17 +511,17 @@  discard block
 block discarded – undo
511 511
 				 *
512 512
 				 * @param mixed $prepared_args[ $var ] The query_var value.
513 513
 				 */
514
-				$query_args[ $var ] = apply_filters( "woocommerce_rest_query_var-{$var}", $prepared_args[ $var ] );
514
+				$query_args[$var] = apply_filters("woocommerce_rest_query_var-{$var}", $prepared_args[$var]);
515 515
 			}
516 516
 		}
517 517
 
518 518
 		$query_args['ignore_sticky_posts'] = true;
519 519
 
520
-		if ( 'include' === $query_args['orderby'] ) {
520
+		if ('include' === $query_args['orderby']) {
521 521
 			$query_args['orderby'] = 'post__in';
522
-		} elseif ( 'id' === $query_args['orderby'] ) {
522
+		} elseif ('id' === $query_args['orderby']) {
523 523
 			$query_args['orderby'] = 'ID'; // ID must be capitalized.
524
-		} elseif ( 'slug' === $query_args['orderby'] ) {
524
+		} elseif ('slug' === $query_args['orderby']) {
525 525
 			$query_args['orderby'] = 'name';
526 526
 		}
527 527
 
@@ -543,10 +543,10 @@  discard block
 block discarded – undo
543 543
 		 *
544 544
 		 * @param array  Array of allowed \WP_Query query vars.
545 545
 		 */
546
-		$valid_vars = apply_filters( 'query_vars', $wp->public_query_vars );
546
+		$valid_vars = apply_filters('query_vars', $wp->public_query_vars);
547 547
 
548
-		$post_type_obj = get_post_type_object( $this->post_type );
549
-		if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
548
+		$post_type_obj = get_post_type_object($this->post_type);
549
+		if (current_user_can($post_type_obj->cap->edit_posts)) {
550 550
 			/**
551 551
 			 * Filter the allowed 'private' query vars for authorized users.
552 552
 			 *
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 			 * @param array $private_query_vars Array of allowed query vars for authorized users.
561 561
 			 * }
562 562
 			 */
563
-			$private = apply_filters( 'woocommerce_rest_private_query_vars', $wp->private_query_vars );
564
-			$valid_vars = array_merge( $valid_vars, $private );
563
+			$private = apply_filters('woocommerce_rest_private_query_vars', $wp->private_query_vars);
564
+			$valid_vars = array_merge($valid_vars, $private);
565 565
 		}
566 566
 		// Define our own in addition to WP's normal vars.
567 567
 		$rest_valid = array(
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 			'meta_compare',
582 582
 			'meta_value_num',
583 583
 		);
584
-		$valid_vars = array_merge( $valid_vars, $rest_valid );
584
+		$valid_vars = array_merge($valid_vars, $rest_valid);
585 585
 
586 586
 		/**
587 587
 		 * Filter allowed query vars for the REST API.
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 		 *    @param string $allowed_query_var The query var to allow.
597 597
 		 * }
598 598
 		 */
599
-		$valid_vars = apply_filters( 'woocommerce_rest_query_vars', $valid_vars );
599
+		$valid_vars = apply_filters('woocommerce_rest_query_vars', $valid_vars);
600 600
 
601 601
 		return $valid_vars;
602 602
 	}
@@ -612,19 +612,19 @@  discard block
 block discarded – undo
612 612
 		$params['context']['default'] = 'view';
613 613
 
614 614
 		$params['after'] = array(
615
-			'description'        => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
615
+			'description'        => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
616 616
 			'type'               => 'string',
617 617
 			'format'             => 'date-time',
618 618
 			'validate_callback'  => 'rest_validate_request_arg',
619 619
 		);
620 620
 		$params['before'] = array(
621
-			'description'        => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
621
+			'description'        => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
622 622
 			'type'               => 'string',
623 623
 			'format'             => 'date-time',
624 624
 			'validate_callback'  => 'rest_validate_request_arg',
625 625
 		);
626 626
 		$params['exclude'] = array(
627
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
627
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
628 628
 			'type'              => 'array',
629 629
 			'items'             => array(
630 630
 				'type'          => 'integer',
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 			'sanitize_callback' => 'wp_parse_id_list',
634 634
 		);
635 635
 		$params['include'] = array(
636
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
636
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
637 637
 			'type'              => 'array',
638 638
 			'items'             => array(
639 639
 				'type'          => 'integer',
@@ -642,20 +642,20 @@  discard block
 block discarded – undo
642 642
 			'sanitize_callback' => 'wp_parse_id_list',
643 643
 		);
644 644
 		$params['offset'] = array(
645
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
645
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
646 646
 			'type'               => 'integer',
647 647
 			'sanitize_callback'  => 'absint',
648 648
 			'validate_callback'  => 'rest_validate_request_arg',
649 649
 		);
650 650
 		$params['order'] = array(
651
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
651
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
652 652
 			'type'               => 'string',
653 653
 			'default'            => 'desc',
654
-			'enum'               => array( 'asc', 'desc' ),
654
+			'enum'               => array('asc', 'desc'),
655 655
 			'validate_callback'  => 'rest_validate_request_arg',
656 656
 		);
657 657
 		$params['orderby'] = array(
658
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
658
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
659 659
 			'type'               => 'string',
660 660
 			'default'            => 'date',
661 661
 			'enum'               => array(
@@ -668,11 +668,11 @@  discard block
 block discarded – undo
668 668
 			'validate_callback'  => 'rest_validate_request_arg',
669 669
 		);
670 670
 
671
-		$post_type_obj = get_post_type_object( $this->post_type );
671
+		$post_type_obj = get_post_type_object($this->post_type);
672 672
 
673
-		if ( isset( $post_type_obj->hierarchical ) && $post_type_obj->hierarchical ) {
673
+		if (isset($post_type_obj->hierarchical) && $post_type_obj->hierarchical) {
674 674
 			$params['parent'] = array(
675
-				'description'       => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
675
+				'description'       => __('Limit result set to those of particular parent IDs.', 'woocommerce'),
676 676
 				'type'              => 'array',
677 677
 				'items'             => array(
678 678
 					'type'          => 'integer',
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 				'default'           => array(),
682 682
 			);
683 683
 			$params['parent_exclude'] = array(
684
-				'description'       => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
684
+				'description'       => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'),
685 685
 				'type'              => 'array',
686 686
 				'items'             => array(
687 687
 					'type'          => 'integer',
@@ -691,10 +691,10 @@  discard block
 block discarded – undo
691 691
 			);
692 692
 		}
693 693
 
694
-		if ( 'wc/v1' === $this->namespace ) {
694
+		if ('wc/v1' === $this->namespace) {
695 695
 			$params['filter'] = array(
696 696
 				'type'        => 'object',
697
-				'description' => __( 'Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce' ),
697
+				'description' => __('Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce'),
698 698
 			);
699 699
 		}
700 700
 
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 	 * @param \WP_REST_Request $request Request object.
709 709
 	 * @return bool|\WP_Error
710 710
 	 */
711
-	protected function update_post_meta_fields( $post, $request ) {
711
+	protected function update_post_meta_fields($post, $request) {
712 712
 		return true;
713 713
 	}
714 714
 }
Please login to merge, or discard this patch.