Move `interval` collection param to a shared parent class

This commit is contained in:
Tomek Wytrębowicz 2023-05-01 22:10:22 +02:00
parent 766e19e109
commit 58bc88e0fc
7 changed files with 59 additions and 102 deletions

View File

@ -9,7 +9,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\API\Reports\AbstractController;
use Automattic\WooCommerce\Admin\API\Reports\GenericStatsController;
use Automattic\WooCommerce\Admin\API\Reports\ParameterException;
use WP_REST_Request;
use WP_REST_Response;
@ -18,9 +18,9 @@ use WP_REST_Response;
* REST API Reports coupons stats controller class.
*
* @internal
* @extends AbstractController
* @extends GenericStatsController
*/
class Controller extends AbstractController {
class Controller extends GenericStatsController {
/**
* Route base.
@ -251,20 +251,6 @@ class Controller extends AbstractController {
'coupons_count',
'orders_count',
);
$params['interval'] = array(
'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
'type' => 'string',
'default' => 'week',
'enum' => array(
'hour',
'day',
'week',
'month',
'quarter',
'year',
),
'validate_callback' => 'rest_validate_request_arg',
);
$params['coupons'] = array(
'description' => __( 'Limit result set to coupons assigned specific coupon IDs.', 'woocommerce' ),
'type' => 'array',

View File

@ -9,7 +9,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\API\Reports\AbstractController;
use Automattic\WooCommerce\Admin\API\Reports\GenericStatsController;
use WP_REST_Request;
use WP_REST_Response;
@ -17,9 +17,9 @@ use WP_REST_Response;
* REST API Reports downloads stats controller class.
*
* @internal
* @extends AbstractController
* @extends GenericStatsController
*/
class Controller extends AbstractController {
class Controller extends GenericStatsController {
/**
* Route base.
@ -205,20 +205,6 @@ class Controller extends AbstractController {
'date',
'download_count',
);
$params['interval'] = array(
'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
'type' => 'string',
'default' => 'week',
'enum' => array(
'hour',
'day',
'week',
'month',
'quarter',
'year',
),
'validate_callback' => 'rest_validate_request_arg',
);
$params['match'] = array(
'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ),
'type' => 'string',

View File

@ -0,0 +1,41 @@
<?php
namespace Automattic\WooCommerce\Admin\API\Reports;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\API\Reports\AbstractController;
/**
* Generic base for all Stats controllers.
*
* @internal
* @extends AbstractController
*/
abstract class GenericStatsController extends AbstractController {
/**
* Get the query params for collections.
* Adds intervals to the generic list.
*
* @return array
*/
public function get_collection_params() {
$params = parent::get_collection_params();
$params['interval'] = array(
'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
'type' => 'string',
'default' => 'week',
'enum' => array(
'hour',
'day',
'week',
'month',
'quarter',
'year',
),
'validate_callback' => 'rest_validate_request_arg',
);
return $params;
}
}

View File

@ -9,7 +9,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\API\Reports\AbstractController;
use Automattic\WooCommerce\Admin\API\Reports\GenericStatsController;
use Automattic\WooCommerce\Admin\API\Reports\ParameterException;
use WP_REST_Request;
use WP_REST_Response;
@ -18,9 +18,9 @@ use WP_REST_Response;
* REST API Reports products stats controller class.
*
* @internal
* @extends AbstractController
* @extends GenericStatsController
*/
class Controller extends AbstractController {
class Controller extends GenericStatsController {
/**
* Route base.
@ -296,20 +296,6 @@ class Controller extends AbstractController {
'orders_count',
'items_sold',
);
$params['interval'] = array(
'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
'type' => 'string',
'default' => 'week',
'enum' => array(
'hour',
'day',
'week',
'month',
'quarter',
'year',
),
'validate_callback' => 'rest_validate_request_arg',
);
$params['categories'] = array(
'description' => __( 'Limit result to items from the specified categories.', 'woocommerce' ),
'type' => 'array',

View File

@ -9,7 +9,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Revenue\Stats;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\API\Reports\AbstractController;
use Automattic\WooCommerce\Admin\API\Reports\GenericStatsController;
use Automattic\WooCommerce\Admin\API\Reports\Revenue\Query as RevenueQuery;
use Automattic\WooCommerce\Admin\API\Reports\ExportableInterface;
use Automattic\WooCommerce\Admin\API\Reports\ExportableTraits;
@ -21,9 +21,9 @@ use WP_REST_Response;
* REST API Reports revenue stats controller class.
*
* @internal
* @extends AbstractController
* @extends GenericStatsController
*/
class Controller extends AbstractController implements ExportableInterface {
class Controller extends GenericStatsController implements ExportableInterface {
/**
* Exportable traits.
*/
@ -341,20 +341,6 @@ class Controller extends AbstractController implements ExportableInterface {
'items_sold',
'gross_sales',
);
$params['interval'] = array(
'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
'type' => 'string',
'default' => 'week',
'enum' => array(
'hour',
'day',
'week',
'month',
'quarter',
'year',
),
'validate_callback' => 'rest_validate_request_arg',
);
$params['segmentby'] = array(
'description' => __( 'Segment the response by additional constraint.', 'woocommerce' ),
'type' => 'string',

View File

@ -9,7 +9,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\API\Reports\AbstractController;
use Automattic\WooCommerce\Admin\API\Reports\GenericStatsController;
use WP_REST_Request;
use WP_REST_Response;
@ -17,9 +17,9 @@ use WP_REST_Response;
* REST API Reports taxes stats controller class.
*
* @internal
* @extends AbstractController
* @extends GenericStatsController
*/
class Controller extends AbstractController {
class Controller extends GenericStatsController {
/**
* Route base.
@ -291,20 +291,6 @@ class Controller extends AbstractController {
'orders_count',
'products_count',
);
$params['interval'] = array(
'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
'type' => 'string',
'default' => 'week',
'enum' => array(
'hour',
'day',
'week',
'month',
'quarter',
'year',
),
'validate_callback' => 'rest_validate_request_arg',
);
$params['taxes'] = array(
'description' => __( 'Limit result set to all items that have the specified term assigned in the taxes taxonomy.', 'woocommerce' ),
'type' => 'array',

View File

@ -9,7 +9,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Variations\Stats;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\API\Reports\AbstractController;
use Automattic\WooCommerce\Admin\API\Reports\GenericStatsController;
use Automattic\WooCommerce\Admin\API\Reports\ParameterException;
use WP_REST_Request;
use WP_REST_Response;
@ -18,9 +18,9 @@ use WP_REST_Response;
* REST API Reports variations stats controller class.
*
* @internal
* @extends AbstractController
* @extends GenericStatsController
*/
class Controller extends AbstractController {
class Controller extends GenericStatsController {
/**
* Route base.
@ -309,20 +309,6 @@ class Controller extends AbstractController {
'orders_count',
'items_sold',
);
$params['interval'] = array(
'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ),
'type' => 'string',
'default' => 'week',
'enum' => array(
'hour',
'day',
'week',
'month',
'quarter',
'year',
),
'validate_callback' => 'rest_validate_request_arg',
);
$params['category_includes'] = array(
'description' => __( 'Limit result to items from the specified categories.', 'woocommerce' ),
'type' => 'array',