getUnionTypeOfHardcodedGlobalVariableWithName() public static method

public static getUnionTypeOfHardcodedGlobalVariableWithName ( string $name, Context $context ) : UnionType | null
$name string
$context Phan\Language\Context
return Phan\Language\UnionType | null Returns UnionType (Possible with empty set) if and only if isHardcodedGlobalVariableWithName is true. Returns null otherwise.
コード例 #1
0
ファイル: UnionTypeVisitor.php プロジェクト: etsy/phan
 /**
  * Visit a node with kind `\ast\AST_VAR`
  *
  * @param Node $node
  * A node of the type indicated by the method name that we'd
  * like to figure out the type that it produces.
  *
  * @return UnionType
  * The set of types that are possibly produced by the
  * given node
  */
 public function visitVar(Node $node) : UnionType
 {
     // $$var or ${...} (whose idea was that anyway?)
     if ($node->children['name'] instanceof Node && ($node->children['name']->kind == \ast\AST_VAR || $node->children['name']->kind == \ast\AST_BINARY_OP)) {
         return MixedType::instance()->asUnionType();
     }
     // This is nonsense. Give up.
     if ($node->children['name'] instanceof Node) {
         return new UnionType();
     }
     $variable_name = $node->children['name'];
     if (!$this->context->getScope()->hasVariableWithName($variable_name)) {
         if (Variable::isSuperglobalVariableWithName($variable_name)) {
             return Variable::getUnionTypeOfHardcodedGlobalVariableWithName($variable_name, $this->context);
         }
         if (!Config::get()->ignore_undeclared_variables_in_global_scope || !$this->context->isInGlobalScope()) {
             throw new IssueException(Issue::fromType(Issue::UndeclaredVariable)($this->context->getFile(), $node->lineno ?? 0, [$variable_name]));
         }
     } else {
         $variable = $this->context->getScope()->getVariableByName($variable_name);
         return $variable->getUnionType();
     }
     return new UnionType();
 }