/** * @depends testGetName */ public function testSetName() { $var = new VariableNode(T_VARIABLE, '$x'); $var->setName('$y'); $this->assertEquals('y', $var->getName()); $var->setName('z'); $this->assertEquals('z', $var->getName()); }
/** * @param string $name * The name of the parameter, with or without the leading $. * @param boolean $rewrite * If TRUE, every reference to the parameter in the function body will be changed * to reflect the new name. * * @return $this */ public function setName($name, $rewrite = FALSE) { $original_name = $this->name->getText(); $this->name->setName($name); if ($rewrite) { $this->getFunction()->find(Filter::isInstanceOf('\\Pharborist\\Variables\\VariableNode'))->filter(function (VariableNode $node) use($original_name) { return $node->getText() === $original_name; })->each(function (VariableNode $node) use($name) { $node->setText('$' . $name); }); } return $this; }