Property.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Node\Identifier;
  5. use PhpParser\Node\Name;
  6. use PhpParser\Node\NullableType;
  7. use PhpParser\Node\UnionType;
  8. class Property extends Node\Stmt
  9. {
  10. /** @var int Modifiers */
  11. public $flags;
  12. /** @var PropertyProperty[] Properties */
  13. public $props;
  14. /** @var null|Identifier|Name|NullableType|UnionType Type declaration */
  15. public $type;
  16. /** @var Node\AttributeGroup[] PHP attribute groups */
  17. public $attrGroups;
  18. /**
  19. * Constructs a class property list node.
  20. *
  21. * @param int $flags Modifiers
  22. * @param PropertyProperty[] $props Properties
  23. * @param array $attributes Additional attributes
  24. * @param null|string|Identifier|Name|NullableType|UnionType $type Type declaration
  25. * @param Node\AttributeGroup[] $attrGroups PHP attribute groups
  26. */
  27. public function __construct(int $flags, array $props, array $attributes = [], $type = null, array $attrGroups = []) {
  28. $this->attributes = $attributes;
  29. $this->flags = $flags;
  30. $this->props = $props;
  31. $this->type = \is_string($type) ? new Identifier($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. * @return bool
  41. */
  42. public function isPublic() : bool {
  43. return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
  44. || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
  45. }
  46. /**
  47. * Whether the property is protected.
  48. *
  49. * @return bool
  50. */
  51. public function isProtected() : bool {
  52. return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
  53. }
  54. /**
  55. * Whether the property is private.
  56. *
  57. * @return bool
  58. */
  59. public function isPrivate() : bool {
  60. return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
  61. }
  62. /**
  63. * Whether the property is static.
  64. *
  65. * @return bool
  66. */
  67. public function isStatic() : bool {
  68. return (bool) ($this->flags & Class_::MODIFIER_STATIC);
  69. }
  70. public function getType() : string {
  71. return 'Stmt_Property';
  72. }
  73. }