Skip to content

Commit 58d9e00

Browse files
committed
Added regression test
1 parent 9eb45d9 commit 58d9e00

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,13 @@ public function testBug4532(): void
990990
]);
991991
}
992992

993+
public function testBug12115(): void
994+
{
995+
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
996+
997+
$this->analyse([__DIR__ . '/data/bug-12115.php'], []);
998+
}
999+
9931000
public function testBug10492(): void
9941001
{
9951002
$this->analyse([__DIR__ . '/data/bug-10492.php'], [
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug12115;
4+
5+
class HelloWorld
6+
{
7+
public function testMe(): void
8+
{
9+
$indexes = [1, 2, 3, 4, 5];
10+
$loopArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
11+
$counterArray = [];
12+
13+
14+
foreach ($indexes as $index) {
15+
// Check if the index is not set in the counter array
16+
if (!isset($counterArray[$index])) {
17+
$counterArray[$index] = ['string_index_1' => 0, 'string_index_2' => 0];
18+
}
19+
20+
foreach ($loopArray as $loop) {
21+
$stringIndex = $loop % 2 === 0 ? 'string_index_1' : 'string_index_2';
22+
$counterArray[$index][$stringIndex]++;
23+
}
24+
}
25+
26+
}
27+
}

0 commit comments

Comments
 (0)