Skip to content

Commit 7a94378

Browse files
phpstan-botclaude
andcommitted
Add regression test for phpstan/phpstan#12373
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 15b7ed0 commit 7a94378

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,17 @@ public function testBug14274(): void
14141414
$this->analyse([__DIR__ . '/data/bug-14274.php'], []);
14151415
}
14161416

1417+
#[RequiresPhp('>= 8.0')]
1418+
public function testBug12373(): void
1419+
{
1420+
$this->cliArgumentsVariablesRegistered = true;
1421+
$this->polluteScopeWithLoopInitialAssignments = false;
1422+
$this->checkMaybeUndefinedVariables = true;
1423+
$this->polluteScopeWithAlwaysIterableForeach = true;
1424+
1425+
$this->analyse([__DIR__ . '/data/bug-12373.php'], []);
1426+
}
1427+
14171428
public function testBug14117(): void
14181429
{
14191430
$this->cliArgumentsVariablesRegistered = true;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php // lint >= 8.0
2+
3+
namespace Bug12373;
4+
5+
function test(): void
6+
{
7+
$foo = [];
8+
9+
[$always_a, $always_b, $always_c] = [rand(0, 1), rand(0, 1), rand(0, 1)];
10+
if (rand(0, 1)) {
11+
[$maybe_a, $maybe_b, $maybe_c] = [rand(0, 1), rand(0, 1), rand(0, 1)];
12+
$flag = true;
13+
} else {
14+
$flag = false;
15+
}
16+
17+
if ($flag && $always_a !== $maybe_a) {
18+
$foo[] = 'first';
19+
}
20+
21+
if (($always_a && !$always_b) || ($flag && $maybe_a && !$maybe_b)) {
22+
$foo[] = 'second';
23+
}
24+
25+
if (($always_a && !$always_c) || ($flag && $maybe_a && !$maybe_c)) {
26+
$foo[] = 'third';
27+
}
28+
}

0 commit comments

Comments
 (0)