Skip to content

Commit a4894b8

Browse files
Simplify
1 parent 3d140c0 commit a4894b8

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@
6565
use PHPStan\Type\TypeUtils;
6666
use PHPStan\Type\TypeWithClassName;
6767
use PHPStan\Type\UnionType;
68-
use PHPStan\Type\VerbosityLevel;
69-
7068
use function array_keys;
7169
use function array_merge;
7270
use function assert;
@@ -1451,11 +1449,8 @@ private function resolveCommonMath(Expr\BinaryOp $expr, Type $leftType, Type $ri
14511449
$leftNumberType = $leftType->toNumber();
14521450
$rightNumberType = $rightType->toNumber();
14531451

1454-
if (($leftNumberType instanceof IntegerRangeType || $leftNumberType instanceof ConstantIntegerType || $leftType instanceof UnionType) &&
1455-
($rightNumberType instanceof IntegerRangeType || $rightNumberType instanceof ConstantIntegerType || $rightType instanceof UnionType)
1456-
) {
1457-
1458-
if ($leftNumberType instanceof ConstantIntegerType) {
1452+
if ($rightNumberType instanceof IntegerRangeType || $rightNumberType instanceof ConstantIntegerType || $rightType instanceof UnionType) {
1453+
if ($leftNumberType instanceof IntegerRangeType || $leftNumberType instanceof ConstantIntegerType) {
14591454
return $this->integerRangeMath(
14601455
$leftNumberType,
14611456
$expr,
@@ -1480,8 +1475,6 @@ private function resolveCommonMath(Expr\BinaryOp $expr, Type $leftType, Type $ri
14801475

14811476
return $union->toNumber();
14821477
}
1483-
1484-
return $this->integerRangeMath($leftNumberType, $expr, $rightNumberType);
14851478
}
14861479

14871480
$specifiedTypes = $this->callOperatorTypeSpecifyingExtensions($expr, $leftType, $rightType);
@@ -1567,16 +1560,14 @@ private function integerRangeMath(Type $range, BinaryOp $node, Type $operand): T
15671560
}
15681561

15691562
$operand = $operand->toNumber();
1570-
if (!$operand instanceof IntegerRangeType && !$operand instanceof ConstantIntegerType) {
1571-
return $operand;
1572-
}
1573-
15741563
if ($operand instanceof IntegerRangeType) {
15751564
$operandMin = $operand->getMin();
15761565
$operandMax = $operand->getMax();
1577-
} else {
1566+
} elseif ($operand instanceof ConstantIntegerType) {
15781567
$operandMin = $operand->getValue();
15791568
$operandMax = $operand->getValue();
1569+
} else {
1570+
return $operand;
15801571
}
15811572

15821573
if ($node instanceof BinaryOp\Plus) {

0 commit comments

Comments
 (0)