From 50abdaa18a441e960b1c4af89dc0be0385589479 Mon Sep 17 00:00:00 2001
From: Deeka Wong <huangdijia@gmail.com>
Date: Thu, 4 Jul 2024 10:13:45 +0800
Subject: [PATCH] Optimized phpdoc (#6927)

---
 src/Functions.php | 20 +++++++++++++++++---
 src/Optional.php  |  5 ++++-
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/Functions.php b/src/Functions.php
index e556404..0310762 100644
--- a/src/Functions.php
+++ b/src/Functions.php
@@ -24,6 +24,11 @@
 
 /**
  * Return the default value of the given value.
+ * @template TValue
+ * @template TReturn
+ *
+ * @param (Closure(TValue):TReturn)|TValue $value
+ * @return ($value is Closure ? TReturn : TValue)
  */
 function value(mixed $value, ...$args)
 {
@@ -65,8 +70,12 @@ function env($key, $default = null)
 /**
  * Retry an operation a given number of times.
  *
+ * @template TReturn
+ *
  * @param float|int|int[] $times
+ * @param callable(int):TReturn $callback
  * @param int $sleep millisecond
+ * @return TReturn|void
  * @throws Throwable
  */
 function retry($times, callable $callback, int $sleep = 0)
@@ -96,9 +105,11 @@ function retry($times, callable $callback, int $sleep = 0)
  * Return the given value, optionally passed through the given callback.
  *
  * @template TValue
+ * @template TReturn
  *
  * @param TValue $value
- * @return ($callback is null ? TValue : mixed)
+ * @param null|(callable(TValue):TReturn) $callback
+ * @return ($callback is null ? TValue : TReturn)
  */
 function with($value, ?callable $callback = null)
 {
@@ -223,9 +234,12 @@ function swoole_hook_flags(): int
 
 /**
  * Provide access to optional objects.
+ * @template TValue
+ * @template TReturn
  *
- * @param mixed $value
- * @return mixed
+ * @param TValue $value
+ * @param null|(callable(TValue):TReturn) $callback
+ * @return ($callback is null ? Optional<TValue> : ($value is null ? null : TReturn))
  */
 function optional($value = null, ?callable $callback = null)
 {
diff --git a/src/Optional.php b/src/Optional.php
index 6eb38f4..2c11e37 100644
--- a/src/Optional.php
+++ b/src/Optional.php
@@ -16,6 +16,9 @@
 use Hyperf\Collection\Arr;
 use Hyperf\Macroable\Macroable;
 
+/**
+ * @template TValue
+ */
 class Optional implements ArrayAccess
 {
     use Macroable {
@@ -25,7 +28,7 @@ class Optional implements ArrayAccess
     /**
      * Create a new optional instance.
      *
-     * @param mixed $value the underlying object
+     * @param TValue $value the underlying object
      */
     public function __construct(protected $value)
     {