Property.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /** @var Node\PropertyHook[] Property hooks */
  19. public array $hooks;
  20. /**
  21. * Constructs a class property list node.
  22. *
  23. * @param int $flags Modifiers
  24. * @param PropertyItem[] $props Properties
  25. * @param array<string, mixed> $attributes Additional attributes
  26. * @param null|Identifier|Name|ComplexType $type Type declaration
  27. * @param Node\AttributeGroup[] $attrGroups PHP attribute groups
  28. * @param Node\PropertyHook[] $hooks Property hooks
  29. */
  30. public function __construct(int $flags, array $props, array $attributes = [], ?Node $type = null, array $attrGroups = [], array $hooks = []) {
  31. $this->attributes = $attributes;
  32. $this->flags = $flags;
  33. $this->props = $props;
  34. $this->type = $type;
  35. $this->attrGroups = $attrGroups;
  36. $this->hooks = $hooks;
  37. }
  38. public function getSubNodeNames(): array {
  39. return ['attrGroups', 'flags', 'type', 'props', 'hooks'];
  40. }
  41. /**
  42. * Whether the property is explicitly or implicitly public.
  43. */
  44. public function isPublic(): bool {
  45. return ($this->flags & Modifiers::PUBLIC) !== 0
  46. || ($this->flags & Modifiers::VISIBILITY_MASK) === 0;
  47. }
  48. /**
  49. * Whether the property is protected.
  50. */
  51. public function isProtected(): bool {
  52. return (bool) ($this->flags & Modifiers::PROTECTED);
  53. }
  54. /**
  55. * Whether the property is private.
  56. */
  57. public function isPrivate(): bool {
  58. return (bool) ($this->flags & Modifiers::PRIVATE);
  59. }
  60. /**
  61. * Whether the property is static.
  62. */
  63. public function isStatic(): bool {
  64. return (bool) ($this->flags & Modifiers::STATIC);
  65. }
  66. /**
  67. * Whether the property is readonly.
  68. */
  69. public function isReadonly(): bool {
  70. return (bool) ($this->flags & Modifiers::READONLY);
  71. }
  72. /**
  73. * Whether the property is abstract.
  74. */
  75. public function isAbstract(): bool {
  76. return (bool) ($this->flags & Modifiers::ABSTRACT);
  77. }
  78. /**
  79. * Whether the property is final.
  80. */
  81. public function isFinal(): bool {
  82. return (bool) ($this->flags & Modifiers::FINAL);
  83. }
  84. /**
  85. * Whether the property has explicit public(set) visibility.
  86. */
  87. public function isPublicSet(): bool {
  88. return (bool) ($this->flags & Modifiers::PUBLIC_SET);
  89. }
  90. /**
  91. * Whether the property has explicit protected(set) visibility.
  92. */
  93. public function isProtectedSet(): bool {
  94. return (bool) ($this->flags & Modifiers::PROTECTED_SET);
  95. }
  96. /**
  97. * Whether the property has explicit private(set) visibility.
  98. */
  99. public function isPrivateSet(): bool {
  100. return (bool) ($this->flags & Modifiers::PRIVATE_SET);
  101. }
  102. public function getType(): string {
  103. return 'Stmt_Property';
  104. }
  105. }