File tree Expand file tree Collapse file tree
tests/PHPStan/Rules/Functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -534,6 +534,14 @@ public function testBug8031(): void
534534 $ this ->analyse ([__DIR__ . '/data/bug-8031.php ' ], []);
535535 }
536536
537+ #[RequiresPhp('>= 8.0.0 ' )]
538+ public function testBug11507 (): void
539+ {
540+ $ this ->checkNullables = true ;
541+ $ this ->checkExplicitMixed = true ;
542+ $ this ->analyse ([__DIR__ . '/data/bug-11507.php ' ], []);
543+ }
544+
537545 public function testBug15245 (): void
538546 {
539547 $ this ->checkNullables = true ;
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ use function PHPStan \dumpType ;
4+
5+ /**
6+ * @template TValue
7+ */
8+ class Collection
9+ {
10+ /**
11+ * @param array<int, TValue> $items
12+ */
13+ public function __construct (
14+ public array $ items ,
15+ ) {}
16+
17+ /**
18+ * Run a map over each of the items.
19+ *
20+ * @template TMapValue
21+ *
22+ * @param callable(TValue, int=): TMapValue $callback
23+ * @return Collection<TMapValue>
24+ */
25+ public function map (callable $ callback )
26+ {
27+ $ keys = array_keys ($ this ->items );
28+
29+ $ items = array_map ($ callback , $ this ->items );
30+
31+ $ result = array_combine ($ keys , $ items );
32+
33+ return new self ($ result );
34+ }
35+ }
36+
37+ /**
38+ * @param Collection<non-empty-array<string>> $collection
39+ * @return Collection<non-empty-array<string>>
40+ */
41+ function foo (Collection $ collection )
42+ {
43+ return $ collection ->map (function (array $ item ) {
44+ $ item ['foo ' ] = '100 ' ;
45+
46+ return $ item ;
47+ });
48+ }
You can’t perform that action at this time.
0 commit comments