Skip to content

Commit

Permalink
refactor: Add type hinting to tap function and HigherOrderTapProxy cl…
Browse files Browse the repository at this point in the history
…ass (#6922)
  • Loading branch information
huangdijia committed Jul 1, 2024
1 parent b2c7ef4 commit 6f4001a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

/**
* Call the given Closure with the given value then return the value.
*
* @param mixed $value
* @template TValue
* @param TValue $value
* @param null|callable $callback
* @return mixed
* @return ($callback is null ? HigherOrderTapProxy<TValue> : TValue)
*/
function tap($value, $callback = null)
{
Expand Down
9 changes: 6 additions & 3 deletions src/HigherOrderTapProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@

namespace Hyperf\Tappable;

/**
* @template TValue
*/
class HigherOrderTapProxy
{
/**
* The target being tapped.
*
* @var mixed
* @var TValue
*/
public $target;

/**
* Create a new tap proxy instance.
*
* @param mixed $target
* @param TValue of object $target
*/
public function __construct($target)
{
Expand All @@ -36,7 +39,7 @@ public function __construct($target)
*
* @param string $method
* @param array $parameters
* @return mixed
* @return TValue
*/
public function __call($method, $parameters)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tappable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait Tappable
* Call the given Closure with this instance then return the instance.
*
* @param null|callable $callback
* @return $this|HigherOrderTapProxy
* @return ($callback is null ? HigherOrderTapProxy : $this)
*/
public function tap($callback = null)
{
Expand Down

0 comments on commit 6f4001a

Please sign in to comment.