PHPSA\Compiler\Expression\Assign::compile PHP Method

compile() protected method

$a = 3;
protected compile ( PhpParser\Node\Expr\Assign $expr, Context $context ) : CompiledExpression
$expr PhpParser\Node\Expr\Assign
$context PHPSA\Context
return PHPSA\CompiledExpression
    protected function compile($expr, Context $context)
    {
        $compiler = $context->getExpressionCompiler();
        $compiledExpression = $compiler->compile($expr->expr);
        if ($expr->var instanceof Node\Expr\List_) {
            $isCorrectType = $compiledExpression->isArray();
            foreach ($expr->var->vars as $key => $var) {
                if (!$var instanceof Node\Expr\Variable) {
                    continue;
                }
                if ($var->name instanceof Node\Expr\Variable) {
                    $this->compileVariableDeclaration($compiler->compile($var->name), new CompiledExpression(), $context);
                    continue;
                }
                $symbol = $context->getSymbol($var->name);
                if (!$symbol) {
                    $symbol = new \PHPSA\Variable($var->name, null, CompiledExpression::UNKNOWN, $context->getCurrentBranch());
                    $context->addVariable($symbol);
                }
                if (!$isCorrectType) {
                    $symbol->modify(CompiledExpression::NULL, null);
                }
                $symbol->incSets();
            }
            return new CompiledExpression();
        }
        if ($expr->var instanceof Node\Expr\Variable) {
            $this->compileVariableDeclaration($compiler->compile($expr->var->name), $compiledExpression, $context);
            return $compiledExpression;
        }
        if ($expr->var instanceof Node\Expr\PropertyFetch) {
            $compiledExpression = $compiler->compile($expr->var->var);
            if ($compiledExpression->getType() == CompiledExpression::OBJECT) {
                $objectDefinition = $compiledExpression->getValue();
                if ($objectDefinition instanceof ClassDefinition) {
                    if (is_string($expr->var->name)) {
                        if ($objectDefinition->hasProperty($expr->var->name)) {
                            return $compiler->compile($objectDefinition->getProperty($expr->var->name));
                        }
                    }
                }
            }
        }
        $context->debug('Unknown how to pass symbol', $expr);
        return new CompiledExpression();
    }