Conditions | 1 |
Paths | 1 |
Total Lines | 372 |
Code Lines | 295 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
142 | public function get_item_schema() { |
||
143 | $weight_unit = get_option( 'woocommerce_weight_unit' ); |
||
144 | $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
||
145 | $schema = array( |
||
146 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
||
147 | 'title' => 'product_variation', |
||
148 | 'type' => 'object', |
||
149 | 'properties' => array( |
||
150 | 'id' => array( |
||
151 | 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
||
152 | 'type' => 'integer', |
||
153 | 'context' => array( 'view', 'edit' ), |
||
154 | 'readonly' => true, |
||
155 | ), |
||
156 | 'name' => array( |
||
157 | 'description' => __( 'Product parent name.', 'woocommerce' ), |
||
158 | 'type' => 'string', |
||
159 | 'context' => array( 'view', 'edit' ), |
||
160 | ), |
||
161 | 'type' => array( |
||
162 | 'description' => __( 'Product type.', 'woocommerce' ), |
||
163 | 'type' => 'string', |
||
164 | 'default' => 'variation', |
||
165 | 'enum' => array( 'variation' ), |
||
166 | 'context' => array( 'view', 'edit' ), |
||
167 | ), |
||
168 | 'parent_id' => array( |
||
169 | 'description' => __( 'Product parent ID.', 'woocommerce' ), |
||
170 | 'type' => 'integer', |
||
171 | 'context' => array( 'view', 'edit' ), |
||
172 | ), |
||
173 | 'date_created' => array( |
||
174 | 'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ), |
||
175 | 'type' => 'date-time', |
||
176 | 'context' => array( 'view', 'edit' ), |
||
177 | 'readonly' => true, |
||
178 | ), |
||
179 | 'date_modified' => array( |
||
180 | 'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ), |
||
181 | 'type' => 'date-time', |
||
182 | 'context' => array( 'view', 'edit' ), |
||
183 | 'readonly' => true, |
||
184 | ), |
||
185 | 'description' => array( |
||
186 | 'description' => __( 'Variation description.', 'woocommerce' ), |
||
187 | 'type' => 'string', |
||
188 | 'context' => array( 'view', 'edit' ), |
||
189 | 'arg_options' => array( |
||
190 | 'sanitize_callback' => 'wp_filter_post_kses', |
||
191 | ), |
||
192 | ), |
||
193 | 'permalink' => array( |
||
194 | 'description' => __( 'Variation URL.', 'woocommerce' ), |
||
195 | 'type' => 'string', |
||
196 | 'format' => 'uri', |
||
197 | 'context' => array( 'view', 'edit' ), |
||
198 | 'readonly' => true, |
||
199 | ), |
||
200 | 'sku' => array( |
||
201 | 'description' => __( 'Unique identifier.', 'woocommerce' ), |
||
202 | 'type' => 'string', |
||
203 | 'context' => array( 'view', 'edit' ), |
||
204 | 'arg_options' => array( |
||
205 | 'sanitize_callback' => 'wc_clean', |
||
206 | ), |
||
207 | ), |
||
208 | 'price' => array( |
||
209 | 'description' => __( 'Current variation price.', 'woocommerce' ), |
||
210 | 'type' => 'string', |
||
211 | 'context' => array( 'view', 'edit' ), |
||
212 | 'readonly' => true, |
||
213 | ), |
||
214 | 'regular_price' => array( |
||
215 | 'description' => __( 'Variation regular price.', 'woocommerce' ), |
||
216 | 'type' => 'string', |
||
217 | 'context' => array( 'view', 'edit' ), |
||
218 | ), |
||
219 | 'sale_price' => array( |
||
220 | 'description' => __( 'Variation sale price.', 'woocommerce' ), |
||
221 | 'type' => 'string', |
||
222 | 'context' => array( 'view', 'edit' ), |
||
223 | ), |
||
224 | 'date_on_sale_from' => array( |
||
225 | 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), |
||
226 | 'type' => 'date-time', |
||
227 | 'context' => array( 'view', 'edit' ), |
||
228 | ), |
||
229 | 'date_on_sale_from_gmt' => array( |
||
230 | 'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ), |
||
231 | 'type' => 'date-time', |
||
232 | 'context' => array( 'view', 'edit' ), |
||
233 | ), |
||
234 | 'date_on_sale_to' => array( |
||
235 | 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
||
236 | 'type' => 'date-time', |
||
237 | 'context' => array( 'view', 'edit' ), |
||
238 | ), |
||
239 | 'date_on_sale_to_gmt' => array( |
||
240 | 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
||
241 | 'type' => 'date-time', |
||
242 | 'context' => array( 'view', 'edit' ), |
||
243 | ), |
||
244 | 'on_sale' => array( |
||
245 | 'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ), |
||
246 | 'type' => 'boolean', |
||
247 | 'context' => array( 'view', 'edit' ), |
||
248 | 'readonly' => true, |
||
249 | ), |
||
250 | 'status' => array( |
||
251 | 'description' => __( 'Variation status.', 'woocommerce' ), |
||
252 | 'type' => 'string', |
||
253 | 'default' => 'publish', |
||
254 | 'enum' => array_keys( get_post_statuses() ), |
||
255 | 'context' => array( 'view', 'edit' ), |
||
256 | ), |
||
257 | 'purchasable' => array( |
||
258 | 'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ), |
||
259 | 'type' => 'boolean', |
||
260 | 'context' => array( 'view', 'edit' ), |
||
261 | 'readonly' => true, |
||
262 | ), |
||
263 | 'virtual' => array( |
||
264 | 'description' => __( 'If the variation is virtual.', 'woocommerce' ), |
||
265 | 'type' => 'boolean', |
||
266 | 'default' => false, |
||
267 | 'context' => array( 'view', 'edit' ), |
||
268 | ), |
||
269 | 'downloadable' => array( |
||
270 | 'description' => __( 'If the variation is downloadable.', 'woocommerce' ), |
||
271 | 'type' => 'boolean', |
||
272 | 'default' => false, |
||
273 | 'context' => array( 'view', 'edit' ), |
||
274 | ), |
||
275 | 'downloads' => array( |
||
276 | 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
||
277 | 'type' => 'array', |
||
278 | 'context' => array( 'view', 'edit' ), |
||
279 | 'items' => array( |
||
280 | 'type' => 'object', |
||
281 | 'properties' => array( |
||
282 | 'id' => array( |
||
283 | 'description' => __( 'File ID.', 'woocommerce' ), |
||
284 | 'type' => 'string', |
||
285 | 'context' => array( 'view', 'edit' ), |
||
286 | ), |
||
287 | 'name' => array( |
||
288 | 'description' => __( 'File name.', 'woocommerce' ), |
||
289 | 'type' => 'string', |
||
290 | 'context' => array( 'view', 'edit' ), |
||
291 | ), |
||
292 | 'file' => array( |
||
293 | 'description' => __( 'File URL.', 'woocommerce' ), |
||
294 | 'type' => 'string', |
||
295 | 'context' => array( 'view', 'edit' ), |
||
296 | ), |
||
297 | ), |
||
298 | ), |
||
299 | ), |
||
300 | 'download_limit' => array( |
||
301 | 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
||
302 | 'type' => 'integer', |
||
303 | 'default' => -1, |
||
304 | 'context' => array( 'view', 'edit' ), |
||
305 | ), |
||
306 | 'download_expiry' => array( |
||
307 | 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
||
308 | 'type' => 'integer', |
||
309 | 'default' => -1, |
||
310 | 'context' => array( 'view', 'edit' ), |
||
311 | ), |
||
312 | 'tax_status' => array( |
||
313 | 'description' => __( 'Tax status.', 'woocommerce' ), |
||
314 | 'type' => 'string', |
||
315 | 'default' => 'taxable', |
||
316 | 'enum' => array( 'taxable', 'shipping', 'none' ), |
||
317 | 'context' => array( 'view', 'edit' ), |
||
318 | ), |
||
319 | 'tax_class' => array( |
||
320 | 'description' => __( 'Tax class.', 'woocommerce' ), |
||
321 | 'type' => 'string', |
||
322 | 'context' => array( 'view', 'edit' ), |
||
323 | ), |
||
324 | 'manage_stock' => array( |
||
325 | 'description' => __( 'Stock management at variation level.', 'woocommerce' ), |
||
326 | 'type' => 'boolean', |
||
327 | 'default' => false, |
||
328 | 'context' => array( 'view', 'edit' ), |
||
329 | ), |
||
330 | 'stock_quantity' => array( |
||
331 | 'description' => __( 'Stock quantity.', 'woocommerce' ), |
||
332 | 'type' => 'integer', |
||
333 | 'context' => array( 'view', 'edit' ), |
||
334 | ), |
||
335 | 'stock_status' => array( |
||
336 | 'description' => __( 'Controls the stock status of the product.', 'woocommerce' ), |
||
337 | 'type' => 'string', |
||
338 | 'default' => 'instock', |
||
339 | 'enum' => array_keys( wc_get_product_stock_status_options() ), |
||
340 | 'context' => array( 'view', 'edit' ), |
||
341 | ), |
||
342 | 'backorders' => array( |
||
343 | 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
||
344 | 'type' => 'string', |
||
345 | 'default' => 'no', |
||
346 | 'enum' => array( 'no', 'notify', 'yes' ), |
||
347 | 'context' => array( 'view', 'edit' ), |
||
348 | ), |
||
349 | 'backorders_allowed' => array( |
||
350 | 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
||
351 | 'type' => 'boolean', |
||
352 | 'context' => array( 'view', 'edit' ), |
||
353 | 'readonly' => true, |
||
354 | ), |
||
355 | 'backordered' => array( |
||
356 | 'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ), |
||
357 | 'type' => 'boolean', |
||
358 | 'context' => array( 'view', 'edit' ), |
||
359 | 'readonly' => true, |
||
360 | ), |
||
361 | 'weight' => array( |
||
362 | /* translators: %s: weight unit */ |
||
363 | 'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ), |
||
|
|||
364 | 'type' => 'string', |
||
365 | 'context' => array( 'view', 'edit' ), |
||
366 | ), |
||
367 | 'dimensions' => array( |
||
368 | 'description' => __( 'Variation dimensions.', 'woocommerce' ), |
||
369 | 'type' => 'object', |
||
370 | 'context' => array( 'view', 'edit' ), |
||
371 | 'properties' => array( |
||
372 | 'length' => array( |
||
373 | /* translators: %s: dimension unit */ |
||
374 | 'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ), |
||
375 | 'type' => 'string', |
||
376 | 'context' => array( 'view', 'edit' ), |
||
377 | ), |
||
378 | 'width' => array( |
||
379 | /* translators: %s: dimension unit */ |
||
380 | 'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ), |
||
381 | 'type' => 'string', |
||
382 | 'context' => array( 'view', 'edit' ), |
||
383 | ), |
||
384 | 'height' => array( |
||
385 | /* translators: %s: dimension unit */ |
||
386 | 'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ), |
||
387 | 'type' => 'string', |
||
388 | 'context' => array( 'view', 'edit' ), |
||
389 | ), |
||
390 | ), |
||
391 | ), |
||
392 | 'shipping_class' => array( |
||
393 | 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
||
394 | 'type' => 'string', |
||
395 | 'context' => array( 'view', 'edit' ), |
||
396 | ), |
||
397 | 'shipping_class_id' => array( |
||
398 | 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
||
399 | 'type' => 'string', |
||
400 | 'context' => array( 'view', 'edit' ), |
||
401 | 'readonly' => true, |
||
402 | ), |
||
403 | 'image' => array( |
||
404 | 'description' => __( 'Variation image data.', 'woocommerce' ), |
||
405 | 'type' => 'object', |
||
406 | 'context' => array( 'view', 'edit' ), |
||
407 | 'properties' => array( |
||
408 | 'id' => array( |
||
409 | 'description' => __( 'Image ID.', 'woocommerce' ), |
||
410 | 'type' => 'integer', |
||
411 | 'context' => array( 'view', 'edit' ), |
||
412 | ), |
||
413 | 'date_created' => array( |
||
414 | 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
||
415 | 'type' => 'date-time', |
||
416 | 'context' => array( 'view', 'edit' ), |
||
417 | 'readonly' => true, |
||
418 | ), |
||
419 | 'date_created_gmt' => array( |
||
420 | 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
||
421 | 'type' => 'date-time', |
||
422 | 'context' => array( 'view', 'edit' ), |
||
423 | 'readonly' => true, |
||
424 | ), |
||
425 | 'date_modified' => array( |
||
426 | 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
||
427 | 'type' => 'date-time', |
||
428 | 'context' => array( 'view', 'edit' ), |
||
429 | 'readonly' => true, |
||
430 | ), |
||
431 | 'date_modified_gmt' => array( |
||
432 | 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
||
433 | 'type' => 'date-time', |
||
434 | 'context' => array( 'view', 'edit' ), |
||
435 | 'readonly' => true, |
||
436 | ), |
||
437 | 'src' => array( |
||
438 | 'description' => __( 'Image URL.', 'woocommerce' ), |
||
439 | 'type' => 'string', |
||
440 | 'format' => 'uri', |
||
441 | 'context' => array( 'view', 'edit' ), |
||
442 | ), |
||
443 | 'name' => array( |
||
444 | 'description' => __( 'Image name.', 'woocommerce' ), |
||
445 | 'type' => 'string', |
||
446 | 'context' => array( 'view', 'edit' ), |
||
447 | ), |
||
448 | 'alt' => array( |
||
449 | 'description' => __( 'Image alternative text.', 'woocommerce' ), |
||
450 | 'type' => 'string', |
||
451 | 'context' => array( 'view', 'edit' ), |
||
452 | ), |
||
453 | ), |
||
454 | ), |
||
455 | 'attributes' => array( |
||
456 | 'description' => __( 'List of attributes.', 'woocommerce' ), |
||
457 | 'type' => 'array', |
||
458 | 'context' => array( 'view', 'edit' ), |
||
459 | 'items' => array( |
||
460 | 'type' => 'object', |
||
461 | 'properties' => array( |
||
462 | 'id' => array( |
||
463 | 'description' => __( 'Attribute ID.', 'woocommerce' ), |
||
464 | 'type' => 'integer', |
||
465 | 'context' => array( 'view', 'edit' ), |
||
466 | ), |
||
467 | 'name' => array( |
||
468 | 'description' => __( 'Attribute name.', 'woocommerce' ), |
||
469 | 'type' => 'string', |
||
470 | 'context' => array( 'view', 'edit' ), |
||
471 | ), |
||
472 | 'option' => array( |
||
473 | 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
||
474 | 'type' => 'string', |
||
475 | 'context' => array( 'view', 'edit' ), |
||
476 | ), |
||
477 | ), |
||
478 | ), |
||
479 | ), |
||
480 | 'menu_order' => array( |
||
481 | 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
||
482 | 'type' => 'integer', |
||
483 | 'context' => array( 'view', 'edit' ), |
||
484 | ), |
||
485 | 'meta_data' => array( |
||
486 | 'description' => __( 'Meta data.', 'woocommerce' ), |
||
487 | 'type' => 'array', |
||
488 | 'context' => array( 'view', 'edit' ), |
||
489 | 'items' => array( |
||
490 | 'type' => 'object', |
||
491 | 'properties' => array( |
||
492 | 'id' => array( |
||
493 | 'description' => __( 'Meta ID.', 'woocommerce' ), |
||
494 | 'type' => 'integer', |
||
495 | 'context' => array( 'view', 'edit' ), |
||
496 | 'readonly' => true, |
||
497 | ), |
||
498 | 'key' => array( |
||
499 | 'description' => __( 'Meta key.', 'woocommerce' ), |
||
500 | 'type' => 'string', |
||
501 | 'context' => array( 'view', 'edit' ), |
||
502 | ), |
||
503 | 'value' => array( |
||
504 | 'description' => __( 'Meta value.', 'woocommerce' ), |
||
505 | 'type' => 'mixed', |
||
506 | 'context' => array( 'view', 'edit' ), |
||
507 | ), |
||
508 | ), |
||
509 | ), |
||
510 | ), |
||
511 | ), |
||
512 | ); |
||
513 | return $this->add_additional_fields_schema( $schema ); |
||
514 | } |
||
903 |