Phan\AST\UnionTypeVisitor::unionTypeFromNode PHP Method

unionTypeFromNode() public static method

public static unionTypeFromNode ( CodeBase $code_base, Context $context, ast\Node | mixed $node, boolean $should_catch_issue_exception = true ) : UnionType
$code_base Phan\CodeBase The code base within which we're operating
$context Phan\Language\Context $context The context of the parser at the node for which we'd like to determine a type
$node ast\Node | mixed The node for which we'd like to determine its type
$should_catch_issue_exception boolean Set to true to cause loggable issues to be thrown instead
return Phan\Language\UnionType The UnionType associated with the given node in the given Context within the given CodeBase
    public static function unionTypeFromNode(CodeBase $code_base, Context $context, $node, bool $should_catch_issue_exception = true) : UnionType
    {
        if (!$node instanceof Node) {
            if ($node === null || $node === 'null') {
                return new UnionType();
            }
            return Type::fromObject($node)->asUnionType();
        }
        if ($should_catch_issue_exception) {
            try {
                return (new self($code_base, $context, $should_catch_issue_exception))($node);
            } catch (IssueException $exception) {
                Issue::maybeEmitInstance($code_base, $context, $exception->getIssueInstance());
                return new UnionType();
            }
        }
        return (new self($code_base, $context, $should_catch_issue_exception))($node);
    }

Usage Example

Example #1
0
 /**
  * @param Context $context
  * @param CodeBase $code_base
  * @param Node|string|null $node
  *
  * @return UnionType
  *
  * @see \Phan\Deprecated\Pass2::node_type
  * Formerly 'function node_type'
  */
 public static function fromNode(Context $context, CodeBase $code_base, $node) : UnionType
 {
     return UnionTypeVisitor::unionTypeFromNode($code_base, $context, $node);
 }
All Usage Examples Of Phan\AST\UnionTypeVisitor::unionTypeFromNode