PHPStan\Analyser\Scope::resolveName PHP Method

resolveName() public method

public resolveName ( Name $name ) : string | null
$name PhpParser\Node\Name
return string | null
    public function resolveName(Name $name)
    {
        $originalClass = (string) $name;
        if ($originalClass === 'self' || $originalClass === 'static') {
            return $this->getClass();
        } elseif ($originalClass === 'parent' && $this->getClass() !== null && $this->broker->hasClass($this->getClass())) {
            $currentClassReflection = $this->broker->getClass($this->getClass());
            if ($currentClassReflection->getParentClass() !== false) {
                return $currentClassReflection->getParentClass()->getName();
            }
        } else {
            return $originalClass;
        }
        return null;
    }

Usage Example

 /**
  * @param \PhpParser\Node\Expr\PropertyFetch|\PhpParser\Node\Expr\StaticPropertyFetch $propertyFetch
  * @param \PHPStan\Analyser\Scope $scope
  * @return string|null
  */
 private function describeProperty($propertyFetch, Scope $scope)
 {
     if ($propertyFetch instanceof Node\Expr\PropertyFetch) {
         if (!is_string($propertyFetch->name)) {
             return null;
         }
         $propertyHolderType = $scope->getType($propertyFetch->var);
         if ($propertyHolderType->getClass() === null) {
             return null;
         }
         return sprintf('Property %s::$%s', $propertyHolderType->getClass(), $propertyFetch->name);
     } elseif ($propertyFetch instanceof Node\Expr\StaticPropertyFetch) {
         if (!$propertyFetch->class instanceof Node\Name || !is_string($propertyFetch->name)) {
             return null;
         }
         return sprintf('Static property %s::$%s', $scope->resolveName($propertyFetch->class), $propertyFetch->name);
     }
     return null;
 }