PHPStan\Rules\Classes\AccessStaticPropertiesRule::processNode PHP Method

processNode() public method

public processNode ( PhpParser\Node $node, Scope $scope ) : array
$node PhpParser\Node
$scope PHPStan\Analyser\Scope
return array
    public function processNode(Node $node, Scope $scope) : array
    {
        if (!is_string($node->name) || !$node->class instanceof Node\Name) {
            return [];
        }
        $name = $node->name;
        $currentClass = $scope->getClass();
        if ($currentClass === null) {
            return [];
        }
        $currentClassReflection = $this->broker->getClass($currentClass);
        $class = (string) $node->class;
        if ($class === 'self' || $class === 'static') {
            $class = $currentClass;
        }
        if ($class === 'parent') {
            if ($currentClassReflection->getParentClass() === false) {
                return [sprintf('%s::%s() accesses parent::$%s but %s does not extend any class.', $currentClass, $scope->getFunctionName(), $name, $currentClass)];
            }
            $currentMethodReflection = $currentClassReflection->getMethod($scope->getFunctionName());
            if (!$currentMethodReflection->isStatic()) {
                // calling parent::method() from instance method
                return [];
            }
            $class = $currentClassReflection->getParentClass()->getName();
        }
        $classReflection = $this->broker->getClass($class);
        if (!$classReflection->hasProperty($name)) {
            return [sprintf('Access to an undefined static property %s::$%s.', $class, $name)];
        }
        $property = $classReflection->getProperty($name, $scope);
        if (!$property->isStatic()) {
            return [sprintf('Static access to instance property %s::$%s.', $class, $name)];
        }
        if (!$scope->canAccessProperty($property)) {
            return [sprintf('Cannot access property %s::$%s from current scope.', $property->getDeclaringClass()->getName(), $name)];
        }
        return [];
    }