Skip to content

Commit 3b8c06e

Browse files
committed
Added regression test
1 parent 8476760 commit 3b8c06e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,13 @@ public function testPR4385Bis(): void
11061106
$this->analyse([__DIR__ . '/data/pr-4385-bis.php'], []);
11071107
}
11081108

1109+
public function testBug11276(): void
1110+
{
1111+
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
1112+
1113+
$this->analyse([__DIR__ . '/data/bug-11276.php'], []);
1114+
}
1115+
11091116
public function testBug12805(): void
11101117
{
11111118
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Bug11276;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param array{from: string, to: string} $expected
9+
*/
10+
public function testLanguagesMatchingRegex(string $url, ?array $expected): void
11+
{
12+
preg_match('#\/(?<from>[a-z]{2})-(?<to>[a-z]{1}[a-z0-9]{1})\/#', $url, $matches);
13+
14+
foreach ($expected as $key => $value) {
15+
if ($matches instanceof ArrayAccess || \array_key_exists($key, $matches)) {
16+
$matches[$key];
17+
}
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)