Skip to content

Commit fb02c76

Browse files
committed
Regression test
Closes phpstan/phpstan#6947
1 parent 471b818 commit fb02c76

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tests/PHPStan/Rules/Comparison/ElseIfConstantConditionRuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,20 @@ public function testBug11674(): void
140140
]);
141141
}
142142

143+
public function testBug6947(): void
144+
{
145+
if (PHP_VERSION_ID < 80000) {
146+
$this->markTestSkipped('Test requires PHP 8.0');
147+
}
148+
149+
$this->treatPhpDocTypesAsCertain = true;
150+
$this->analyse([__DIR__ . '/data/bug-6947.php'], [
151+
[
152+
'Elseif condition is always false.',
153+
11,
154+
'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%</>.',
155+
],
156+
]);
157+
}
158+
143159
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug6947;
4+
5+
abstract class HelloWorld
6+
{
7+
public function sayHello(): void
8+
{
9+
if (is_string($this->getValue())) {
10+
11+
} elseif (is_array($this->getValue())) {
12+
13+
}
14+
}
15+
16+
abstract public function getValue():int|float|string|null;
17+
}

0 commit comments

Comments
 (0)