/** * @inheritDoc */ public function resolveVariableType(Node $node) { // $this->call() if ($node instanceof Node\Expr\MethodCall && property_exists($node->var, 'name') && null === $node->getAttribute('guessedType', null)) { if ('container' == $node->var->name && $this->isController($this->table->lookUp('this')->type())) { $context = self::CONTAINER; } else { $context = $this->table->lookUp($node->var->name)->type(); } $type = $this->getType($context, $node->name, $node); if (null !== $type) { $node->setAttribute('guessedType', $type); } } // $x = $this->call() if ($node instanceof Node\Expr\Assign && $node->var instanceof Node\Expr\Variable && $node->expr instanceof Node\Expr\MethodCall && property_exists($node->expr->var, 'name') && null === $node->getAttribute('guessedType', null)) { if ('container' == $node->expr->var->name && $this->isController($this->table->lookUp('this')->type())) { $context = self::CONTAINER; } else { $context = $this->table->lookUp($node->expr->var->name)->type(); } $type = $this->getType($context, $node->expr->name, $node->expr); if (null !== $type) { $node->var->setAttribute('guessedType', $type); $this->table->setSymbol($node->var->name, $type); } } }
/** * {@inheritdoc} */ public function resolveVariableType(Node $node) { if ($node instanceof Node\Expr\Assign) { // $x = ... if ($node->var instanceof Node\Expr\Variable) { // skips variable names like ${$node->nodeName} if (!is_string($node->var->name)) { return; } // $x = new X(); if ($node->expr instanceof Node\Expr\New_) { if ($node->expr->class instanceof Node\Name) { $type = $node->expr->class->toString(); $this->table->setSymbol($node->var->name, $type); $node->var->setAttribute('guessedType', $type); } } // $x = $y; if ($node->expr instanceof Node\Expr\Variable) { $type = $this->table->lookUp($node->expr->name)->type(); $node->var->setAttribute('guessedType', $type); $this->table->setSymbol($node->var->name, $type); } // $x = $this->x if ($node->expr instanceof Node\Expr\PropertyFetch) { $type = $this->table->lookUpClassProperty($node->expr->name)->type(); $node->var->setAttribute('guessedType', $type); $this->table->setSymbol($node->var->name, $type); } } } }
/** * {@inheritdoc} */ public function resolveVariableType(Node $node) { if ($node instanceof Node\Expr\Assign) { // $this->x = ... // excluding $this->$x = ... if ($node->var instanceof Node\Expr\PropertyFetch) { // $stub[$key]->x = ... ; if not tested a php notice will occur // @TODO change to be able to use all types of properties like $x->x = 10 if ($node->var->var instanceof Node\Expr\ArrayDimFetch) { return; } // @TODO change to be able to use all types of properties like $x->x = 10 if ($node->var->var->name !== 'this' || !is_string($node->var->name)) { return; } // $this->x = new X(); if ($node->expr instanceof Node\Expr\New_) { if ($node->expr->class instanceof Node\Name) { $type = $node->expr->class->toString(); $node->var->setAttribute('guessedType', $type); $this->table->setClassProperty($node->var->name, $type); } } // $this->x = $y; if ($node->expr instanceof Node\Expr\Variable) { $type = $this->table->lookUp($node->expr->name)->type(); $node->var->setAttribute('guessedType', $type); $this->table->setClassProperty($node->var->name, $type); } // $this->x = $this->y; if ($node->expr instanceof Node\Expr\PropertyFetch) { $type = $this->table->lookUpClassProperty($node->expr->name)->type(); $node->var->setAttribute('guessedType', $type); $this->table->setClassProperty($node->var->name, $type); } } } }
/** * {@inheritdoc} */ public function resolveVariableType(Node $node) { if ($node instanceof Node\Expr\Variable) { $node->setAttribute('guessedType', $this->table->lookUp($node->name)->type()); } }
public function testLookUpReturnsNullSymbol() { $table = new SymbolTable(); $this->assertEquals(new Symbol('var', ''), $table->lookUp('var')); }