Skip to content

Commit 50cbd45

Browse files
committed
add NSRT test
1 parent 3372181 commit 50cbd45

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace OptionalArrayKeyInMultiDimArrayLoop;
4+
5+
/**
6+
* @param array<int, array{1: int, 2: int, 3: float}> $rows
7+
*/
8+
function foo(array $rows): mixed
9+
{
10+
$itemMap = [];
11+
12+
foreach ($rows as $row) {
13+
$x = $row[1];
14+
$month = $row[2];
15+
16+
$itemMap[$x][$month]['foo'] ??= 5;
17+
$itemMap[$x][$month]['bar'] ??= 5;
18+
19+
\PHPStan\Testing\assertType('array{foo: 5, bar: 5, amount?: 0.0}', $itemMap[$x][$month]);
20+
$itemMap[$x][$month]['amount'] ??= 0.0;
21+
}
22+
23+
return $itemMap;
24+
}

0 commit comments

Comments
 (0)