Skip to content

Commit 84e6766

Browse files
phpstan-botclaude
andcommitted
Add IfConstantConditionRule test for phpstan/phpstan#8270
The original bug report was about a false positive "If condition is always true." error, so this adds a non-regression test in IfConstantConditionRuleTest. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a4295bc commit 84e6766

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,10 @@ public function testBug4284(): void
213213
]);
214214
}
215215

216+
public function testBug8270(): void
217+
{
218+
$this->treatPhpDocTypesAsCertain = true;
219+
$this->analyse([__DIR__ . '/data/bug-8270.php'], []);
220+
}
221+
216222
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug8270Rule;
6+
7+
function () {
8+
$list = [];
9+
10+
for ($i = 0; $i < 10; $i++) {
11+
$list[] = [
12+
'test' => false,
13+
'value' => rand(),
14+
];
15+
}
16+
17+
if ($list === []) {
18+
return;
19+
}
20+
21+
$k = array_key_first($list);
22+
$list[$k]['test'] = true;
23+
24+
foreach ($list as $item) {
25+
if ($item['test']) {
26+
echo $item['value'];
27+
}
28+
}
29+
};

0 commit comments

Comments
 (0)