From 300522ad2f07fd4cbfbd8952d0e46edc6a928f9e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 27 Feb 2026 00:47:34 +0700 Subject: [PATCH] Fix Filter Assert on callable without return type --- src/Assert/Filter.php | 9 +++++---- tests/FilterTest.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Assert/Filter.php b/src/Assert/Filter.php index 2e6a79b..533f192 100644 --- a/src/Assert/Filter.php +++ b/src/Assert/Filter.php @@ -10,6 +10,7 @@ use ReflectionIntersectionType; use ReflectionMethod; use ReflectionNamedType; +use ReflectionType; use ReflectionUnionType; use Webmozart\Assert\Assert; @@ -37,6 +38,9 @@ public static function boolean(callable $filter): void }; $returnType = $reflection->getReturnType(); + if (! $returnType instanceof ReflectionType) { + throw new InvalidArgumentException(sprintf(self::MESSAGE, 'none')); + } if ($returnType instanceof ReflectionUnionType || $returnType instanceof ReflectionIntersectionType) { $separator = $returnType instanceof ReflectionUnionType ? '|' : '&'; @@ -68,12 +72,9 @@ function (ReflectionNamedType|ReflectionIntersectionType $reflectionType): strin ); } - if (! $returnType instanceof ReflectionNamedType) { - throw new InvalidArgumentException(sprintf(self::MESSAGE, 'mixed')); - } + Assert::isInstanceOf($returnType, ReflectionNamedType::class); $returnTypeName = $returnType->getName(); - if ($returnType->allowsNull()) { throw new InvalidArgumentException(sprintf( self::MESSAGE, diff --git a/tests/FilterTest.php b/tests/FilterTest.php index b9ecad0..ab3a9f6 100644 --- a/tests/FilterTest.php +++ b/tests/FilterTest.php @@ -37,7 +37,7 @@ public function testOnceWithStringFilter(): void public function testWithoutReturnTypeCallable(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Expected a bool return type on callable filter, mixed given'); + $this->expectExceptionMessage('Expected a bool return type on callable filter, none given'); $data = [1, 2, 3];