From 612eea76eec2a22f41b0e24be27f49454e4fd5f5 Mon Sep 17 00:00:00 2001 From: ChinaMoli Date: Fri, 23 Aug 2024 15:54:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=BE=85=E5=8A=A9=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helper.php | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/helper.php b/src/helper.php index 0a14735..c40bc15 100644 --- a/src/helper.php +++ b/src/helper.php @@ -16,12 +16,15 @@ /** * 按条件抛异常 * - * @param mixed $condition - * @param Throwable|string $exception - * @param array ...$parameters - * @return mixed + * @template TValue + * @template TException of \Throwable + * + * @param TValue $condition + * @param TException|class-string|string $exception + * @param mixed ...$parameters + * @return TValue * - * @throws Throwable + * @throws TException */ function throw_if($condition, $exception, ...$parameters) { @@ -37,11 +40,15 @@ function throw_if($condition, $exception, ...$parameters) /** * 按条件抛异常 * - * @param mixed $condition - * @param Throwable|string $exception - * @param array ...$parameters - * @return mixed - * @throws Throwable + * @template TValue + * @template TException of \Throwable + * + * @param TValue $condition + * @param TException|class-string|string $exception + * @param mixed ...$parameters + * @return TValue + * + * @throws TException */ function throw_unless($condition, $exception, ...$parameters) { @@ -57,9 +64,11 @@ function throw_unless($condition, $exception, ...$parameters) /** * 对一个值调用给定的闭包,然后返回该值 * - * @param mixed $value - * @param callable|null $callback - * @return mixed + * @template TValue + * + * @param TValue $value + * @param (callable(TValue): mixed)|null $callback + * @return TValue */ function tap($value, $callback = null) { @@ -77,8 +86,10 @@ function tap($value, $callback = null) /** * Return the default value of the given value. * - * @param mixed $value - * @return mixed + * @template TValue + * + * @param TValue|\Closure(): TValue $value + * @return TValue */ function value($value) {