PSR-4ify the report parameter exception class.
This commit is contained in:
parent
57ece077a6
commit
a61d292c67
|
@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats;
|
|||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\ParameterException;
|
||||
|
||||
/**
|
||||
* REST API Reports coupons stats controller class.
|
||||
*
|
||||
|
@ -66,7 +68,7 @@ class Controller extends \WC_REST_Reports_Controller {
|
|||
$coupons_query = new Query( $query_args );
|
||||
try {
|
||||
$report_data = $coupons_query->get_data();
|
||||
} catch ( \WC_Admin_Reports_Parameter_Exception $e ) {
|
||||
} catch ( ParameterException $e ) {
|
||||
return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats;
|
|||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter;
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\ParameterException;
|
||||
|
||||
/**
|
||||
* Date & time interval and numeric range handling class for Reporting API.
|
||||
|
@ -275,7 +276,7 @@ class Segmenter extends ReportsSegmenter {
|
|||
$segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table );
|
||||
} elseif ( 'variation' === $this->query_args['segmentby'] ) {
|
||||
if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) {
|
||||
throw new \WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) );
|
||||
throw new ParameterException( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) );
|
||||
}
|
||||
|
||||
$segmenting_selections = array(
|
||||
|
|
|
@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Orders\Stats;
|
|||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\ParameterException;
|
||||
|
||||
/**
|
||||
* REST API Reports orders stats controller class.
|
||||
*
|
||||
|
@ -75,7 +77,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller {
|
|||
$orders_query = new Query( $query_args );
|
||||
try {
|
||||
$report_data = $orders_query->get_data();
|
||||
} catch ( \WC_Admin_Reports_Parameter_Exception $e ) {
|
||||
} catch ( ParameterException $e ) {
|
||||
return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Orders\Stats;
|
|||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter;
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\ParameterException;
|
||||
|
||||
/**
|
||||
* Date & time interval and numeric range handling class for Reporting API.
|
||||
|
@ -370,7 +371,7 @@ class Segmenter extends ReportsSegmenter {
|
|||
$segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table );
|
||||
} elseif ( 'variation' === $this->query_args['segmentby'] ) {
|
||||
if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) {
|
||||
throw new \WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) );
|
||||
throw new ParameterException( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) );
|
||||
}
|
||||
|
||||
$segmenting_selections = array(
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
* @package WooCommerce Admin
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\API\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC_Admin_Reports_Parameter_Exception class.
|
||||
*/
|
||||
class WC_Admin_Reports_Parameter_Exception extends WC_Data_Exception {}
|
||||
class ParameterException extends \WC_Data_Exception {}
|
|
@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats;
|
|||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\ParameterException;
|
||||
|
||||
/**
|
||||
* REST API Reports products stats controller class.
|
||||
*
|
||||
|
@ -80,7 +82,7 @@ class Controller extends \WC_REST_Reports_Controller {
|
|||
$query = new Query( $query_args );
|
||||
try {
|
||||
$report_data = $query->get_data();
|
||||
} catch ( \WC_Admin_Reports_Parameter_Exception $e ) {
|
||||
} catch ( ParameterException $e ) {
|
||||
return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats;
|
|||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter;
|
||||
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\ParameterException;
|
||||
|
||||
/**
|
||||
* Date & time interval and numeric range handling class for Reporting API.
|
||||
|
@ -163,7 +163,7 @@ class Segmenter extends ReportsSegmenter {
|
|||
$segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table );
|
||||
} elseif ( 'variation' === $this->query_args['segmentby'] ) {
|
||||
if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) {
|
||||
throw new \WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) );
|
||||
throw new ParameterException( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) );
|
||||
}
|
||||
|
||||
$segmenting_selections = array(
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Revenue\Stats;
|
|||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\Revenue\Query as RevenueQuery;
|
||||
use \Automattic\WooCommerce\Admin\API\Reports\ParameterException;
|
||||
|
||||
/**
|
||||
* REST API Reports revenue stats controller class.
|
||||
|
@ -66,7 +67,7 @@ class Controller extends \WC_REST_Reports_Controller {
|
|||
$reports_revenue = new RevenueQuery( $query_args );
|
||||
try {
|
||||
$report_data = $reports_revenue->get_data();
|
||||
} catch ( \WC_Admin_Reports_Parameter_Exception $e ) {
|
||||
} catch ( ParameterException $e ) {
|
||||
return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue