If the short alias syntax is used compute the alias instead of setting it to null

This commit is contained in:
nikic 2011-08-04 12:58:12 +02:00
parent afd6c70b77
commit 2703f42933
2 changed files with 17 additions and 2 deletions

View File

@ -2,8 +2,22 @@
/**
* @property PHPParser_Node_Name $name Namespace/Class to alias
* @property null|string $alias Alias
* @property string $alias Alias
*/
class PHPParser_Node_Stmt_UseUse extends PHPParser_Node_Stmt
{
public function __construct(array $subNodes, $line = -1, $docComment = null) {
parent::__construct($subNodes, $line, $docComment);
if (null === $this->alias) {
$this->alias = $this->name->getLast();
}
if ('self' == $this->alias || 'parent' == $this->alias) {
throw new PHPParser_Error(sprintf(
'Cannot use "%s" as "%s" because "%2$s" is a special class name',
$this->name, $this->alias
));
}
}
}

View File

@ -433,7 +433,8 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
}
public function pStmt_UseUse(PHPParser_Node_Stmt_UseUse $node) {
return $this->p($node->name) . (null !== $node->alias ? ' as ' . $node->alias : '');
return $this->p($node->name)
. ($node->name->getLast() !== $node->alias ? ' as ' . $node->alias : '');
}
public function pStmt_Interface(PHPParser_Node_Stmt_Interface $node) {