Skip to content

Commit

Permalink
feat: rescue parameter of rescue function now accepts the Throwable (
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdesign committed Oct 29, 2021
1 parent 695d005 commit 08ef81b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stubs/Helpers.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @template TDefault
*
* @param callable(): TValue $callback
* @param TDefault|(callable(): TDefault) $rescue
* @param TDefault|(callable(\Throwable): TDefault) $rescue
* @param bool $report
* @return TValue|TDefault
*/
Expand Down
18 changes: 17 additions & 1 deletion tests/Features/ReturnTypes/Helpers/RescueStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Exception;
use function PHPStan\Testing\assertType;
use Throwable;

class RescueStub
{
Expand Down Expand Up @@ -50,7 +51,22 @@ public function testRescueWithClosureDefault(): void
assertType('int|string', $rescued);
}

public function testRetryWithoutReporting(): void
public function testRescueWithClosureDefaultThrowable(): void
{
$rescued = rescue(function () {
if (mt_rand(0, 1)) {
throw new Exception();
}

return 'ok';
}, function (Throwable $e) {
return 0;
});

assertType('int|string', $rescued);
}

public function testRescueWithoutReporting(): void
{
$rescued = rescue(function () {
if (mt_rand(0, 1)) {
Expand Down

0 comments on commit 08ef81b

Please sign in to comment.