From 6f85c27d4fd55aba23db9674862d7df0f72a074d Mon Sep 17 00:00:00 2001 From: Amine Ben hammou Date: Wed, 27 Mar 2019 17:26:05 +0100 Subject: [PATCH] Fix PHPStan warnings --- lib/WP/Functions.php | 23 ++++++++++++++++++++--- lib/WooCommerce/Helper.php | 13 ++----------- tasks/phpstan/bootstrap.php | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lib/WP/Functions.php b/lib/WP/Functions.php index 0903360b2f..fe0c481bb1 100644 --- a/lib/WP/Functions.php +++ b/lib/WP/Functions.php @@ -19,15 +19,32 @@ class Functions { self::$instance = $instance; } - function doAction() { + /** + * @param string $tag + * @param mixed ...$args + * @return mixed + */ + function doAction($tag, ...$args) { return call_user_func_array('do_action', func_get_args()); } - function applyFilters() { + /** + * @param string $tag + * @param mixed ...$args + * @return mixed + */ + function applyFilters($tag, ...$args) { return call_user_func_array('apply_filters', func_get_args()); } - function addAction() { + /** + * @param string $tag + * @param callable $function_to_add + * @param int $priority + * @param int $accepted_args + * @return boolean + */ + function addAction($tag, $function_to_add, $priority = 10, $accepted_args = 1) { return call_user_func_array('add_action', func_get_args()); } diff --git a/lib/WooCommerce/Helper.php b/lib/WooCommerce/Helper.php index b24f6545f6..c77305cb67 100644 --- a/lib/WooCommerce/Helper.php +++ b/lib/WooCommerce/Helper.php @@ -5,25 +5,16 @@ class Helper { function isWooCommerceActive() { return class_exists('WooCommerce'); } + function wcGetCustomerOrderCount($user_id) { - if (! is_callable('wc_get_customer_order_count')) { - throw new \Exception("function 'wc_get_customer_order_count' not found!"); - } return wc_get_customer_order_count($user_id); } - function wcGetOrder($order = false) { - if (! is_callable('wc_get_order')) { - throw new \Exception("function 'wc_get_order' not found!"); - } + function wcGetOrder($order = false) { return wc_get_order($order); } function wcPrice($price, array $args = array()) { - if (! is_callable('wc_price')) { - throw new \Exception("function 'wc_price' not found!"); - - } return wc_price($price, $args); } } diff --git a/tasks/phpstan/bootstrap.php b/tasks/phpstan/bootstrap.php index ea398de575..01500d6490 100644 --- a/tasks/phpstan/bootstrap.php +++ b/tasks/phpstan/bootstrap.php @@ -4,3 +4,19 @@ define('ABSPATH', getenv('WP_ROOT') . '/'); require_once ABSPATH . 'wp-load.php'; require_once ABSPATH . 'wp-admin/includes/admin.php'; + +function wc_get_customer_order_count(int $user_id): int { + return 0; +} + +/** + * @param mixed $order + * @return mixed + */ +function wc_get_order($order = false) { + return false; +} + +function wc_price(float $price, array $args = []): string { + return ''; +} \ No newline at end of file