Skip to content

Commit b4ecd33

Browse files
committed
Fix false positives on existing-offsets after assign
1 parent 12a0b4e commit b4ecd33

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,13 @@ public function testBug12406(): void
856856
$this->analyse([__DIR__ . '/data/bug-12406.php'], []);
857857
}
858858

859+
public function testBug12406b(): void
860+
{
861+
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
862+
863+
$this->analyse([__DIR__ . '/data/bug-12406b.php'], []);
864+
}
865+
859866
public function testBug11679(): void
860867
{
861868
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Bug12406_2;
4+
5+
final class Foo
6+
{
7+
8+
public function sayHello(string $s): void
9+
{
10+
$stats = [];
11+
preg_match_all('~
12+
commit[ ][a-z0-9]{40}\\n
13+
Author:\s+(.+)\s+<[^>]+>\\n
14+
AuthorDate:[^\\n]+\\n
15+
Commit:[^\\n]+\\n
16+
CommitDate:[^\\n]+\\n\\n
17+
(\s+(?:[^\n]+\n)+)\n
18+
[ ](\\d+)[ ]files?[ ]changed,(?:[ ](\\d+)[ ]insertions?\\(\\+\\),?)?(?:[ ](\\d+)[ ]deletions?\\(-\\))?
19+
~mx', $s, $matches, PREG_SET_ORDER);
20+
21+
for ($i = 0; $i < count($matches); $i++) {
22+
$author = $matches[$i][1];
23+
$files = (int) $matches[$i][3];
24+
25+
$stats[$author]['commits']
26+
= ($stats[$author]['commits'] ?? 0) + 1;
27+
$stats[$author]['files']
28+
= ($stats[$author]['files'] ?? 0) + $files;
29+
}
30+
}
31+
32+
}

0 commit comments

Comments
 (0)