Phan\AST\UnionTypeVisitor::visitCast PHP Method

visitCast() public method

Visit a node with kind \ast\AST_CAST
public visitCast ( ast\Node $node ) : UnionType
$node ast\Node A node of the type indicated by the method name that we'd like to figure out the type that it produces.
return Phan\Language\UnionType The set of types that are possibly produced by the given node
    public function visitCast(Node $node) : UnionType
    {
        // TODO: Check if the cast is allowed based on the right side type
        UnionType::fromNode($this->context, $this->code_base, $node->children['expr']);
        switch ($node->flags) {
            case \ast\flags\TYPE_NULL:
                return NullType::instance()->asUnionType();
            case \ast\flags\TYPE_BOOL:
                return BoolType::instance()->asUnionType();
            case \ast\flags\TYPE_LONG:
                return IntType::instance()->asUnionType();
            case \ast\flags\TYPE_DOUBLE:
                return FloatType::instance()->asUnionType();
            case \ast\flags\TYPE_STRING:
                return StringType::instance()->asUnionType();
            case \ast\flags\TYPE_ARRAY:
                return ArrayType::instance()->asUnionType();
            case \ast\flags\TYPE_OBJECT:
                return ObjectType::instance()->asUnionType();
            default:
                throw new NodeException($node, 'Unknown type (' . $node->flags . ') in cast');
        }
    }