PHPStan\Reflection\ClassReflection::getProperty PHP Method

getProperty() public method

public getProperty ( string $propertyName, Scope $scope = null ) : PHPStan\Reflection\PropertyReflection
$propertyName string
$scope PHPStan\Analyser\Scope
return PHPStan\Reflection\PropertyReflection
    public function getProperty(string $propertyName, Scope $scope = null) : PropertyReflection
    {
        if (!isset($this->properties[$propertyName])) {
            $privateProperty = null;
            $publicProperty = null;
            foreach ($this->propertiesClassReflectionExtensions as $extension) {
                if ($extension->hasProperty($this, $propertyName)) {
                    $property = $extension->getProperty($this, $propertyName);
                    if ($scope !== null && $scope->canAccessProperty($property)) {
                        return $this->properties[$propertyName] = $property;
                    }
                    $this->properties[$propertyName] = $property;
                }
            }
        }
        if (!isset($this->properties[$propertyName])) {
            throw new \PHPStan\Reflection\MissingPropertyFromReflectionException($this->getName(), $propertyName);
        }
        return $this->properties[$propertyName];
    }

Usage Example

 public function hasMethod(ClassReflection $classReflection, string $methodName) : bool
 {
     $traitNames = $this->getTraitNames($classReflection->getNativeReflection());
     if (!$classReflection->isSubclassOf(Object::class) && !in_array(\Nette\SmartObject::class, $traitNames, true)) {
         return false;
     }
     if (substr($methodName, 0, 2) !== 'on' || strlen($methodName) <= 2) {
         return false;
     }
     return $classReflection->hasProperty($methodName) && $classReflection->getProperty($methodName)->isPublic();
 }