Skip to content

Commit

Permalink
Optimized phpdoc (#6927)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia authored Jul 4, 2024
1 parent 9d71202 commit 50abdaa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 4 additions & 1 deletion src/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Hyperf\Collection\Arr;
use Hyperf\Macroable\Macroable;

/**
* @template TValue
*/
class Optional implements ArrayAccess
{
use Macroable {
Expand All @@ -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)
{
Expand Down

0 comments on commit 50abdaa

Please sign in to comment.