No Description

Property.php 2.5KB

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