Property.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  17. * Constructs a class property list node.
  18. *
  19. * @param int $flags Modifiers
  20. * @param PropertyProperty[] $props Properties
  21. * @param array $attributes Additional attributes
  22. * @param null|string|Identifier|Name|NullableType|UnionType $type Type declaration
  23. */
  24. public function __construct(int $flags, array $props, array $attributes = [], $type = null) {
  25. $this->attributes = $attributes;
  26. $this->flags = $flags;
  27. $this->props = $props;
  28. $this->type = \is_string($type) ? new Identifier($type) : $type;
  29. }
  30. public function getSubNodeNames() : array {
  31. return ['flags', 'type', 'props'];
  32. }
  33. /**
  34. * Whether the property is explicitly or implicitly public.
  35. *
  36. * @return bool
  37. */
  38. public function isPublic() : bool {
  39. return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
  40. || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
  41. }
  42. /**
  43. * Whether the property is protected.
  44. *
  45. * @return bool
  46. */
  47. public function isProtected() : bool {
  48. return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
  49. }
  50. /**
  51. * Whether the property is private.
  52. *
  53. * @return bool
  54. */
  55. public function isPrivate() : bool {
  56. return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
  57. }
  58. /**
  59. * Whether the property is static.
  60. *
  61. * @return bool
  62. */
  63. public function isStatic() : bool {
  64. return (bool) ($this->flags & Class_::MODIFIER_STATIC);
  65. }
  66. public function getType() : string {
  67. return 'Stmt_Property';
  68. }
  69. }