Skip to content

Commit bc8af0d

Browse files
committed
Update ExponentiateHelper.php
1 parent dc0180e commit bc8af0d

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Type/ExponentiateHelper.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\Type\Constant\ConstantFloatType;
66
use PHPStan\Type\Constant\ConstantIntegerType;
7+
use Throwable;
78
use function is_float;
89
use function is_int;
910
use function pow;
@@ -85,9 +86,15 @@ private static function exponentiateConstantScalar(ConstantScalarType $base, Typ
8586
$max = null;
8687
if ($exponent->getMin() !== null) {
8788
$min = self::pow($base->getValue(), $exponent->getMin());
89+
if ($min === null) {
90+
return null;
91+
}
8892
}
8993
if ($exponent->getMax() !== null) {
9094
$max = self::pow($base->getValue(), $exponent->getMax());
95+
if ($max === null) {
96+
return null;
97+
}
9198
}
9299

93100
if (!is_float($min) && !is_float($max)) {
@@ -97,6 +104,11 @@ private static function exponentiateConstantScalar(ConstantScalarType $base, Typ
97104

98105
if ($exponent instanceof ConstantScalarType) {
99106
$result = self::pow($base->getValue(), $exponent->getValue());
107+
108+
if ($result === null) {
109+
return null;
110+
}
111+
100112
if (is_int($result)) {
101113
return new ConstantIntegerType($result);
102114
}
@@ -106,12 +118,13 @@ private static function exponentiateConstantScalar(ConstantScalarType $base, Typ
106118
return null;
107119
}
108120

109-
/**
110-
* @return float|int
111-
*/
112-
private static function pow(mixed $base, mixed $exp)
121+
private static function pow(mixed $base, mixed $exp): float|int|null
113122
{
114-
return pow($base, $exp);
123+
try {
124+
return pow($base, $exp);
125+
} catch (Throwable) {
126+
return null;
127+
}
115128
}
116129

117130
}

0 commit comments

Comments
 (0)