7
7
use PhpParser \Node \Expr \FuncCall ;
8
8
use PHPStan \Analyser \Scope ;
9
9
use PHPStan \Reflection \FunctionReflection ;
10
+ use PHPStan \Type \Constant \ConstantIntegerType ;
10
11
use PHPStan \Type \DynamicFunctionThrowTypeExtension ;
11
- use PHPStan \Type \NeverType ;
12
12
use PHPStan \Type \ObjectType ;
13
13
use PHPStan \Type \Type ;
14
- use PHPStan \Type \TypeCombinator ;
15
14
use function count ;
16
15
use const PHP_INT_MIN ;
17
16
@@ -29,39 +28,19 @@ public function getThrowTypeFromFunctionCall(FunctionReflection $functionReflect
29
28
return $ functionReflection ->getThrowType ();
30
29
}
31
30
32
- $ containsMin = false ;
33
- $ valueType = $ scope ->getType ($ funcCall ->getArgs ()[0 ]->value );
34
- foreach ($ valueType ->getConstantScalarTypes () as $ constantScalarType ) {
35
- if ($ constantScalarType ->getValue () === PHP_INT_MIN ) {
36
- $ containsMin = true ;
37
- }
38
-
39
- $ valueType = TypeCombinator::remove ($ valueType , $ constantScalarType );
40
- }
41
-
42
- if (!$ valueType instanceof NeverType) {
43
- $ containsMin = true ;
44
- }
31
+ $ valueType = $ scope ->getType ($ funcCall ->getArgs ()[0 ]->value )->toInteger ();
32
+ $ containsMin = $ valueType ->isSuperTypeOf (new ConstantIntegerType (PHP_INT_MIN ));
45
33
46
- $ divisionByZero = false ;
47
- $ divisorType = $ scope -> getType ( $ funcCall -> getArgs ()[ 1 ]-> value );
48
- foreach ( $ divisorType ->getConstantScalarTypes () as $ constantScalarType ) {
49
- if ($ containsMin && $ constantScalarType -> getValue () === - 1 ) {
34
+ $ divisorType = $ scope -> getType ( $ funcCall -> getArgs ()[ 1 ]-> value )-> toInteger () ;
35
+ if (! $ containsMin -> no ()) {
36
+ $ divisionByMinusOne = $ divisorType ->isSuperTypeOf ( new ConstantIntegerType (- 1 ));
37
+ if (! $ divisionByMinusOne -> no () ) {
50
38
return new ObjectType (ArithmeticError::class);
51
39
}
52
-
53
- if ($ constantScalarType ->getValue () === 0 ) {
54
- $ divisionByZero = true ;
55
- }
56
-
57
- $ divisorType = TypeCombinator::remove ($ divisorType , $ constantScalarType );
58
- }
59
-
60
- if (!$ divisorType instanceof NeverType) {
61
- return new ObjectType ($ containsMin ? ArithmeticError::class : DivisionByZeroError::class);
62
40
}
63
41
64
- if ($ divisionByZero ) {
42
+ $ divisionByZero = $ divisorType ->isSuperTypeOf (new ConstantIntegerType (0 ));
43
+ if (!$ divisionByZero ->no ()) {
65
44
return new ObjectType (DivisionByZeroError::class);
66
45
}
67
46
0 commit comments