/** * Parse a use declaration. * @return UseDeclarationNode */ private function useDeclaration() { $declaration = new UseDeclarationNode(); $node = new NameNode(); $this->tryMatch(T_NS_SEPARATOR, $node); $this->mustMatch(T_STRING, $node, NULL, TRUE)->getText(); while ($this->tryMatch(T_NS_SEPARATOR, $node)) { $this->mustMatch(T_STRING, $node, NULL, TRUE)->getText(); } $declaration->addChild($node, 'name'); if ($this->tryMatch(T_AS, $declaration)) { $this->mustMatch(T_STRING, $declaration, 'alias', TRUE)->getText(); } return $declaration; }
public function testCreate() { $declaration = UseDeclarationNode::create('Cleese as Chapman'); $this->assertEquals('Cleese', $declaration->getName()->getText()); $this->assertEquals('Chapman', $declaration->getAlias()->getText()); }