55use PhpParser \Node \Expr \FuncCall ;
66use PhpParser \Node \Expr \UnaryMinus ;
77use PHPStan \Analyser \Scope ;
8+ use PHPStan \Php \PhpVersion ;
89use PHPStan \Reflection \FunctionReflection ;
910use PHPStan \Type \Accessory \AccessoryNumericStringType ;
1011use PHPStan \Type \Constant \ConstantBooleanType ;
2223class BcMathStringOrNullReturnTypeExtension implements \PHPStan \Type \DynamicFunctionReturnTypeExtension
2324{
2425
26+ /** @var PhpVersion */
27+ private $ phpVersion ;
28+
29+ public function __construct (PhpVersion $ phpVersion )
30+ {
31+ $ this ->phpVersion = $ phpVersion ;
32+ }
33+
2534 public function isFunctionSupported (FunctionReflection $ functionReflection ): bool
2635 {
2736 return in_array ($ functionReflection ->getName (), ['bcdiv ' , 'bcmod ' , 'bcpowmod ' , 'bcsqrt ' ], true );
@@ -41,7 +50,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
4150
4251 $ defaultReturnType = new UnionType ([$ stringAndNumericStringType , new NullType ()]);
4352
44- if (isset ($ functionCall ->args [1 ]) === false ) {
53+ if (isset ($ functionCall ->args [1 ]) === false || $ this -> phpVersion -> getVersionId () >= 80000 ) {
4554 return $ stringAndNumericStringType ;
4655 }
4756
@@ -126,7 +135,7 @@ private function getTypeForBcSqrt(FuncCall $functionCall, Scope $scope): Type
126135 }
127136
128137 /**
129- * bcpowmod()
138+ * @see bcpowmod()
130139 * https://www.php.net/manual/en/function.bcpowmod.php
131140 * > Returns the result as a string, or FALSE if modulus is 0 or exponent is negative.
132141 * @param FuncCall $functionCall
0 commit comments