Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Nette Object method getter syntax #15

Open
wants to merge 1 commit into
base: 1.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Reflection/Nette/NetteObjectClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public function dataHasProperty(): array
'protectedProperty',
false,
];
$data[] = [
'PHPStan\Tests\NetteObjectChild',
'methodAsClosureGetter',
true,
];
}
return $data;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/data/NetteObjectChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ protected function getProtectedProperty(): string
return 'protected';
}

public function methodAsClosureGetter(): string
{
return 'methodAsClosureGetter';
}

}