PHPStan\Rules\Classes\ExistingClassesInPropertiesRule::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
    {
        $className = $scope->getClass();
        if ($className === null) {
            return [];
        }
        $classReflection = $this->broker->getClass($className);
        $propertyReflection = $classReflection->getProperty($node->name, $scope);
        $propertyType = $propertyReflection->getType();
        if ($propertyType instanceof ArrayType) {
            $nestedItemType = $propertyType->getNestedItemType();
            if ($nestedItemType->getItemType()->getClass() !== null && !$this->broker->hasClass($nestedItemType->getItemType()->getClass())) {
                return [sprintf('Property %s::$%s has unknown class %s as its array type.', $className, $node->name, $propertyType->describe())];
            }
        }
        if ($propertyType->getClass() === null) {
            return [];
        }
        if (!$this->broker->hasClass($propertyType->getClass())) {
            return [sprintf('Property %s::$%s has unknown class %s as its type.', $propertyReflection->getDeclaringClass()->getName(), $node->name, $propertyType->getClass())];
        }
        return [];
    }
ExistingClassesInPropertiesRule