Skip to content

Commit 50abdaa

Browse files
authored
Optimized phpdoc (#6927)
1 parent 9d71202 commit 50abdaa

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/Functions.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
/**
2626
* Return the default value of the given value.
27+
* @template TValue
28+
* @template TReturn
29+
*
30+
* @param (Closure(TValue):TReturn)|TValue $value
31+
* @return ($value is Closure ? TReturn : TValue)
2732
*/
2833
function value(mixed $value, ...$args)
2934
{
@@ -65,8 +70,12 @@ function env($key, $default = null)
6570
/**
6671
* Retry an operation a given number of times.
6772
*
73+
* @template TReturn
74+
*
6875
* @param float|int|int[] $times
76+
* @param callable(int):TReturn $callback
6977
* @param int $sleep millisecond
78+
* @return TReturn|void
7079
* @throws Throwable
7180
*/
7281
function retry($times, callable $callback, int $sleep = 0)
@@ -96,9 +105,11 @@ function retry($times, callable $callback, int $sleep = 0)
96105
* Return the given value, optionally passed through the given callback.
97106
*
98107
* @template TValue
108+
* @template TReturn
99109
*
100110
* @param TValue $value
101-
* @return ($callback is null ? TValue : mixed)
111+
* @param null|(callable(TValue):TReturn) $callback
112+
* @return ($callback is null ? TValue : TReturn)
102113
*/
103114
function with($value, ?callable $callback = null)
104115
{
@@ -223,9 +234,12 @@ function swoole_hook_flags(): int
223234

224235
/**
225236
* Provide access to optional objects.
237+
* @template TValue
238+
* @template TReturn
226239
*
227-
* @param mixed $value
228-
* @return mixed
240+
* @param TValue $value
241+
* @param null|(callable(TValue):TReturn) $callback
242+
* @return ($callback is null ? Optional<TValue> : ($value is null ? null : TReturn))
229243
*/
230244
function optional($value = null, ?callable $callback = null)
231245
{

src/Optional.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Hyperf\Collection\Arr;
1717
use Hyperf\Macroable\Macroable;
1818

19+
/**
20+
* @template TValue
21+
*/
1922
class Optional implements ArrayAccess
2023
{
2124
use Macroable {
@@ -25,7 +28,7 @@ class Optional implements ArrayAccess
2528
/**
2629
* Create a new optional instance.
2730
*
28-
* @param mixed $value the underlying object
31+
* @param TValue $value the underlying object
2932
*/
3033
public function __construct(protected $value)
3134
{

0 commit comments

Comments
 (0)