2
2
3
3
namespace PHPStan \Type ;
4
4
5
- use PHPStan \Type \Accessory \AccessoryNumericStringType ;
6
5
use PHPStan \Type \Constant \ConstantFloatType ;
7
6
use PHPStan \Type \Constant \ConstantIntegerType ;
8
7
use function is_float ;
@@ -26,9 +25,22 @@ public static function exponentiate(Type $base, Type $exponent): Type
26
25
return new NeverType ();
27
26
}
28
27
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
+ }
32
44
}
33
45
34
46
// exponentiation of a float, stays a float
@@ -66,29 +78,8 @@ public static function exponentiate(Type $base, Type $exponent): Type
66
78
]);
67
79
}
68
80
69
- private static function exponentiateConstantScalar (Type $ base , Type $ exponent ): ?Type
81
+ private static function exponentiateConstantScalar (ConstantScalarType $ base , Type $ exponent ): ?Type
70
82
{
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
-
92
83
if ($ exponent instanceof IntegerRangeType) {
93
84
$ min = null ;
94
85
$ max = null ;
0 commit comments