File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
tests/PHPStan/Rules/Methods Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -507,4 +507,9 @@ public function testBug4603(): void
507507 $ this ->analyse ([__DIR__ . '/data/bug-4603.php ' ], []);
508508 }
509509
510+ public function testBug3151 (): void
511+ {
512+ $ this ->analyse ([__DIR__ . '/data/bug-3151.php ' ], []);
513+ }
514+
510515}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug3151 ;
4+
5+ class Foo
6+ {
7+
8+ /**
9+ * @template T
10+ * @param T[] $haystack
11+ * @param callable(T): bool $matcher
12+ * @return T|null;
13+ */
14+ function search (array $ haystack , callable $ matcher )
15+ {
16+ foreach ($ haystack as $ item ) {
17+ if (!$ matcher ($ item )) {
18+ continue ;
19+ }
20+ return $ item ;
21+ }
22+ return null ;
23+ }
24+
25+ /**
26+ * @param array<array{type: string, foo: string}> $myArray
27+ * @return array{type: string, foo: string}
28+ */
29+ function findByType (array $ myArray , string $ type ): array {
30+ $ found = $ this ->search ($ myArray , function (array $ item ) use ($ type ): bool {
31+ return $ item ['type ' ] === $ type ;
32+ });
33+ if ($ found === null ) {
34+ throw new \LogicException ();
35+ }
36+ return $ found ;
37+ }
38+
39+ }
You can’t perform that action at this time.
0 commit comments