Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Assert/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ReflectionIntersectionType;
use ReflectionMethod;
use ReflectionNamedType;
use ReflectionType;
use ReflectionUnionType;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -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 ? '|' : '&';
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down