Skip to content

Commit fad2aab

Browse files
authored
Use generics in throw_if and throw_unless to indicate dynamic exception type (#47938)
1 parent d3586eb commit fad2aab

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Illuminate/Support/helpers.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,14 @@ function tap($value, $callback = null)
314314
/**
315315
* Throw the given exception if the given condition is true.
316316
*
317+
* @template TException of \Throwable
318+
*
317319
* @param mixed $condition
318-
* @param \Throwable|string $exception
320+
* @param TException|class-string<TException> $exception
319321
* @param mixed ...$parameters
320322
* @return mixed
321323
*
322-
* @throws \Throwable
324+
* @throws TException
323325
*/
324326
function throw_if($condition, $exception = 'RuntimeException', ...$parameters)
325327
{
@@ -339,12 +341,14 @@ function throw_if($condition, $exception = 'RuntimeException', ...$parameters)
339341
/**
340342
* Throw the given exception unless the given condition is true.
341343
*
344+
* @template TException of \Throwable
345+
*
342346
* @param mixed $condition
343-
* @param \Throwable|string $exception
347+
* @param TException|class-string<TException> $exception
344348
* @param mixed ...$parameters
345349
* @return mixed
346350
*
347-
* @throws \Throwable
351+
* @throws TException
348352
*/
349353
function throw_unless($condition, $exception = 'RuntimeException', ...$parameters)
350354
{

0 commit comments

Comments
 (0)