Skip to content

Commit 87743da

Browse files
committed
phpstan fix
1 parent 8d50f6d commit 87743da

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Assert/Filter.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,32 @@
44

55
namespace ArrayLookup\Assert;
66

7+
use Closure;
78
use InvalidArgumentException;
89
use ReflectionFunction;
910
use ReflectionMethod;
1011
use ReflectionNamedType;
11-
use TypeError;
12+
use Webmozart\Assert\Assert;
1213

1314
use function sprintf;
1415

1516
final class Filter
1617
{
1718
public static function boolean(callable $filter): void
1819
{
19-
try {
20+
if ($filter instanceof Closure) {
2021
$reflection = new ReflectionFunction($filter);
21-
} catch (TypeError) {
22+
} elseif (is_object($filter)) {
2223
$reflection = new ReflectionMethod($filter, '__invoke');
24+
} else {
25+
Assert::string($filter);
26+
27+
if (! str_contains($filter, '::')) {
28+
$reflection = new ReflectionFunction($filter);
29+
} else {
30+
[, $method] = explode('::', $filter);
31+
$reflection = new ReflectionMethod($filter, $method);
32+
}
2333
}
2434

2535
$returnType = $reflection->getReturnType();

0 commit comments

Comments
 (0)