Skip to content

Commit 5374f42

Browse files
committed
Added regression test
1 parent 5f3c308 commit 5374f42

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/PHPStan/Rules/Variables/IssetRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,16 @@ public function testIssetAfterRememberedConstructor(): void
492492
]);
493493
}
494494

495+
public function testPr4374(): void
496+
{
497+
$this->treatPhpDocTypesAsCertain = true;
498+
499+
$this->analyse([__DIR__ . '/data/pr-4374.php'], [
500+
[
501+
'Offset string on array<PR4374\Foo> in isset() always exists and is not nullable.',
502+
23,
503+
],
504+
]);
505+
}
506+
495507
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace PR4374;
4+
5+
class Foo {}
6+
7+
final class AnnotationsMethodsClassReflectionExtension
8+
{
9+
10+
/** @var Foo[][] */
11+
private array $methods = [];
12+
13+
public function hasMethod(string $cacheKey, string $methodName): bool
14+
{
15+
if (!isset($this->methods[$cacheKey][$methodName])) {
16+
$method = $this->findClassReflectionWithMethod();
17+
if ($method === null) {
18+
return false;
19+
}
20+
$this->methods[$cacheKey][$methodName] = $method;
21+
}
22+
23+
return isset($this->methods[$cacheKey][$methodName]);
24+
}
25+
26+
private function findClassReflectionWithMethod(
27+
): ?Foo
28+
{
29+
if (rand(0,1)) {
30+
return new Foo();
31+
}
32+
return null;
33+
}
34+
}

0 commit comments

Comments
 (0)