22
33namespace PHPStan \Type \Php ;
44
5- use PhpParser \Node \ Expr \ ConstFetch ;
5+ use PhpParser \Node ;
66use PhpParser \Node \Expr \FuncCall ;
77use PHPStan \Analyser \Scope ;
88use PHPStan \Reflection \FunctionReflection ;
9+ use PHPStan \Reflection \ReflectionProvider ;
910use PHPStan \Type \ArrayType ;
1011use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
1112use PHPStan \Type \MixedType ;
1213use PHPStan \Type \StringType ;
1314use PHPStan \Type \Type ;
15+ use PHPStan \Type \TypeCombinator ;
1416use function count ;
15- use function in_array ;
1617
1718class FilterInputDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension
1819{
1920
20- public function __construct (private FilterFunctionReturnTypeHelper $ filterFunctionReturnTypeHelper )
21+ public function __construct (private FilterFunctionReturnTypeHelper $ filterFunctionReturnTypeHelper, private ReflectionProvider $ reflectionProvider )
2122 {
2223 }
2324
@@ -32,11 +33,15 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
3233 return null ;
3334 }
3435
35- $ typeExpr = $ functionCall ->getArgs ()[0 ]->value ;
36- if (
37- !($ typeExpr instanceof ConstFetch)
38- || !in_array ((string ) $ typeExpr ->name , ['INPUT_GET ' , 'INPUT_POST ' , 'INPUT_COOKIE ' , 'INPUT_SERVER ' , 'INPUT_ENV ' ], true )
39- ) {
36+ $ supportedTypes = TypeCombinator::union (
37+ $ this ->reflectionProvider ->getConstant (new Node \Name ('INPUT_GET ' ), null )->getValueType (),
38+ $ this ->reflectionProvider ->getConstant (new Node \Name ('INPUT_POST ' ), null )->getValueType (),
39+ $ this ->reflectionProvider ->getConstant (new Node \Name ('INPUT_COOKIE ' ), null )->getValueType (),
40+ $ this ->reflectionProvider ->getConstant (new Node \Name ('INPUT_SERVER ' ), null )->getValueType (),
41+ $ this ->reflectionProvider ->getConstant (new Node \Name ('INPUT_ENV ' ), null )->getValueType (),
42+ );
43+ $ typeType = $ scope ->getType ($ functionCall ->getArgs ()[0 ]->value );
44+ if (!$ typeType ->isInteger ()->yes () || $ supportedTypes ->isSuperTypeOf ($ typeType )->no ()) {
4045 return null ;
4146 }
4247
0 commit comments