2
2
3
3
namespace PHPStan \Type \Nette ;
4
4
5
+ use PhpParser \Node \Arg ;
5
6
use PhpParser \Node \Expr \MethodCall ;
7
+ use PhpParser \Node \Scalar \String_ ;
6
8
use PHPStan \Analyser \Scope ;
7
9
use PHPStan \Reflection \MethodReflection ;
8
10
use PHPStan \Reflection \ParametersAcceptorSelector ;
@@ -38,13 +40,13 @@ public function getTypeFromMethodCall(
38
40
): Type
39
41
{
40
42
$ calledOnType = $ scope ->getType ($ methodCall ->var );
41
- $ defaultType = ParametersAcceptorSelector:: selectSingle ( $ calledOnType ->getMethod ('createComponent ' , $ scope )->getVariants ()) ->getReturnType ();
43
+ $ defaultType = $ calledOnType ->getMethod ('createComponent ' , $ scope )->getVariants ()[ 0 ] ->getReturnType ();
42
44
$ defaultType = TypeCombinator::remove ($ defaultType , new NullType ());
43
45
if ($ defaultType ->isSuperTypeOf (new ObjectType ('Nette\ComponentModel\IComponent ' ))->yes ()) {
44
46
$ defaultType = new MixedType (false , new NullType ());
45
47
}
46
48
$ args = $ methodCall ->getArgs ();
47
- if (count ($ args ) !== 1 ) {
49
+ if (count ($ args ) < 1 ) {
48
50
return $ defaultType ;
49
51
}
50
52
@@ -64,7 +66,11 @@ public function getTypeFromMethodCall(
64
66
65
67
$ method = $ calledOnType ->getMethod ($ methodName , $ scope );
66
68
67
- $ types [] = ParametersAcceptorSelector::selectSingle ($ method ->getVariants ())->getReturnType ();
69
+ $ types [] = ParametersAcceptorSelector::selectFromArgs (
70
+ $ scope ,
71
+ [new Arg (new String_ ($ componentName ))],
72
+ $ method ->getVariants (),
73
+ )->getReturnType ();
68
74
}
69
75
70
76
return TypeCombinator::union (...$ types );
0 commit comments