Skip to content

Commit 8406cc6

Browse files
committed
fix union types
1 parent 8e5c640 commit 8406cc6

3 files changed

Lines changed: 33 additions & 18 deletions

File tree

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: 6 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,19 +223,11 @@ 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-
],
238226
[
239227
'Call to function assert() with false will always evaluate to false.',
240228
719,
241229
'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%</>.',
242230
],
243-
[
244-
'Call to function is_numeric() with \'blabla\' will always evaluate to false.',
245-
719,
246-
],
247231
[
248232
'Call to function assert() with true will always evaluate to true.',
249233
726,
@@ -1182,7 +1166,12 @@ public function testBug14177(): void
11821166
public function testBug13566(): void
11831167
{
11841168
$this->treatPhpDocTypesAsCertain = true;
1185-
$this->analyse([__DIR__ . '/data/bug-13566.php'], []);
1169+
$this->analyse([__DIR__ . '/data/bug-13566.php'], [
1170+
[
1171+
'Call to function is_numeric() with 123 will always evaluate to true.',
1172+
195
1173+
]
1174+
]);
11861175
}
11871176

11881177
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,32 @@ 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+
}
185+
186+
public function test(): void
187+
{
188+
// send 404 header
189+
self::notFound(0);
190+
}
191+
}
192+
168193

194+
$x = 123;
195+
if (is_numeric($x)) {
169196
}

0 commit comments

Comments
 (0)