UseUse.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Node\Identifier;
  5. class UseUse extends Node\Stmt
  6. {
  7. /** @var int One of the Stmt\Use_::TYPE_* constants. Will only differ from TYPE_UNKNOWN for mixed group uses */
  8. public $type;
  9. /** @var Node\Name Namespace, class, function or constant to alias */
  10. public $name;
  11. /** @var Identifier|null Alias */
  12. public $alias;
  13. /**
  14. * Constructs an alias (use) node.
  15. *
  16. * @param Node\Name $name Namespace/Class to alias
  17. * @param null|string|Identifier $alias Alias
  18. * @param int $type Type of the use element (for mixed group use only)
  19. * @param array $attributes Additional attributes
  20. */
  21. public function __construct(Node\Name $name, $alias = null, int $type = Use_::TYPE_UNKNOWN, array $attributes = []) {
  22. $this->attributes = $attributes;
  23. $this->type = $type;
  24. $this->name = $name;
  25. $this->alias = \is_string($alias) ? new Identifier($alias) : $alias;
  26. }
  27. public function getSubNodeNames() : array {
  28. return ['type', 'name', 'alias'];
  29. }
  30. /**
  31. * Get alias. If not explicitly given this is the last component of the used name.
  32. *
  33. * @return Identifier
  34. */
  35. public function getAlias() : Identifier {
  36. if (null !== $this->alias) {
  37. return $this->alias;
  38. }
  39. return new Identifier($this->name->getLast());
  40. }
  41. public function getType() : string {
  42. return 'Stmt_UseUse';
  43. }
  44. }