Skip to content

Commit dc0180e

Browse files
committed
revert
1 parent 4d807f2 commit dc0180e

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

src/Type/ExponentiateHelper.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Type;
44

5-
use PHPStan\Type\Accessory\AccessoryNumericStringType;
65
use PHPStan\Type\Constant\ConstantFloatType;
76
use PHPStan\Type\Constant\ConstantIntegerType;
87
use function is_float;
@@ -26,9 +25,22 @@ public static function exponentiate(Type $base, Type $exponent): Type
2625
return new NeverType();
2726
}
2827

29-
$result = self::exponentiateConstantScalar($base, $exponent);
30-
if ($result !== null) {
31-
return $result;
28+
$allowedExponentTypes = new UnionType([
29+
new IntegerType(),
30+
new FloatType(),
31+
new StringType(),
32+
new BooleanType(),
33+
new NullType(),
34+
]);
35+
if (!$allowedExponentTypes->isSuperTypeOf($exponent)->yes()) {
36+
return new ErrorType();
37+
}
38+
39+
if ($base instanceof ConstantScalarType) {
40+
$result = self::exponentiateConstantScalar($base, $exponent);
41+
if ($result !== null) {
42+
return $result;
43+
}
3244
}
3345

3446
// exponentiation of a float, stays a float
@@ -66,29 +78,8 @@ public static function exponentiate(Type $base, Type $exponent): Type
6678
]);
6779
}
6880

69-
private static function exponentiateConstantScalar(Type $base, Type $exponent): ?Type
81+
private static function exponentiateConstantScalar(ConstantScalarType $base, Type $exponent): ?Type
7082
{
71-
$allowedOperandTypes = new UnionType([
72-
new IntegerType(),
73-
new FloatType(),
74-
new IntersectionType([
75-
new StringType(),
76-
new AccessoryNumericStringType(),
77-
]),
78-
new BooleanType(),
79-
new NullType(),
80-
]);
81-
if (!$allowedOperandTypes->isSuperTypeOf($exponent)->yes()) {
82-
return new ErrorType();
83-
}
84-
if (!$allowedOperandTypes->isSuperTypeOf($base)->yes()) {
85-
return new ErrorType();
86-
}
87-
88-
if (!$base instanceof ConstantScalarType) {
89-
return null;
90-
}
91-
9283
if ($exponent instanceof IntegerRangeType) {
9384
$min = null;
9485
$max = null;

0 commit comments

Comments
 (0)