Skip to content

Commit f5dc4e7

Browse files
committed
Added regression test
1 parent d4f2276 commit f5dc4e7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,4 +1024,11 @@ public function testBug13538(): void
10241024
]);
10251025
}
10261026

1027+
public function testBug12805(): void
1028+
{
1029+
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
1030+
1031+
$this->analyse([__DIR__ . '/data/bug-12805.php'], []);
1032+
}
1033+
10271034
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12805;
4+
5+
/**
6+
* @param array<string, array{ rtx?: int }> $operations
7+
* @return array<string, array{ rtx: int }>
8+
*/
9+
function bug(array $operations): array {
10+
$base = [];
11+
12+
foreach ($operations as $operationName => $operation) {
13+
if (!isset($base[$operationName])) {
14+
$base[$operationName] = [];
15+
}
16+
if (!isset($base[$operationName]['rtx'])) {
17+
$base[$operationName]['rtx'] = 0;
18+
}
19+
$base[$operationName]['rtx'] += $operation['rtx'] ?? 0;
20+
}
21+
22+
return $base;
23+
}

0 commit comments

Comments
 (0)