Property.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Modifiers;
  4. use PhpParser\Node;
  5. use PhpParser\Node\ComplexType;
  6. use PhpParser\Node\Identifier;
  7. use PhpParser\Node\Name;
  8. use PhpParser\Node\PropertyItem;
  9. class Property extends Node\Stmt {
  10. /** @var int Modifiers */
  11. public int $flags;
  12. /** @var PropertyItem[] Properties */
  13. public array $props;
  14. /** @var null|Identifier|Name|ComplexType Type declaration */
  15. public ?Node $type;
  16. /** @var Node\AttributeGroup[] PHP attribute groups */
  17. public array $attrGroups;
  18. /**
  19. * Constructs a class property list node.
  20. *
  21. * @param int $flags Modifiers
  22. * @param PropertyItem[] $props Properties
  23. * @param array<string, mixed> $attributes Additional attributes
  24. * @param null|Identifier|Name|ComplexType $type Type declaration
  25. * @param Node\AttributeGroup[] $attrGroups PHP attribute groups
  26. */
  27. public function __construct(int $flags, array $props, array $attributes = [], ?Node $type = null, array $attrGroups = []) {
  28. $this->attributes = $attributes;
  29. $this->flags = $flags;
  30. $this->props = $props;
  31. $this->type = $type;
  32. $this->attrGroups = $attrGroups;
  33. }
  34. public function getSubNodeNames(): array {
  35. return ['attrGroups', 'flags', 'type', 'props'];
  36. }
  37. /**
  38. * Whether the property is explicitly or implicitly public.
  39. */
  40. public function isPublic(): bool {
  41. return ($this->flags & Modifiers::PUBLIC) !== 0
  42. || ($this->flags & Modifiers::VISIBILITY_MASK) === 0;
  43. }
  44. /**
  45. * Whether the property is protected.
  46. */
  47. public function isProtected(): bool {
  48. return (bool) ($this->flags & Modifiers::PROTECTED);
  49. }
  50. /**
  51. * Whether the property is private.
  52. */
  53. public function isPrivate(): bool {
  54. return (bool) ($this->flags & Modifiers::PRIVATE);
  55. }
  56. /**
  57. * Whether the property is static.
  58. */
  59. public function isStatic(): bool {
  60. return (bool) ($this->flags & Modifiers::STATIC);
  61. }
  62. /**
  63. * Whether the property is readonly.
  64. */
  65. public function isReadonly(): bool {
  66. return (bool) ($this->flags & Modifiers::READONLY);
  67. }
  68. public function getType(): string {
  69. return 'Stmt_Property';
  70. }
  71. }