Skip to content

Commit

Permalink
Revert "I don't think these needs to be benevolent."
Browse files Browse the repository at this point in the history
This reverts commit 0dab653.
  • Loading branch information
johnbillion committed Oct 24, 2021
1 parent 0dab653 commit 2d63bdb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Type/Php/RoundFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpParser\Node\Expr\FuncCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\BenevolentUnionType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\FloatType;
Expand All @@ -13,7 +14,6 @@
use PHPStan\Type\NeverType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;

class RoundFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
{
Expand All @@ -37,15 +37,15 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
// PHP 8 fatals with a missing parameter.
$noArgsReturnType = new NeverType(true);
// PHP 7 can return either a float or fatal.
$defaultReturnType = new UnionType([
$defaultReturnType = new BenevolentUnionType([
new FloatType(),
new NeverType(true),
]);
} else {
// PHP 7 returns null with a missing parameter.
$noArgsReturnType = new NullType();
// PHP 7 can return either a float or false.
$defaultReturnType = new UnionType([
$defaultReturnType = new BenevolentUnionType([
new FloatType(),
new ConstantBooleanType(false),
]);
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/data/round-php8.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
assertType('*NEVER*', round(array()));
assertType('*NEVER*', round(array(123)));
assertType('*NEVER*', round());
assertType('*NEVER*|float', round($_GET['foo']));
assertType('(*NEVER*|float)', round($_GET['foo']));

// Ceil
assertType('float', ceil(123));
Expand All @@ -32,7 +32,7 @@
assertType('*NEVER*', ceil(array()));
assertType('*NEVER*', ceil(array(123)));
assertType('*NEVER*', ceil());
assertType('*NEVER*|float', ceil($_GET['foo']));
assertType('(*NEVER*|float)', ceil($_GET['foo']));

// Floor
assertType('float', floor(123));
Expand All @@ -47,4 +47,4 @@
assertType('*NEVER*', floor(array()));
assertType('*NEVER*', floor(array(123)));
assertType('*NEVER*', floor());
assertType('*NEVER*|float', floor($_GET['foo']));
assertType('(*NEVER*|float)', floor($_GET['foo']));
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/data/round.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
assertType('false', round(array()));
assertType('false', round(array(123)));
assertType('null', round());
assertType('float|false', round($_GET['foo']));
assertType('(float|false)', round($_GET['foo']));

// Ceil
assertType('float', ceil(123));
Expand All @@ -32,7 +32,7 @@
assertType('false', ceil(array()));
assertType('false', ceil(array(123)));
assertType('null', ceil());
assertType('float|false', ceil($_GET['foo']));
assertType('(float|false)', ceil($_GET['foo']));

// Floor
assertType('float', floor(123));
Expand All @@ -47,4 +47,4 @@
assertType('false', floor(array()));
assertType('false', floor(array(123)));
assertType('null', floor());
assertType('float|false', floor($_GET['foo']));
assertType('(float|false)', floor($_GET['foo']));

0 comments on commit 2d63bdb

Please sign in to comment.