mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-27 04:24:43 +01:00
If the short alias syntax is used compute the alias instead of setting it to null
This commit is contained in:
parent
afd6c70b77
commit
2703f42933
@ -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
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user