Skip to content

Commit 358ef15

Browse files
committed
Fix
1 parent 94f1a87 commit 358ef15

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/Assert/Filter.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
use ReflectionFunction;
1010
use ReflectionMethod;
1111
use ReflectionNamedType;
12-
use Webmozart\Assert\Assert;
1312

14-
use function explode;
1513
use function is_object;
1614
use function sprintf;
17-
use function str_contains;
1815

1916
final class Filter
2017
{
@@ -25,14 +22,7 @@ public static function boolean(callable $filter): void
2522
} elseif (is_object($filter)) {
2623
$reflection = new ReflectionMethod($filter, '__invoke');
2724
} else {
28-
Assert::string($filter);
29-
30-
if (! str_contains($filter, '::')) {
31-
$reflection = new ReflectionFunction($filter);
32-
} else {
33-
[, $method] = explode('::', $filter);
34-
$reflection = new ReflectionMethod($filter, $method);
35-
}
25+
throw new InvalidArgumentException('Expected Closure or invokable object, string given');
3626
}
3727

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

src/Collector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public function getResults(): array
6868
// ensure transform property is set early ->withTransform() method
6969
Assert::isCallable($this->transform);
7070

71-
$count = 0;
72-
$collectedData = [];
71+
$count = 0;
72+
$collectedData = [];
7373

7474
if (is_callable($this->when)) {
7575
// filter must be a callable with bool return type

tests/FilterTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ public function __invoke(int $datum): bool
2323
$this->assertTrue(AtLeast::once($data, $filter));
2424
}
2525

26+
public function testOnceWithStringFilter(): void
27+
{
28+
$this->expectException(InvalidArgumentException::class);
29+
$this->expectExceptionMessage('Expected Closure or invokable object, string given');
30+
31+
$data = [1, 'f'];
32+
$filter = 'is_string';
33+
34+
AtLeast::once($data, $filter);
35+
}
36+
2637
public function testWithoutReturnTypeCallable(): void
2738
{
2839
$this->expectException(InvalidArgumentException::class);
@@ -39,7 +50,7 @@ public function __invoke(int $datum)
3950
};
4051
// phpcs:enable
4152

42-
$this->assertTrue(AtLeast::once($data, $filter));
53+
AtLeast::once($data, $filter);
4354
}
4455

4556
public function testWithNonBoolReturnTypeCallable(): void
@@ -55,6 +66,6 @@ public function __invoke(int $datum): string
5566
}
5667
};
5768

58-
$this->assertTrue(AtLeast::once($data, $filter));
69+
AtLeast::once($data, $filter);
5970
}
6071
}

0 commit comments

Comments
 (0)