From 4f81bf9e4fd508dd829ecf4db1773ff9dc6017c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Mon, 14 Oct 2024 12:07:10 +0200 Subject: [PATCH 1/2] let return type reflect actual behavior with falsey values --- src/Illuminate/Support/helpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index b7f3a33a1199..5abe5befd5b0 100644 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -393,7 +393,7 @@ function tap($value, $callback = null) * @param TValue $condition * @param TException|class-string|string $exception * @param mixed ...$parameters - * @return ($condition is true ? never : TValue) + * @return ($condition is non-empty-mixed ? never : TValue) * * @throws TException */ @@ -421,7 +421,7 @@ function throw_if($condition, $exception = 'RuntimeException', ...$parameters) * @param TValue $condition * @param TException|class-string|string $exception * @param mixed ...$parameters - * @return ($condition is true ? TValue : never) + * @return ($condition is non-empty-mixed ? TValue : never) * * @throws TException */ From 8eb32c3892974727178d6489a6d8d1ecb7d3b070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Mon, 14 Oct 2024 12:31:12 +0200 Subject: [PATCH 2/2] let type assertions reflect actual behavior with falsey values --- types/Support/Helpers.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/types/Support/Helpers.php b/types/Support/Helpers.php index 1c0f63ea3d7d..d0201de6172d 100644 --- a/types/Support/Helpers.php +++ b/types/Support/Helpers.php @@ -46,10 +46,9 @@ function testThrowIf(float|int $foo): void assertType('never', throw_if(true, Exception::class)); assertType('bool', throw_if(false, Exception::class)); assertType('false', throw_if(empty($foo))); - throw_if(is_float($foo)); - assertType('int', $foo); - throw_if($foo == false); - assertType('int|int<1, max>', $foo); + assertType('null', throw_if(null, Exception::class)); + assertType('string', throw_if('', Exception::class)); + assertType('never', throw_if('foo', Exception::class)); } function testThrowUnless(float|int $foo): void @@ -58,9 +57,9 @@ function testThrowUnless(float|int $foo): void assertType('never', throw_unless(false, Exception::class)); assertType('true', throw_unless(empty($foo))); throw_unless(is_int($foo)); - assertType('int', $foo); - throw_unless($foo == false); - assertType('0', $foo); + assertType('never', throw_unless(null, Exception::class)); + assertType('never', throw_unless('', Exception::class)); + assertType('string', throw_unless('foo', Exception::class)); } assertType('int', transform('filled', fn () => 1, true));