Skip to content

Commit 3c9f020

Browse files
Add non regression test
1 parent 6b2473a commit 3c9f020

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,11 @@ public function testBug12605(): void
907907
]);
908908
}
909909

910+
public function testBug4809(): void
911+
{
912+
$this->analyse([__DIR__ . '/data/bug-4809.php'], []);
913+
}
914+
910915
public function testBug11602(): void
911916
{
912917
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
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 Bug4809;
4+
5+
class SomeClass
6+
{
7+
/**
8+
* @param array{
9+
* some?: string,
10+
* another?: string,
11+
* } $data
12+
* @param string $key
13+
* @return void
14+
*/
15+
public function someFunction(array $data, string $key): void
16+
{
17+
if($key !== 'some' && $key !== 'another') {
18+
return;
19+
}
20+
21+
if(!array_key_exists($key, $data)) {
22+
return;
23+
}
24+
25+
var_dump($data[$key]);
26+
}
27+
}

0 commit comments

Comments
 (0)