Skip to content

Commit

Permalink
Add dynamic return types to rescue helper (#48062)
Browse files Browse the repository at this point in the history
  • Loading branch information
axlon authored Aug 14, 2023
1 parent 5a7f2b4 commit e5e7704
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,13 @@ function request($key = null, $default = null)
/**
* Catch a potential exception and return a default value.
*
* @param callable $callback
* @param mixed $rescue
* @template TRescueValue
* @template TRescueFallback
*
* @param callable(): TRescueValue $callback
* @param (callable(\Throwable): TRescueFallback)|TRescueFallback $rescue
* @param bool|callable $report
* @return mixed
* @return TRescueValue|TRescueFallback
*/
function rescue(callable $callback, $rescue = null, $report = true)
{
Expand Down
4 changes: 4 additions & 0 deletions types/Support/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@
assertType('null', transform(null, fn () => 1));
assertType('null', transform('', fn () => 1));
assertType('null', transform([], fn () => 1));

assertType('int|null', rescue(fn () => 123));
assertType('int', rescue(fn () => 123, 345));
assertType('int', rescue(fn () => 123, fn () => 345));

0 comments on commit e5e7704

Please sign in to comment.