Skip to content

Commit f829abe

Browse files
committed
fix union types
1 parent 8e5c640 commit f829abe

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,6 @@ private function getConditionalSpecifiedTypes(
15891589
$argumentExpr instanceof Node\Scalar
15901590
|| ($argumentExpr instanceof ConstFetch && in_array(strtolower($argumentExpr->name->toString()), ['true', 'false', 'null'], true))
15911591
)
1592-
&& $targetType->isConstantScalarValue()->yes()
15931592
) {
15941593
return null;
15951594
}

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ public function testImpossibleCheckTypeFunctionCall(): void
7474
'Call to function is_callable() with \'nonexistentFunction\' will always evaluate to false.',
7575
87,
7676
],
77-
[
78-
'Call to function is_numeric() with \'123\' will always evaluate to true.',
79-
102,
80-
],
81-
[
82-
'Call to function is_numeric() with \'blabla\' will always evaluate to false.',
83-
105,
84-
],
8577
[
8678
'Call to function is_numeric() with 123|float will always evaluate to true.',
8779
118,
@@ -231,15 +223,6 @@ public function testImpossibleCheckTypeFunctionCall(): void
231223
718,
232224
'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%</>.',
233225
],
234-
[
235-
'Call to function is_numeric() with \'123\' will always evaluate to true.',
236-
718,
237-
],
238-
[
239-
'Call to function assert() with false will always evaluate to false.',
240-
719,
241-
'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%</>.',
242-
],
243226
[
244227
'Call to function is_numeric() with \'blabla\' will always evaluate to false.',
245228
719,

tests/PHPStan/Rules/Comparison/data/bug-13566.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,27 @@ function test(): void
165165
{
166166
// send 404 header
167167
notFound(false);
168+
}
169+
170+
171+
class ReturnViaUnion
172+
{
173+
/**
174+
* @return ($exit is int ? void : never)
175+
*/
176+
public static function notFound(int|string $exit = 'hello world'): void
177+
{
178+
header('HTTP/1.1 404 Not Found', true, 404);
179+
180+
if (!is_int($exit)) {
181+
echo '404 Not Found';
182+
exit;
183+
}
184+
}
168185

186+
public function test(): void
187+
{
188+
// send 404 header
189+
self::notFound(0);
190+
}
169191
}

0 commit comments

Comments
 (0)