44
55use Nette \Object ;
66use PHPStan \Reflection \ClassReflection ;
7- use PHPStan \Reflection \ClassReflectionExtension ;
87use PHPStan \Reflection \MethodReflection ;
8+ use PHPStan \Reflection \MethodsClassReflectionExtension ;
9+ use PHPStan \Reflection \PropertiesClassReflectionExtension ;
910use PHPStan \Reflection \PropertyReflection ;
1011
11- class NetteObjectClassReflectionExtension implements ClassReflectionExtension
12+ class NetteObjectClassReflectionExtension implements MethodsClassReflectionExtension, PropertiesClassReflectionExtension
1213{
1314
1415 public function hasProperty (ClassReflection $ classReflection , string $ propertyName ): bool
@@ -23,14 +24,33 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
2324
2425 // todo setter taky?
2526
27+ $ getterMethod = $ this ->getMethodByProperty ($ classReflection , $ propertyName );
28+ if ($ getterMethod === null ) {
29+ return false ;
30+ }
31+
32+ return $ getterMethod ->isPublic ();
33+ }
34+
35+ /**
36+ * @param \PHPStan\Reflection\ClassReflection $classReflection
37+ * @param string $propertyName
38+ * @return \PHPStan\Reflection\MethodReflection|null
39+ */
40+ private function getMethodByProperty (ClassReflection $ classReflection , string $ propertyName )
41+ {
2642 $ getterMethodName = sprintf ('get%s ' , ucfirst ($ propertyName ));
43+ if (!$ classReflection ->hasMethod ($ getterMethodName )) {
44+ return null ;
45+ }
2746
28- return $ classReflection ->hasMethod ( $ getterMethodName ) && $ classReflection -> getMethod ($ getterMethodName)-> isPublic ( );
47+ return $ classReflection ->getMethod ($ getterMethodName );
2948 }
3049
3150 public function getProperty (ClassReflection $ classReflection , string $ propertyName ): PropertyReflection
3251 {
33- return new NetteObjectPropertyReflection ($ classReflection );
52+ $ getterMethod = $ this ->getMethodByProperty ($ classReflection , $ propertyName );
53+ return new NetteObjectPropertyReflection ($ classReflection , $ getterMethod ->getReturnType ());
3454 }
3555
3656 public function hasMethod (ClassReflection $ classReflection , string $ methodName ): bool
@@ -48,6 +68,6 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
4868
4969 public function getMethod (ClassReflection $ classReflection , string $ methodName ): MethodReflection
5070 {
51- return new NetteObjectEventListenerMethodReflection ($ classReflection );
71+ return new NetteObjectEventListenerMethodReflection ($ methodName , $ classReflection );
5272 }
5373}
0 commit comments