code standards

This commit is contained in:
Mike Jolley 2019-06-13 10:47:16 +01:00
parent ee949427e3
commit a1e9b457c0
9 changed files with 72 additions and 57 deletions

View File

@ -23,8 +23,9 @@ checks:
verify_property_names: false
filter:
excluded_paths:
- src/RestApi/Version1/
- src/RestApi/Version2/
- src/RestApi/Version3/
- src/Controllers/Version1/
- src/Controllers/Version2/
- src/Controllers/Version3/
- unit-tests/
- vendor/
- classmap.php

View File

@ -175,7 +175,7 @@ class Continents extends DataController {
*
* @since 3.5.0
* @param \WP_REST_Request $request Request data.
* @return \WP_Error\WP_REST_Response
* @return \WP_Error|\WP_REST_Response
*/
public function get_item( $request ) {
$data = $this->get_continent( strtoupper( $request['location'] ), $request );

View File

@ -131,7 +131,7 @@ class Orders extends AbstractObjectsController {
*
* @since 3.0.0
* @param int $id Object ID.
* @return WC_Data|bool
* @return \WC_Data|bool
*/
protected function get_object( $id ) {
$order = wc_get_order( $id );
@ -146,7 +146,7 @@ class Orders extends AbstractObjectsController {
/**
* Expands an order item to get its data.
*
* @param WC_Order_item $item Order item data.
* @param \WC_Order_item $item Order item data.
* @return array
*/
protected function get_order_item_data( $item ) {
@ -198,7 +198,7 @@ class Orders extends AbstractObjectsController {
* Get formatted item data.
*
* @since 3.0.0
* @param WC_Data $object WC_Data instance.
* @param \WC_Data $object WC_Data instance.
* @return array
*/
protected function get_formatted_item_data( $object ) {
@ -312,7 +312,7 @@ class Orders extends AbstractObjectsController {
* refers to object type being prepared for the response.
*
* @param \WP_REST_Response $response The response object.
* @param WC_Data $object Object data.
* @param \WC_Data $object Object data.
* @param \WP_REST_Request $request Request object.
*/
return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
@ -460,7 +460,7 @@ class Orders extends AbstractObjectsController {
/**
* Prepare a single order for create or update.
*
* @throws WC_REST_Exception When fails to set any item.
* @throws \WC_REST_Exception When fails to set any item.
* @param \WP_REST_Request $request Request object.
* @param bool $creating If is creating a new object.
* @return \WP_Error|WC_Data
@ -522,7 +522,7 @@ class Orders extends AbstractObjectsController {
* The dynamic portion of the hook name, `$this->post_type`,
* refers to the object type slug.
*
* @param WC_Data $order Object object.
* @param \WC_Data $order Object object.
* @param \WP_REST_Request $request Request object.
* @param bool $creating If is creating a new object.
*/
@ -531,10 +531,10 @@ class Orders extends AbstractObjectsController {
/**
* Save an object data.
* *
*
* @param \WP_REST_Request $request Full details about the request.
* @param bool $creating If is creating a new object.
* @return WC_Data|\WP_Error
* @return \WC_Data|\WP_Error
* @throws \WC_REST_Exception But all errors are validated before returning any data.
*/
protected function save_object( $request, $creating = false ) {
@ -710,8 +710,8 @@ class Orders extends AbstractObjectsController {
* @param array $posted $shipping Item data.
* @param string $action 'create' to add shipping or 'update' to update it.
* @param object $item Passed when updating an item. Null during creation.
* @return WC_Order_Item_Shipping
* @throws WC_REST_Exception Invalid data, server error.
* @return \WC_Order_Item_Shipping
* @throws \WC_REST_Exception Invalid data, server error.
*/
protected function prepare_shipping_lines( $posted, $action = 'create', $item = null ) {
$item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
@ -734,8 +734,8 @@ class Orders extends AbstractObjectsController {
* @param array $posted Item data.
* @param string $action 'create' to add fee or 'update' to update it.
* @param object $item Passed when updating an item. Null during creation.
* @return WC_Order_Item_Fee
* @throws WC_REST_Exception Invalid data, server error.
* @return \WC_Order_Item_Fee
* @throws \WC_REST_Exception Invalid data, server error.
*/
protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) {
$item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
@ -758,8 +758,8 @@ class Orders extends AbstractObjectsController {
* @param array $posted Item data.
* @param string $action 'create' to add coupon or 'update' to update it.
* @param object $item Passed when updating an item. Null during creation.
* @return WC_Order_Item_Coupon
* @throws WC_REST_Exception Invalid data, server error.
* @return \WC_Order_Item_Coupon
* @throws \WC_REST_Exception Invalid data, server error.
*/
protected function prepare_coupon_lines( $posted, $action = 'create', $item = null ) {
$item = is_null( $item ) ? new \WC_Order_Item_Coupon( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
@ -781,10 +781,10 @@ class Orders extends AbstractObjectsController {
* When updating, the item ID provided is checked to ensure it is associated
* with the order.
*
* @param WC_Order $order order object.
* @param \WC_Order $order order object.
* @param string $item_type The item type.
* @param array $posted item provided in the request body.
* @throws WC_REST_Exception If item ID is not associated with order.
* @throws \WC_REST_Exception If item ID is not associated with order.
*/
protected function set_item( $order, $item_type, $posted ) {
global $wpdb;

View File

@ -133,7 +133,7 @@ class ProductAttributeTerms extends AbstractTermsContoller {
/**
* Prepare a single product attribute term output for response.
*
* @param WP_Term $item Term object.
* @param \WP_Term $item Term object.
* @param \WP_REST_Request $request Request params.
* @return \WP_REST_Response $response
*/
@ -173,7 +173,7 @@ class ProductAttributeTerms extends AbstractTermsContoller {
/**
* Update term meta fields.
*
* @param WP_Term $term Term object.
* @param \WP_Term $term Term object.
* @param \WP_REST_Request $request Request params.
* @return bool|\WP_Error
*/

View File

@ -33,7 +33,7 @@ class ProductShippingClasses extends AbstractTermsContoller {
/**
* Prepare a single product shipping class output for response.
*
* @param obj $item Term object.
* @param object $item Term object.
* @param \WP_REST_Request $request Request params.
* @return \WP_REST_Response $response
*/

View File

@ -136,7 +136,7 @@ class Products extends AbstractObjectsController {
* @param int $id Object ID.
*
* @since 3.0.0
* @return WC_Data
* @return \WC_Data
*/
protected function get_object( $id ) {
return wc_get_product( $id );
@ -145,7 +145,7 @@ class Products extends AbstractObjectsController {
/**
* Prepare a single product output for response.
*
* @param WC_Data $object Object data.
* @param \WC_Data $object Object data.
* @param \WP_REST_Request $request Request object.
*
* @since 3.0.0
@ -177,7 +177,7 @@ class Products extends AbstractObjectsController {
* refers to object type being prepared for the response.
*
* @param \WP_REST_Response $response The response object.
* @param WC_Data $object Object data.
* @param \WC_Data $object Object data.
* @param \WP_REST_Request $request Request object.
*/
return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
@ -188,7 +188,7 @@ class Products extends AbstractObjectsController {
*
* @param \WP_REST_Request $request Request object.
* @param bool $creating If is creating a new object.
* @return \WP_Error|WC_Data
* @return \WP_Error|\WC_Data
*/
protected function prepare_object_for_database( $request, $creating = false ) {
$id = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
@ -1173,7 +1173,7 @@ class Products extends AbstractObjectsController {
/**
* Prepare links for the request.
*
* @param WC_Data $object Object data.
* @param \WC_Data $object Object data.
* @param \WP_REST_Request $request Request object.
*
* @return array Links for the given post.
@ -1368,11 +1368,9 @@ class Products extends AbstractObjectsController {
/**
* Save default attributes.
*
* @param WC_Product $product Product instance.
* @param \WC_Product $product Product instance.
* @param \WP_REST_Request $request Request data.
*
* @since 3.0.0
* @return WC_Product
* @return \WC_Product
*/
protected function save_default_attributes( $product, $request ) {
if ( isset( $request['default_attributes'] ) && is_array( $request['default_attributes'] ) ) {
@ -2192,6 +2190,7 @@ class Products extends AbstractObjectsController {
'type' => 'string',
'validate_callback' => 'rest_validate_request_arg',
);
$params['status'] = array(
'default' => 'any',
'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce' ),
@ -2200,6 +2199,7 @@ class Products extends AbstractObjectsController {
'sanitize_callback' => 'sanitize_key',
'validate_callback' => 'rest_validate_request_arg',
);
$params['type'] = array(
'description' => __( 'Limit result set to products assigned a specific type.', 'woocommerce' ),
'type' => 'string',
@ -2207,42 +2207,49 @@ class Products extends AbstractObjectsController {
'sanitize_callback' => 'sanitize_key',
'validate_callback' => 'rest_validate_request_arg',
);
$params['sku'] = array(
'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);
$params['featured'] = array(
'description' => __( 'Limit result set to featured products.', 'woocommerce' ),
'type' => 'boolean',
'sanitize_callback' => 'wc_string_to_bool',
'validate_callback' => 'rest_validate_request_arg',
);
$params['category'] = array(
'description' => __( 'Limit result set to products assigned a specific category ID.', 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'wp_parse_id_list',
'validate_callback' => 'rest_validate_request_arg',
);
$params['tag'] = array(
'description' => __( 'Limit result set to products assigned a specific tag ID.', 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'wp_parse_id_list',
'validate_callback' => 'rest_validate_request_arg',
);
$params['shipping_class'] = array(
'description' => __( 'Limit result set to products assigned a specific shipping class ID.', 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'wp_parse_id_list',
'validate_callback' => 'rest_validate_request_arg',
);
$params['attribute'] = array(
'description' => __( 'Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug.', 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);
$params['attribute_term'] = array(
'description' => __( 'Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce' ),
'type' => 'string',
@ -2259,24 +2266,28 @@ class Products extends AbstractObjectsController {
'validate_callback' => 'rest_validate_request_arg',
);
}
$params['on_sale'] = array(
'description' => __( 'Limit result set to products on sale.', 'woocommerce' ),
'type' => 'boolean',
'sanitize_callback' => 'wc_string_to_bool',
'validate_callback' => 'rest_validate_request_arg',
);
$params['min_price'] = array(
'description' => __( 'Limit result set to products based on a minimum price.', 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);
$params['max_price'] = array(
'description' => __( 'Limit result set to products based on a maximum price.', 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);
$params['stock_status'] = array(
'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce' ),
'type' => 'string',
@ -2284,17 +2295,20 @@ class Products extends AbstractObjectsController {
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);
$params['low_in_stock'] = array(
'description' => __( 'Limit result set to products that are low or out of stock.', 'woocommerce' ),
'type' => 'boolean',
'default' => false,
'sanitize_callback' => 'wc_string_to_bool',
);
$params['search'] = array(
'description' => __( 'Search by similar product name or sku.', 'woocommerce' ),
'type' => 'string',
'validate_callback' => 'rest_validate_request_arg',
);
$params['orderby']['enum'] = array_merge( $params['orderby']['enum'], array( 'price', 'popularity', 'rating' ) );
return $params;