Trait_.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. class Trait_ extends ClassLike {
  5. /**
  6. * Constructs a trait node.
  7. *
  8. * @param string|Node\Identifier $name Name
  9. * @param array{
  10. * stmts?: Node\Stmt[],
  11. * attrGroups?: Node\AttributeGroup[],
  12. * } $subNodes Array of the following optional subnodes:
  13. * 'stmts' => array(): Statements
  14. * 'attrGroups' => array(): PHP attribute groups
  15. * @param array<string, mixed> $attributes Additional attributes
  16. */
  17. public function __construct($name, array $subNodes = [], array $attributes = []) {
  18. $this->attributes = $attributes;
  19. $this->name = \is_string($name) ? new Node\Identifier($name) : $name;
  20. $this->stmts = $subNodes['stmts'] ?? [];
  21. $this->attrGroups = $subNodes['attrGroups'] ?? [];
  22. }
  23. public function getSubNodeNames(): array {
  24. return ['attrGroups', 'name', 'stmts'];
  25. }
  26. public function getType(): string {
  27. return 'Stmt_Trait';
  28. }
  29. }