65
65
use PHPStan \Type \TypeUtils ;
66
66
use PHPStan \Type \TypeWithClassName ;
67
67
use PHPStan \Type \UnionType ;
68
- use PHPStan \Type \VerbosityLevel ;
69
-
70
68
use function array_keys ;
71
69
use function array_merge ;
72
70
use function assert ;
@@ -1451,11 +1449,8 @@ private function resolveCommonMath(Expr\BinaryOp $expr, Type $leftType, Type $ri
1451
1449
$ leftNumberType = $ leftType ->toNumber ();
1452
1450
$ rightNumberType = $ rightType ->toNumber ();
1453
1451
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) {
1459
1454
return $ this ->integerRangeMath (
1460
1455
$ leftNumberType ,
1461
1456
$ expr ,
@@ -1480,8 +1475,6 @@ private function resolveCommonMath(Expr\BinaryOp $expr, Type $leftType, Type $ri
1480
1475
1481
1476
return $ union ->toNumber ();
1482
1477
}
1483
-
1484
- return $ this ->integerRangeMath ($ leftNumberType , $ expr , $ rightNumberType );
1485
1478
}
1486
1479
1487
1480
$ specifiedTypes = $ this ->callOperatorTypeSpecifyingExtensions ($ expr , $ leftType , $ rightType );
@@ -1567,16 +1560,14 @@ private function integerRangeMath(Type $range, BinaryOp $node, Type $operand): T
1567
1560
}
1568
1561
1569
1562
$ operand = $ operand ->toNumber ();
1570
- if (!$ operand instanceof IntegerRangeType && !$ operand instanceof ConstantIntegerType) {
1571
- return $ operand ;
1572
- }
1573
-
1574
1563
if ($ operand instanceof IntegerRangeType) {
1575
1564
$ operandMin = $ operand ->getMin ();
1576
1565
$ operandMax = $ operand ->getMax ();
1577
- } else {
1566
+ } elseif ( $ operand instanceof ConstantIntegerType) {
1578
1567
$ operandMin = $ operand ->getValue ();
1579
1568
$ operandMax = $ operand ->getValue ();
1569
+ } else {
1570
+ return $ operand ;
1580
1571
}
1581
1572
1582
1573
if ($ node instanceof BinaryOp \Plus) {
0 commit comments