packages/NodeTypeResolver/src/ComplexNodeTypeResolver.php
public function resolvePropertyTypeInfo(Property $property): ?VarTypeInfo
    {
        $types = [];

        $propertyDefault = $property->props[0]->default;
        if ($propertyDefault !== null) {
            $types[] = $this->nodeToStringTypeResolver->resolver($propertyDefault);
        }

        $classNode = $property->getAttribute(AttributeKey::CLASS_NODE);
        if (! $classNode instanceof Class_) {
            throw new ShouldNotHappenException();
        }

        $propertyName = $this->nameResolver->resolve($property);
        if ($propertyName === null) {
            return null;
        }

        /** @var Assign[] $propertyAssignNodes */
        $propertyAssignNodes = $this->betterNodeFinder->find([$classNode], function (Node $node) use (
            $propertyName
        ): bool {
            if ($node instanceof Assign && $node->var instanceof PropertyFetch) {
                // is property match
                return $this->nameResolver->isName($node->var, $propertyName);
            }

            return false;
        });

        foreach ($propertyAssignNodes as $propertyAssignNode) {
            $types = array_merge(
                $types,
                $this->nodeTypeResolver->resolveSingleTypeToStrings($propertyAssignNode->expr)
            );
        }

        $types = array_filter($types);

        return new VarTypeInfo($types, $this->typeAnalyzer, $types, true);
    }
public function resolvePropertyTypeInfo(Property $property): ?VarTypeInfo
    {
        $types = [];

        $propertyDefault = $property->props[0]->default;
        if ($propertyDefault !== null) {
            $types[] = $this->nodeToStringTypeResolver->resolver($propertyDefault);
        }

        $classNode = $property->getAttribute(AttributeKey::CLASS_NODE);
        if (! $classNode instanceof Class_) {
            throw new ShouldNotHappenException();
        }

        $propertyName = $this->nameResolver->resolve($property);
        if ($propertyName === null) {
            return null;
        }

        /** @var Assign[] $propertyAssignNodes */
        $propertyAssignNodes = $this->betterNodeFinder->find([$classNode], function (Node $node) use (
            $propertyName
        ): bool {
            if ($node instanceof Assign && $node->var instanceof PropertyFetch) {
                // is property match
                return $this->nameResolver->isName($node->var, $propertyName);
            }

            return false;
        });

        foreach ($propertyAssignNodes as $propertyAssignNode) {
            $types = array_merge(
                $types,
                $this->nodeTypeResolver->resolveSingleTypeToStrings($propertyAssignNode->expr)
            );
        }

        $types = array_filter($types);

        return new VarTypeInfo($types, $this->typeAnalyzer, $types, true);
    }
public function resolvePropertyTypeInfo ( Property $ property ) : ? VarTypeInfo { $ types = [ ] ; $ propertyDefault = $ property -> props [ 0 ] -> default ; if ( $ propertyDefault !== null ) { $ types [ ] = $ this -> nodeToStringTypeResolver -> resolver ( $ propertyDefault ) ; } $ classNode = $ property -> getAttribute ( AttributeKey :: CLASS_NODE ) ; if ( ! $ classNode instanceof Class_ ) { throw new ShouldNotHappenException ( ) ; } $ propertyName = $ this -> nameResolver -> resolve ( $ property ) ; if ( $ propertyName === null ) { return null ; } /** @var Assign[] $propertyAssignNodes */ $ propertyAssignNodes = $ this -> betterNodeFinder -> find ( [ $ classNode ] , function ( Node $ node ) use ( $ propertyName ) : bool { if ( $ node instanceof Assign && $ node -> var instanceof PropertyFetch ) { // is property match return $ this -> nameResolver -> isName ( $ node -> var , $ propertyName ) ; } return false ; } ) ; foreach ( $ propertyAssignNodes as $ propertyAssignNode ) { $ types = array_merge ( $ types , $ this -> nodeTypeResolver -> resolveSingleTypeToStrings ( $ propertyAssignNode -> expr ) ) ; } $ types = array_filter ( $ types ) ; return new VarTypeInfo ( $ types , $ this -> typeAnalyzer , $ types , true ) ; }
Based on static analysis of code, looking for property assigns
Based on static analysis of code looking for property assigns