diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 01ebf9d2aac..123a68901cd 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -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 diff --git a/src/Controllers/Version4/Data/Continents.php b/src/Controllers/Version4/Data/Continents.php index 69b76280515..557f9023448 100644 --- a/src/Controllers/Version4/Data/Continents.php +++ b/src/Controllers/Version4/Data/Continents.php @@ -67,7 +67,7 @@ class Continents extends DataController { * Return the list of countries and states for a given continent. * * @since 3.5.0 - * @param string $continent_code Continent code. + * @param string $continent_code Continent code. * @param \WP_REST_Request $request Request data. * @return array|mixed Response data, ready for insertion into collection data. */ @@ -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 ); @@ -189,7 +189,7 @@ class Continents extends DataController { * Prepare the data object for response. * * @since 3.5.0 - * @param object $item Data object. + * @param object $item Data object. * @param \WP_REST_Request $request Request object. * @return \WP_REST_Response $response Response data. */ @@ -206,7 +206,7 @@ class Continents extends DataController { * Allows modification of the loction data right before it is returned. * * @param \WP_REST_Response $response The response object. - * @param array $item The original list of continent(s), countries, and states. + * @param array $item The original list of continent(s), countries, and states. * @param \WP_REST_Request $request Request used to generate the response. */ return apply_filters( 'woocommerce_rest_prepare_data_continent', $response, $item, $request ); diff --git a/src/Controllers/Version4/Data/Countries.php b/src/Controllers/Version4/Data/Countries.php index c1993db8583..60c78e97d73 100644 --- a/src/Controllers/Version4/Data/Countries.php +++ b/src/Controllers/Version4/Data/Countries.php @@ -66,7 +66,7 @@ class Countries extends DataController { /** * Get a list of countries and states. * - * @param string $country_code Country code. + * @param string $country_code Country code. * @param \WP_REST_Request $request Request data. * @return array|mixed Response data, ready for insertion into collection data. */ @@ -136,7 +136,7 @@ class Countries extends DataController { * Prepare the data object for response. * * @since 3.5.0 - * @param object $item Data object. + * @param object $item Data object. * @param \WP_REST_Request $request Request object. * @return \WP_REST_Response $response Response data. */ diff --git a/src/Controllers/Version4/Data/Currencies.php b/src/Controllers/Version4/Data/Currencies.php index 3974edcaeb6..169767cc29c 100644 --- a/src/Controllers/Version4/Data/Currencies.php +++ b/src/Controllers/Version4/Data/Currencies.php @@ -76,7 +76,7 @@ class Currencies extends DataController { /** * Get currency information. * - * @param string $code Currency code. + * @param string $code Currency code. * @param \WP_REST_Request $request Request data. * @return array|mixed Response data, ready for insertion into collection data. */ @@ -142,7 +142,7 @@ class Currencies extends DataController { /** * Prepare the data object for response. * - * @param object $item Data object. + * @param object $item Data object. * @param \WP_REST_Request $request Request object. * @return \WP_REST_Response $response Response data. */ diff --git a/src/Controllers/Version4/Data/DownloadIPs.php b/src/Controllers/Version4/Data/DownloadIPs.php index 9d27f037d94..07d737792b7 100644 --- a/src/Controllers/Version4/Data/DownloadIPs.php +++ b/src/Controllers/Version4/Data/DownloadIPs.php @@ -84,7 +84,7 @@ class DownloadIPs extends DataController { * Prepare the data object for response. * * @since 3.5.0 - * @param object $item Data object. + * @param object $item Data object. * @param \WP_REST_Request $request Request object. * @return \WP_REST_Response $response Response data. */ diff --git a/src/Controllers/Version4/Orders.php b/src/Controllers/Version4/Orders.php index d1e85b61850..a082444c830 100644 --- a/src/Controllers/Version4/Orders.php +++ b/src/Controllers/Version4/Orders.php @@ -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 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. + * @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. */ protected function set_item( $order, $item_type, $posted ) { global $wpdb; @@ -1707,7 +1707,7 @@ class Orders extends AbstractObjectsController { public function get_collection_params() { $params = parent::get_collection_params(); - $params['status'] = array( + $params['status'] = array( 'default' => 'any', 'description' => __( 'Limit result set to orders which have specific statuses.', 'woocommerce' ), 'type' => 'array', diff --git a/src/Controllers/Version4/ProductAttributeTerms.php b/src/Controllers/Version4/ProductAttributeTerms.php index eeb20f54edd..7d831e0b633 100644 --- a/src/Controllers/Version4/ProductAttributeTerms.php +++ b/src/Controllers/Version4/ProductAttributeTerms.php @@ -31,7 +31,7 @@ class ProductAttributeTerms extends AbstractTermsContoller { $this->namespace, '/' . $this->rest_base, array( - 'args' => array( + 'args' => array( 'attribute_id' => array( 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), 'type' => 'integer', @@ -67,8 +67,8 @@ class ProductAttributeTerms extends AbstractTermsContoller { $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( - 'args' => array( - 'id' => array( + 'args' => array( + 'id' => array( 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), 'type' => 'integer', ), @@ -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 */ diff --git a/src/Controllers/Version4/ProductShippingClasses.php b/src/Controllers/Version4/ProductShippingClasses.php index 0df19fc7600..57c3a5fc5c5 100644 --- a/src/Controllers/Version4/ProductShippingClasses.php +++ b/src/Controllers/Version4/ProductShippingClasses.php @@ -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 */ diff --git a/src/Controllers/Version4/Products.php b/src/Controllers/Version4/Products.php index 1259175b973..bd27277997a 100644 --- a/src/Controllers/Version4/Products.php +++ b/src/Controllers/Version4/Products.php @@ -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 ); @@ -187,8 +187,8 @@ class Products extends AbstractObjectsController { * Prepare a single product for create or update. * * @param \WP_REST_Request $request Request object. - * @param bool $creating If is creating a new object. - * @return \WP_Error|WC_Data + * @param bool $creating If is creating a new object. + * @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'] ) ) { @@ -2187,12 +2185,13 @@ class Products extends AbstractObjectsController { public function get_collection_params() { $params = parent::get_collection_params(); - $params['slug'] = array( + $params['slug'] = array( 'description' => __( 'Limit result set to products with a specific slug.', 'woocommerce' ), 'type' => 'string', 'validate_callback' => 'rest_validate_request_arg', ); - $params['status'] = array( + + $params['status'] = array( 'default' => 'any', 'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce' ), 'type' => 'string', @@ -2200,49 +2199,57 @@ class Products extends AbstractObjectsController { 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg', ); - $params['type'] = array( + + $params['type'] = array( 'description' => __( 'Limit result set to products assigned a specific type.', 'woocommerce' ), 'type' => 'string', 'enum' => array_keys( wc_get_product_types() ), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg', ); - $params['sku'] = array( + + $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( + + $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( + + $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( + + $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( + + $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( + + $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( + + $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;