Phan\Language\Element\Variable::fromNodeInContext PHP Метод

fromNodeInContext() публичный статический Метод

public static fromNodeInContext ( ast\Node $node, Context $context, CodeBase $code_base, boolean $should_check_type = true ) : Variable
$node ast\Node An AST_VAR node
$context Phan\Language\Context The context in which the variable is found
$code_base Phan\CodeBase
$should_check_type boolean
Результат Variable A variable begotten from a node
    public static function fromNodeInContext(Node $node, Context $context, CodeBase $code_base, bool $should_check_type = true) : Variable
    {
        $variable_name = (new ContextNode($code_base, $context, $node))->getVariableName();
        // Get the type of the assignment
        $union_type = $should_check_type ? UnionType::fromNode($context, $code_base, $node) : new UnionType();
        $variable = new Variable($context->withLineNumberStart($node->lineno ?? 0), $variable_name, $union_type, $node->flags ?? 0);
        return $variable;
    }

Usage Example

Пример #1
0
 /**
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitVar(Node $node) : Context
 {
     $variable_name = (new ContextNode($this->code_base, $this->context, $node))->getVariableName();
     // Check to see if the variable already exists
     if ($this->context->getScope()->hasVariableWithName($variable_name)) {
         $variable = $this->context->getScope()->getVariableWithName($variable_name);
         // If we're assigning to an array element then we don't
         // know what the constitutation of the parameter is
         // outside of the scope of this assignment, so we add to
         // its union type rather than replace it.
         if ($this->is_dim_assignment) {
             $variable->getUnionType()->addUnionType($this->right_type);
         } else {
             // If the variable isn't a pass-by-reference paramter
             // we clone it so as to not disturb its previous types
             // as we replace it.
             if ($variable instanceof Parameter) {
                 if ($variable->isPassByReference()) {
                 } else {
                     $variable = clone $variable;
                 }
             } else {
                 $variable = clone $variable;
             }
             $variable->setUnionType($this->right_type);
         }
         $this->context->addScopeVariable($variable);
         return $this->context;
     }
     $variable = Variable::fromNodeInContext($this->assignment_node, $this->context, $this->code_base, false);
     // Set that type on the variable
     $variable->getUnionType()->addUnionType($this->right_type);
     // Note that we're not creating a new scope, just
     // adding variables to the existing scope
     $this->context->addScopeVariable($variable);
     return $this->context;
 }
All Usage Examples Of Phan\Language\Element\Variable::fromNodeInContext