Skip to content

Commit

Permalink
Handle an integer and float union.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Feb 1, 2022
1 parent a4cff18 commit d2b50e3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Type/Php/RoundFunctionReturnTypeExtension.php
Expand Up @@ -14,6 +14,7 @@
use PHPStan\Type\NeverType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

class RoundFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
{
Expand Down Expand Up @@ -62,7 +63,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
}

if (PHP_VERSION_ID >= 80000) {
if (!($firstArgType instanceof IntegerType) && !($firstArgType instanceof FloatType)) {
$allowed = TypeCombinator::union(
new IntegerType(),
new FloatType(),
);
if (!$allowed->accepts($firstArgType, true)->yes()) {
// PHP 8 fatals if the parameter is not an integer or float.
return new NeverType(true);
}
Expand Down

0 comments on commit d2b50e3

Please sign in to comment.