From 411e89a355265de127d8e24ff804a75d55d21b32 Mon Sep 17 00:00:00 2001 From: martinjonas Date: Thu, 14 Dec 2017 16:08:29 +0100 Subject: [PATCH] Support for Nette Object method getter syntax Support for Nette Object method getter syntax - CS fix --- .../Nette/NetteObjectClassReflectionExtension.php | 9 +++++++++ .../Nette/NetteObjectClassReflectionExtensionTest.php | 5 +++++ tests/data/NetteObjectChild.php | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/src/Reflection/Nette/NetteObjectClassReflectionExtension.php b/src/Reflection/Nette/NetteObjectClassReflectionExtension.php index 416a194..ba27e52 100644 --- a/src/Reflection/Nette/NetteObjectClassReflectionExtension.php +++ b/src/Reflection/Nette/NetteObjectClassReflectionExtension.php @@ -7,6 +7,7 @@ use PHPStan\Reflection\MethodsClassReflectionExtension; use PHPStan\Reflection\PropertiesClassReflectionExtension; use PHPStan\Reflection\PropertyReflection; +use PHPStan\Type\CallableType; class NetteObjectClassReflectionExtension implements MethodsClassReflectionExtension, PropertiesClassReflectionExtension { @@ -17,6 +18,10 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa return false; } + if ($classReflection->hasNativeMethod($propertyName)) { + return true; + } + $getterMethod = $this->getMethodByProperty($classReflection, $propertyName); if ($getterMethod === null) { return false; @@ -45,6 +50,10 @@ private function getMethodByProperty(ClassReflection $classReflection, string $p public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection { + if ($classReflection->hasNativeMethod($propertyName)) { + return new NetteObjectPropertyReflection($classReflection, new CallableType()); + } + /** @var \PHPStan\Reflection\MethodReflection $getterMethod */ $getterMethod = $this->getMethodByProperty($classReflection, $propertyName); return new NetteObjectPropertyReflection($classReflection, $getterMethod->getReturnType()); diff --git a/tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php b/tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php index 985da61..068b051 100644 --- a/tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php +++ b/tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php @@ -87,6 +87,11 @@ public function dataHasProperty(): array 'protectedProperty', false, ]; + $data[] = [ + 'PHPStan\Tests\NetteObjectChild', + 'methodAsClosureGetter', + true, + ]; } return $data; } diff --git a/tests/data/NetteObjectChild.php b/tests/data/NetteObjectChild.php index ab1815b..6a7d622 100644 --- a/tests/data/NetteObjectChild.php +++ b/tests/data/NetteObjectChild.php @@ -25,4 +25,9 @@ protected function getProtectedProperty(): string return 'protected'; } + public function methodAsClosureGetter(): string + { + return 'methodAsClosureGetter'; + } + }