Skip to content

Commit 03d1f30

Browse files
committed
Regression test
1 parent fb483a7 commit 03d1f30

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

tests/.claude/settings.local.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"WebFetch(domain:phpbench.readthedocs.io)"
5+
]
6+
}
7+
}

tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,16 @@ public function testBug7699(): void
201201
$this->analyse([__DIR__ . '/data/bug-7699.php'], []);
202202
}
203203

204+
public function testBug4284(): void
205+
{
206+
$this->treatPhpDocTypesAsCertain = true;
207+
$this->analyse([__DIR__ . '/data/bug-4284.php'], [
208+
[
209+
'If condition is always true.',
210+
25,
211+
'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.',
212+
],
213+
]);
214+
}
215+
204216
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug4284;
4+
5+
class HelloWorld
6+
{
7+
/** @param mixed[] $browser */
8+
public function sayHello(array $browser): void
9+
{
10+
$browserName = '';
11+
$upgradeBrowserLink = '';
12+
13+
if ($browser['name'] === 1) {
14+
$browserName = '123';
15+
$upgradeBrowserLink = '456';
16+
} elseif ($browser['name'] === 2) {
17+
$browserName = '789';
18+
$upgradeBrowserLink = '123';
19+
}
20+
21+
if ($browserName && $upgradeBrowserLink) {
22+
//
23+
}
24+
if ($browserName) {
25+
if ($upgradeBrowserLink) {
26+
//
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)