Skip to content

Commit dc4a089

Browse files
committed
move repetitive message to class constant
1 parent 611360b commit dc4a089

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Assert/Filter.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
final class Filter
2323
{
24+
/**
25+
* @var string
26+
*/
27+
private const MESSAGE = 'Expected a bool return type on callable filter, %s given';
28+
2429
public static function boolean(callable $filter): void
2530
{
2631
if ($filter instanceof Closure) {
@@ -43,7 +48,7 @@ public static function boolean(callable $filter): void
4348

4449
throw new InvalidArgumentException(
4550
sprintf(
46-
'Expected a bool return type on callable filter, %s given',
51+
self::MESSAGE,
4752
implode($separator, array_map(
4853
static fn (ReflectionNamedType $reflectionNamedType): string => $reflectionNamedType->getName(),
4954
$types
@@ -53,13 +58,13 @@ public static function boolean(callable $filter): void
5358
}
5459

5560
if (! $returnType instanceof ReflectionNamedType) {
56-
throw new InvalidArgumentException('Expected a bool return type on callable filter, mixed given');
61+
throw new InvalidArgumentException(sprintf(self::MESSAGE, 'mixed'));
5762
}
5863

5964
$returnTypeName = $returnType->getName();
6065
if ($returnTypeName !== 'bool') {
6166
throw new InvalidArgumentException(sprintf(
62-
'Expected a bool return type on callable filter, %s given',
67+
self::MESSAGE,
6368
$returnTypeName
6469
));
6570
}

0 commit comments

Comments
 (0)