Skip to content

Commit 3836343

Browse files
phpstan-botclaude
andcommitted
Add regression test for #7716
Closes phpstan/phpstan#7716 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 156b1ea commit 3836343

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug7716;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
/**
10+
* @param array{foo?: int, bar?: int} $array
11+
*/
12+
public function sayHello(array $array): int
13+
{
14+
$hasFoo = isset($array['foo']) && $array['foo'] > 1;
15+
$hasBar = isset($array['bar']) && $array['bar'] > 1;
16+
17+
if ($hasFoo) {
18+
assertType('int<2, max>', $array['foo']);
19+
return $array['foo'];
20+
}
21+
22+
if ($hasBar) {
23+
assertType('int<2, max>', $array['bar']);
24+
return $array['bar'];
25+
}
26+
27+
return 0;
28+
}
29+
30+
/**
31+
* @param array{foo?: int, bar?: int} $array
32+
*/
33+
public function sayHello2(array $array): int
34+
{
35+
$hasBar = isset($array['bar']) && $array['bar'] > 1;
36+
$hasFoo = isset($array['foo']) && $array['foo'] > 1;
37+
38+
if ($hasFoo) {
39+
assertType('int<2, max>', $array['foo']);
40+
return $array['foo'];
41+
}
42+
43+
if ($hasBar) {
44+
assertType('int<2, max>', $array['bar']);
45+
return $array['bar'];
46+
}
47+
48+
return 0;
49+
}
50+
}

0 commit comments

Comments
 (0)