1010use PHPStan \Type \Constant \ConstantStringType ;
1111use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
1212use PHPStan \Type \IntegerRangeType ;
13+ use PHPStan \Type \IntegerType ;
1314use PHPStan \Type \MixedType ;
1415use PHPStan \Type \Type ;
1516use PHPStan \Type \TypeUtils ;
@@ -31,7 +32,7 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
3132public function getTypeFromFunctionCall (FunctionReflection $ functionReflection , FuncCall $ functionCall , Scope $ scope ): Type
3233{
3334$ defaultReturnType = ParametersAcceptorSelector::selectSingle ($ functionReflection ->getVariants ())->getReturnType ();
34- if (count ($ functionCall ->getArgs ()) !== 1 ) { // strtotime() & 2nd param baseTimestamp are both unsupported use cases
35+ if (count ($ functionCall ->getArgs ()) === 0 ) {
3536return $ defaultReturnType ;
3637}
3738$ argType = $ scope ->getType ($ functionCall ->getArgs ()[0 ]->value );
@@ -49,9 +50,17 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
4950return new ConstantBooleanType (false );
5051}
5152
52- $ results = array_map ('intval ' , $ results );
53+ // 2nd param $baseTimestamp is too non-deterministic so simply return int
54+ if (count ($ functionCall ->getArgs ()) > 1 ) {
55+ return new IntegerType ();
56+ }
57+
58+ // if it is positive we can narrow down to positive-int as long as time flows forward
59+ if (min (array_map ('intval ' , $ results )) > 0 ) {
60+ return IntegerRangeType::createAllGreaterThan (0 );
61+ }
5362
54- return IntegerRangeType:: createAllGreaterThan ( min ( $ results ) );
63+ return new IntegerType ( );
5564}
5665
5766}
0 commit comments