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 8
8
"php" : " ~7.0" ,
9
9
"phpstan/phpstan" : " ^0.6" ,
10
10
"nette/component-model" : " ^2.3.0" ,
11
+ "nette/forms" : " ^2.3.0" ,
11
12
"nette/utils" : " ^2.3.0"
12
13
},
13
14
"require-dev" : {
Original file line number Diff line number Diff line change @@ -28,3 +28,8 @@ services:
28
28
class : PHPStan\Type\Nette\ComponentModelDynamicReturnTypeExtension
29
29
tags :
30
30
- 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