Skip to content

Commit 628af63

Browse files
committed
Added regression test
1 parent d73fc15 commit 628af63

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
@@ -1017,4 +1017,11 @@ public function testBug13538(): void
10171017
]);
10181018
}
10191019

1020+
public function testBug12805(): void
1021+
{
1022+
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
1023+
1024+
$this->analyse([__DIR__ . '/data/bug-12805.php'], []);
1025+
}
1026+
10201027
}
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)