File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 88 "php" : " ~7.0" ,
99 "phpstan/phpstan" : " ^0.6" ,
1010 "nette/component-model" : " ^2.3.0" ,
11+ "nette/forms" : " ^2.3.0" ,
1112 "nette/utils" : " ^2.3.0"
1213 },
1314 "require-dev" : {
Original file line number Diff line number Diff line change @@ -28,3 +28,8 @@ services:
2828 class : PHPStan\Type\Nette\ComponentModelDynamicReturnTypeExtension
2929 tags :
3030 - phpstan.broker.dynamicMethodReturnTypeExtension
31+
32+ -
33+ class : PHPStan\Type\Nette\FormsBaseControlDynamicReturnTypeExtension
34+ tags :
35+ - phpstan.broker.dynamicMethodReturnTypeExtension
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Type \Nette ;
4+
5+ use PhpParser \Node \Expr \MethodCall ;
6+ use PHPStan \Analyser \Scope ;
7+ use PHPStan \Reflection \MethodReflection ;
8+ use PHPStan \Type \Type ;
9+
10+ class FormsBaseControlDynamicReturnTypeExtension implements \PHPStan \Type \DynamicMethodReturnTypeExtension
11+ {
12+
13+ public static function getClass (): string
14+ {
15+ return \Nette \Forms \Controls \BaseControl::class;
16+ }
17+
18+ public function isMethodSupported (
19+ MethodReflection $ methodReflection
20+ ): bool
21+ {
22+ return $ methodReflection ->getDeclaringClass ()->getName () === \Nette \Forms \Controls \BaseControl::class;
23+ }
24+
25+ public function getTypeFromMethodCall (
26+ MethodReflection $ methodReflection ,
27+ MethodCall $ methodCall ,
28+ Scope $ scope
29+ ): Type
30+ {
31+ if ($ methodReflection ->getReturnType ()->getClass () !== null && $ methodReflection ->getReturnType ()->getClass () === \Nette \Forms \Controls \BaseControl::class) {
32+ return $ scope ->getType ($ methodCall ->var );
33+ }
34+
35+ return $ methodReflection ->getReturnType ();
36+ }
37+
38+ }
You can’t perform that action at this time.
0 commit comments